dmchen/delete-trans-tool

This commit is contained in:
dmchen 2024-08-28 06:52:38 +00:00
parent e42cf46cfc
commit 0da625bf55
5 changed files with 59 additions and 2 deletions

View File

@ -121,6 +121,8 @@ void mndGenerateMachineCode();
void mndDumpSdb(); void mndDumpSdb();
void mndDeleteTrans();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -59,6 +59,7 @@ static struct {
#endif #endif
bool dumpConfig; bool dumpConfig;
bool dumpSdb; bool dumpSdb;
bool deleteTrans;
bool generateGrant; bool generateGrant;
bool memDbg; bool memDbg;
bool checkS3; bool checkS3;
@ -187,6 +188,8 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
} }
} else if (strcmp(argv[i], "-s") == 0) { } else if (strcmp(argv[i], "-s") == 0) {
global.dumpSdb = true; global.dumpSdb = true;
} else if (strcmp(argv[i], "-dTxn") == 0) {
global.deleteTrans = true;
} else if (strcmp(argv[i], "-E") == 0) { } else if (strcmp(argv[i], "-E") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
if (strlen(argv[++i]) >= PATH_MAX) { if (strlen(argv[++i]) >= PATH_MAX) {
@ -436,6 +439,22 @@ int mainWindows(int argc, char **argv) {
return 0; return 0;
} }
if (global.deleteTrans) {
TdFilePtr pFile;
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
printf("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
tstrerror(code));
return code;
}
mndDeleteTrans();
taosCleanupCfg();
taosCloseLog();
taosCleanupArgs();
taosConvDestroy();
return 0;
}
osSetProcPath(argc, (char **)argv); osSetProcPath(argc, (char **)argv);
taosCleanupArgs(); taosCleanupArgs();

View File

@ -630,4 +630,30 @@ void mndDumpSdb() {
mInfo("dump sdb info success"); mInfo("dump sdb info success");
} }
void mndDeleteTrans() {
mInfo("start to dump sdb info to sdb.json");
char path[PATH_MAX * 2] = {0};
(void)snprintf(path, sizeof(path), "%s%smnode", tsDataDir, TD_DIRSEP);
SMsgCb msgCb = {0};
msgCb.reportStartupFp = reportStartup;
msgCb.sendReqFp = sendReq;
msgCb.sendSyncReqFp = sendSyncReq;
msgCb.sendRspFp = sendRsp;
msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack
tmsgSetDefault(&msgCb);
(void)walInit(NULL);
(void)syncInit();
SMnodeOpt opt = {.msgCb = msgCb};
SMnode *pMnode = mndOpen(path, &opt);
if (pMnode == NULL) return;
(void)sdbWriteFileForDump(pMnode->pSdb);
mInfo("dump sdb info success");
}
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -280,6 +280,7 @@ int32_t sdbReadFile(SSdb *pSdb);
*/ */
int32_t sdbWriteFile(SSdb *pSdb, int32_t delta); int32_t sdbWriteFile(SSdb *pSdb, int32_t delta);
int32_t sdbWriteFileForDump(SSdb *pSdb);
/** /**
* @brief Parse and write raw data to sdb, then free the pRaw object * @brief Parse and write raw data to sdb, then free the pRaw object
* *

View File

@ -381,7 +381,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
return code; return code;
} }
static int32_t sdbWriteFileImp(SSdb *pSdb) { static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
int32_t code = 0; int32_t code = 0;
char tmpfile[PATH_MAX] = {0}; char tmpfile[PATH_MAX] = {0};
@ -409,6 +409,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
} }
for (int32_t i = SDB_MAX - 1; i >= 0; --i) { for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
if (i == skip_type) continue;
SdbEncodeFp encodeFp = pSdb->encodeFps[i]; SdbEncodeFp encodeFp = pSdb->encodeFps[i];
if (encodeFp == NULL) continue; if (encodeFp == NULL) continue;
@ -550,7 +551,7 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
} }
} }
if (code == 0) { if (code == 0) {
code = sdbWriteFileImp(pSdb); code = sdbWriteFileImp(pSdb, -1);
} }
if (code == 0) { if (code == 0) {
if (pSdb->pWal != NULL) { if (pSdb->pWal != NULL) {
@ -566,6 +567,14 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
return code; return code;
} }
int32_t sdbWriteFileForDump(SSdb *pSdb) {
int32_t code = 0;
code = sdbWriteFileImp(pSdb, 0);
return code;
}
int32_t sdbDeploy(SSdb *pSdb) { int32_t sdbDeploy(SSdb *pSdb) {
int32_t code = 0; int32_t code = 0;
code = sdbDeployData(pSdb); code = sdbDeployData(pSdb);