0
点赞
收藏
分享

微信扫一扫

【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)

【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)

4. updatefields

updatefields命令用于回档与动态变更表结构,命令格式为 ./tcapulogmgr updatefields --directory= --engine-directory= --tbusid= --conf= [--speed= --seqcontinuous],其中,前四个必填参数的含义分别为:

  • --directory ulog文件目录
  • --engine-directory 冷备文件目录
  • --tbusid 表示要执行回档操作和动态变更表结构的svr_id,用于从目录中过滤出对应的binlog文件
  • --conf updatefields命令的配置文件,指定了DirServerAddr、PassWord、要回档数据和导入数据的表以及用于转换记录的so文件

updatefields命令的配置文件模板与说明

<?xml version="1.0" encoding="GBK" standalone="yes" ?>
<tcapulogmgr>

<!--动态变更表结构的配置-->
<UpdateFieldsCfg UpdateFieldsCfgNum="1">
<!--SourceAppID、SourceZoneID、SourceTableName用于指定要回档的数据表的业务ID、区服ID和表名-->
<!--DestAppID、DestZoneID、DestTableName用于指定保存转换后的记录的业务ID、区服ID和表名-->
<!--LibFile用于指定用户生成的用来转换记录结构的so文件-->
<UpdateFieldsCfgItem SourceAppID="2" SourceZoneID="3" SourceTableName="TestData" DestAppID="2" DestZoneID="3" DestTableName="TestData_new" LibFile="do_nothing.so"/>
<!--PassWord用于指定DestTableName所在业务的密码-->
<ServiceApiCfg PassWord="**********" ConnectTimeOut="10000" RegistTableTimeOut="10000" DirServerNum="1" >
<!--DirServerAddr用于指定DestTableName所在业务的目录服务器地址-->
<DirServerAddr>tcp://*.*.*.*:9999</DirServerAddr>
</ServiceApiCfg>
</UpdateFieldsCfg>

</tcapulogmgr>

方括号中的参数为可选项:

  • --speed 速度控制参数
  • --seqcontinuous 表示binlog的序号必须连续,不连续则报错

假如用于转换记录结构的代码文件为do_nothing.cpp,可以使用 g++ -shared -fPIC -o do_nothing.so do_nothing.cpp 生成对应的动态链接库文件。在do_nothing.cpp文件中,需要根据具体需求实现TransferRecord函数。

TransferRecord函数示例

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <assert.h>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <tr1/functional>

#define TCAPLUS_MAX_TABLE_NAME_LEN_FOR_PLUGIN 128

enum EnumTransRecordStatus {
ENUM_TRANS_RECORD_SUC = 0,
ENUM_TRANS_RECORD_NOT_EXIST = 1,
ENUM_TRANS_RECORD_FAIL= -1,
};

typedef int int32_t;

typedef struct {
int32_t iAppID;
int32_t iZoneID;
char szTableName[TCAPLUS_MAX_TABLE_NAME_LEN_FOR_PLUGIN];
std::tr1::function<int(const char*)> pFuncForBillLog;
} TcapsvrImportCallBackPara;

typedef std::map<std::string, std::string> TcapFieldNameValueMap;
typedef std::vector<TcapFieldNameValueMap> VALUELIST;
typedef std::vector<EnumTransRecordStatus> STATUSLIST;

using namespace std;

extern "C" int TransferRecord(const VALUELIST& old_list,
VALUELIST& new_list, STATUSLIST& status_list,
TcapsvrImportCallBackPara* pCallBackPara)
{
if (NULL == pCallBackPara)
{
return -1;
}

VALUELIST::const_iterator it_list;
new_list.clear();

for (it_list = old_list.begin(); it_list != old_list.end(); ++it_list)
{
int ret = ENUM_TRANS_RECORD_SUC;
TcapFieldNameValueMap new_map;
const TcapFieldNameValueMap& old_map = *it_list;

TcapFieldNameValueMap::const_iterator it;
for (it = old_map.begin(); it != old_map.end(); ++it)
{
std::pair<TcapFieldNameValueMap::iterator, bool> result;
result = new_map.insert(std::make_pair(it->first, it->second));
if(!result.second)
{
status_list.push_back(ENUM_TRANS_RECORD_FAIL);
return -1;
}
}

// add new filed: platformid, use default value 0
// int32_t platformid = 0;
// std::string new_value((char*)&platformid, sizeof(platformid));
// std::string new_key = "platformid";

// std::pair<TcapFieldNameValueMap::iterator, bool> result = new_map.insert(std::make_pair(new_key, new_value));
// if(!result.second)
// {
// status_list.push_back(ENUM_TRANS_RECORD_FAIL);
// return -1;
// }

new_list.push_back(new_map);
status_list.push_back((EnumTransRecordStatus)ret);
}

return 0;
}

按照上述函数示例生成so文件,并在tcapulogmgr_cfg.xml中配置相关参数后,执行 ./tcapulogmgr updatefields --directory=/txh/ulog/1.2.2.1 --engine-directory=/txh --tbusid=1.2.2.1 --conf=tcapulogmgr_cfg.xml --seqcontinuous。假设/txh目录下由配置文件中SourceTableName字段指定的数据表的引擎文件的checkpoint为50,/txh/ulog/1.2.2.1目录下最大的sequence为60,那么该命令会redo sequence在51到60之间的binlog,对SourceTableName字段指定的数据表进行回档操作;同时,会使用so文件对这10条binlog对应的记录结构进行转换,将其redo到DestTableName字段指定的数据表中。

更多信息请关注TcaplusDB微信公众号,风里雨里,我们一直在等你!

【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)_腾讯游戏

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

举报

相关推荐

0 条评论