当前位置:网站首页>【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)
【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)
2022-06-29 03:26:00 【数据库大师】
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是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。
边栏推荐
- SSH login without password
- Stm32l4 Series MCU ADC accurately calculates input voltage through internal reference voltage
- Jerry's watch stops moving [chapter]
- Matlab exercises - image drawing exercises
- Laravel, execute PHP artist migrate and report an error alter table `users`add unique `users_ email_ unique`(`email`))
- 2022-2028 global pneumatic test probe industry survey and trend analysis report
- 2022/02/15
- Synchronous real-time data of Jerry's watch [chapter]
- 相同的树[从部分到整体]
- Bluebridge cup 2022 preliminaries - minesweeping
猜你喜欢
![[flutter topic] 66 diagram basic constraints box (I) yyds dry goods inventory](/img/8b/55a43383e1cb6b37231dba980c7b11.jpg)
[flutter topic] 66 diagram basic constraints box (I) yyds dry goods inventory
![[test theory] quality analysis ability](/img/4b/d011e16c7b2be52fe12c123214779e.jpg)
[test theory] quality analysis ability

19.03 容器的说明和简单应用例续

Matlab exercises - image drawing exercises

How to keep source code secret in embedded development

Logarithmic calculation in reverse order, logarithmic calculation in sequence -- merge sort

Input input box click with border

Allegro's method of setting network flying line and network color
![相同的树[从部分到整体]](/img/2d/997b9cb9cd4f8ea8620f5a66fcf00a.png)
相同的树[从部分到整体]

2022-2028 global sound insulation coating industry research and trend analysis report
随机推荐
Deeply analyzing the business logic of "chain 2+1" mode
Linear and nonlinear structures
How to keep source code secret in embedded development
Jerry's watch pause [chapter]
Allegro's method of canceling the routing of a good line
2022-2028 global MWIR camera industry research and trend analysis report
【资料上新】基于3568开发板的NPU开发资料全面升级
Is it safe for qiniu school to open an account in 2022?
set time format
Requirements analysis specification and requirements specification
2022-2028 global pneumatic test probe industry survey and trend analysis report
相同的树[从部分到整体]
An internal error occurred during: 'Retrieving archetypes:'.
MATALB signal processing - signal transformation (7)
Certification training | streamnational certification training phase 2
Several ways to add breakpoints using GDB
Web APIs 高阶函数 丨黑马程序员
Connect error: no route to host (errno:113)
2022-2028 global secondary butyl lithium industry research and trend analysis report
Different binary search trees [bottom-up backtracking spanning tree + memory search -- space for time]