提交 5d80e808 编写于 作者: S Shengliang Guan

fix: dump sdb to json

上级 e0d3b53b
......@@ -20,10 +20,13 @@
#include "tconfig.h"
#include "tjson.h"
#define TMP_SDB_DATA_DIR "/tmp/dumpsdb"
#define TMP_SDB_MNODE_DIR "/tmp/dumpsdb/mnode"
#define TMP_SDB_FILE "/tmp/dumpsdb/mnode/data/sdb.data"
#define TMP_SDB_PATH "/tmp/dumpsdb/mnode/data"
#define TMP_DNODE_DIR "/tmp/dumpsdb"
#define TMP_MNODE_DIR "/tmp/dumpsdb/mnode"
#define TMP_SDB_DATA_DIR "/tmp/dumpsdb/mnode/data"
#define TMP_SDB_SYNC_DIR "/tmp/dumpsdb/mnode/sync"
#define TMP_SDB_DATA_FILE "/tmp/dumpsdb/mnode/data/sdb.data"
#define TMP_SDB_RAFT_CFG_FILE "/tmp/dumpsdb/mnode/sync/raft_config.json"
#define TMP_SDB_RAFT_STORE_FILE "/tmp/dumpsdb/mnode/sync/raft_store.json"
void reportStartup(const char *name, const char *desc) {}
......@@ -318,6 +321,10 @@ void dumpHeader(SSdb *pSdb, SJson *json) {
}
int32_t dumpSdb() {
wDebugFlag = 0;
mDebugFlag = 0;
sDebugFlag = 0;
SMsgCb msgCb = {0};
msgCb.reportStartupFp = reportStartup;
msgCb.sendReqFp = sendReq;
......@@ -325,9 +332,10 @@ int32_t dumpSdb() {
msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack
tmsgSetDefault(&msgCb);
walInit();
syncInit();
SMnodeOpt opt = {.msgCb = msgCb};
SMnode *pMnode = mndOpen(TMP_SDB_MNODE_DIR, &opt);
SMnode *pMnode = mndOpen(TMP_MNODE_DIR, &opt);
if (pMnode == NULL) return -1;
SSdb *pSdb = pMnode->pSdb;
......@@ -369,13 +377,11 @@ int32_t dumpSdb() {
taosCloseFile(&pFile);
tjsonDelete(json);
taosMemoryFree(pCont);
taosRemoveDir(TMP_SDB_DATA_DIR);
taosRemoveDir(TMP_DNODE_DIR);
return 0;
}
int32_t parseArgs(int32_t argc, char *argv[]) {
char file[PATH_MAX] = {0};
for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) {
......@@ -388,20 +394,8 @@ int32_t parseArgs(int32_t argc, char *argv[]) {
printf("'-c' requires a parameter, default is %s\n", configDir);
return -1;
}
} else if (strcmp(argv[i], "-f") == 0) {
if (i < argc - 1) {
if (strlen(argv[++i]) >= PATH_MAX) {
printf("file path overflow");
return -1;
}
tstrncpy(file, argv[i], PATH_MAX);
} else {
printf("'-f' requires a parameter, default is %s\n", configDir);
return -1;
}
} else {
printf("-c Configuration directory. \n");
printf("-f Input sdb.data file. \n");
return -1;
}
}
......@@ -416,13 +410,28 @@ int32_t parseArgs(int32_t argc, char *argv[]) {
return -1;
}
if (file[0] == 0) {
snprintf(file, PATH_MAX, "%s/mnode/data/sdb.data", tsDataDir);
}
strcpy(tsDataDir, TMP_SDB_DATA_DIR);
taosMulMkDir(TMP_SDB_PATH);
taosCopyFile(file, TMP_SDB_FILE);
char dataFile[PATH_MAX] = {0};
char raftCfgFile[PATH_MAX] = {0};
char raftStoreFile[PATH_MAX] = {0};
snprintf(dataFile, PATH_MAX, "%s/mnode/data/sdb.data", tsDataDir);
snprintf(raftCfgFile, PATH_MAX, "%s/mnode/sync/raft_config.json", tsDataDir);
snprintf(raftStoreFile, PATH_MAX, "%s/mnode/sync/raft_store.json", tsDataDir);
char cmd[PATH_MAX * 2] = {0};
snprintf(cmd, sizeof(cmd), "rm -rf %s", TMP_DNODE_DIR);
system(cmd);
snprintf(cmd, sizeof(cmd), "mkdir -p %s", TMP_SDB_DATA_DIR);
system(cmd);
snprintf(cmd, sizeof(cmd), "mkdir -p %s", TMP_SDB_SYNC_DIR);
system(cmd);
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", dataFile, TMP_SDB_DATA_FILE);
system(cmd);
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", raftCfgFile, TMP_SDB_RAFT_CFG_FILE);
system(cmd);
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", raftStoreFile, TMP_SDB_RAFT_STORE_FILE);
system(cmd);
strcpy(tsDataDir, TMP_DNODE_DIR);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册