【TcaplusDB知识库】如何(批量)申请通过xml、tdr、proto文件新增表


【TcaplusDB知识库】如何(批量)申请通过xml/tdr/proto文件新增表

 

申请加表接口支持在同一个业务的不同游戏区下添加多张表,其接口的cmd值为10002。

请求地址

POST
http://OmsAddress/app/newoms.php/webservice/business/table/batchapply?cmd=10002&ip-type=webservicerest&access-token=AccessTokenVal

POST请求参数说明

参数名称数据类型说明是否必填字段备注
app_id 整型 加表所在的业务id  
attachment_id 数组 定义表结构的xml文件id列表  
attention_man 字符串 用分号";"分隔关注人,字段最大长度为200  
table_info 数组 table_info各数组项是在指定的app_id各zone下申请的加表信息,其数据结构见如下表格  

 

申请加表时,table_info各数据项的结构:

zone_id表所在的zone的id    
tables 数组,数组中一个数据项是一张表的信息,表所填信息如右 参数名称 字段名称 数组类型 说明
    table_name 表名称 字符串 长度1-31,只能包含字母、数字、下划线,首字母为字母、下划线
    table_type 表类型 整型 0为generic,1为list 默认0
    table_maxnum List最多元素个数 整型 table_type为1时,必填,范围1-1024
    auto_approve_add_table_trans 是否自动审核此申请单 整型 若自动审核,需要加表所在的集群的权限允许
    auto_execute_add_table_trans 是否自动执行此申请单对应的事务 整型 auto_approve_add_table_trans=1时,此处自动执行才有效,且需要加表所在的集群权限允许
    compress 表压缩 整型 0不开启表压缩,1开启表压缩 默认0
    calc_resource_type 计算表资源的模型 整型 1,简单模型;2,专家模式 默认1
    active_record_num 活跃记录数 整型 calc_resource_type为1时必填,范围1-2147483647
    total_record_num 总记录数 整型 calc_resource_type为1、2时必填
    estimated_read_load 读频率 整型 calc_resource_type为1时必填
    estimated_write_load 写频率 整型 calc_resource_type为1时必填
    key_avarage_record_size 最大key大小 整型 calc_resource_type为1、2时必填
    value_avarage_record_size Value平均大小 整型 calc_resource_type为1、2时必填
    pcu 最高在线(PCU) 整型 calc_resource_type为2时必填
    relationship_chain_interval 每玩家关系链读取间隔(秒) 整型 calc_resource_type为2时必填
    relationship_chain_count 玩家关系链一次性读取记录条数(条) 整型 calc_resource_type为2时必填
    index_count 索引/List数目 整型 calc_resource_type为2时必填
    read_index_interval 每玩家索引/List读取间隔(秒) 整型 calc_resource_type为2时必填
    read_index_count 平均每次索引/List读取时读取的记录条数(条) 整型 calc_resource_type为2时必填
    read_interval 每玩家触发单条读取间隔(秒) 整型 calc_resource_type为2时必填
    write_interval 每玩家触发单条写入间隔(秒) 整型 calc_resource_type为2时必填

 

Data参数

使用json格式表示记录相关信息,示例如下:

{
  "table_info": [
      {
          "tables": [
              {
                  "relationship_chain_count": 1,
                  "table_type": 0,
                  "compress": 0,
                  "value_avarage_record_size": 1,
                  "active_record_num": "2",
                  "total_record_num": "3",
                  "estimated_read_load": "4",
                  "read_index_interval": 60,
                  "index_count": 1,
                  "calc_resource_type": 2,
                  "write_interval": 60,
                  "pcu": 1,
                  "relationship_chain_interval": 60,
                  "table_name": "test_table_generic_modify",
                  "estimated_write_load": "5",
                  "key_avarage_record_size": 1,
                  "read_interval": 60,
                  "read_index_count": 1
              }
          ],
          "zone_id": "3"
      }
  ],
  "memo": "by auto test",
  "attachment_id": [
      99
  ],
  "app_id": "2"
}

返回说明

  1. http请求的Status为200,请求成功,返回加表信息;返回数据结构见“请求示例”

  2. http请求的Status 不等于200,请求失败,返回的数据为json格式,内容为错误信息描述 | |

请求示例

通过 curl 方法发起请求

命令中的红色部分是需要用户自行填写的参数,请参阅url中GET参数说明

curl -H "Content-type: application/json" -X "POST" -d '{ "table_info": [ { "tables": [ { "relationship_chain_count": 1, "table_type": 0, "compress": 0, "value_avarage_record_size": 1, "active_record_num": "2", "total_record_num": "3", "estimated_read_load": "4", "read_index_interval": 60, "index_count": 1, "calc_resource_type": 2, "write_interval": 60, "pcu": 1, "relationship_chain_interval": 60, "table_name": "test_table_generic_modify", "estimated_write_load": "5", "key_avarage_record_size": 1, "read_interval": 60, "read_index_count": 1 } ], "zone_id": "3" } ], "memo": "by auto test", "attachment_id": [ 99 ], "app_id": "2" }' http://omsaddress/app/newoms.php/webservice/business/table/batchapply?cmd=10002&ip-type=webservicerest&access-token=

返回示例

成功返回示例

http请求的Status=200

[
  {
      "relationship_chain_count": 1,
      "table_type": 0, //表类型,0:generic;1:list
      "compress": 0,
      "value_avarage_record_size": 1,
      "active_record_num": "2",
      "total_record_num": "3",
      "estimated_read_load": "4",
      "read_index_interval": 60,
      "index_count": 1,
      "calc_resource_type": 2,
      "write_interval": 60,
      "pcu": 1,
      "relationship_chain_interval": 60,
      "table_name": "test_table_generic_modify",//表名称
      "estimated_write_load": "5",
      "key_avarage_record_size": 1,
      "read_interval": 60,
      "read_index_count": 1,
      "resource_ratio": 1,
      "zone_list": "3",//表所在的游戏区id
      "set_id": 126,//表所在的集群id
      "app_id": "2",//表所在的业务id
      "app_name": "t_app",
      "memo": "by auto test",
      "attention_man": "",
      "user": "tcaplus",
      "type": "xml",
      "apply_type": "0",
      "tdr": "99",
      "write_time": "2017-03-02 20:20:10",
      "dm_ratio": 5,
      "kelly_id": 0,
      "table_maxnum": 0,
      "id": 108//加表申请单id
  }
]

错误返回

http请求的Status!=200

[
  "ip(10.29.89.51) not in whitelist for applying to add table(cmd:10002) of set_id:126 app_id:2 zone_id:3"
]
{
  "name": "Unauthorized",
  "message": "you are not allowed to access this app:app_id:2",
  "code": 0,
  "status": 401,
  "type": "yii\\web ForbiddenHttpException"
}
[
  "table_name:已经申请其他表操作 app:2 zone:3 table_name:test_table_generic_modify apply id:108 apply type:{applytype} error type:{errortype}"
]
[
  "table_name:已经申请其他表操作 app:2 zone:3 table_name:test_table_generic_modify apply id:108 apply type:{applytype} error type:{errortype}"
]

 


 

img

TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。