diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index b821231539..1f205b3f11 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -121,6 +121,8 @@ void mndGenerateMachineCode(); void mndDumpSdb(); +void mndDeleteTrans(); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index e5c37e3d55..9b0cd7d5a5 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -59,6 +59,7 @@ static struct { #endif bool dumpConfig; bool dumpSdb; + bool deleteTrans; bool generateGrant; bool memDbg; bool checkS3; @@ -187,6 +188,8 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { } } else if (strcmp(argv[i], "-s") == 0) { global.dumpSdb = true; + } else if (strcmp(argv[i], "-dTxn") == 0) { + global.deleteTrans = true; } else if (strcmp(argv[i], "-E") == 0) { if (i < argc - 1) { if (strlen(argv[++i]) >= PATH_MAX) { @@ -436,6 +439,22 @@ int mainWindows(int argc, char **argv) { 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); taosCleanupArgs(); diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 565e244014..04c9093c11 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -630,4 +630,30 @@ void mndDumpSdb() { 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 diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index 4584cb817a..c33b1d4366 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -280,6 +280,7 @@ int32_t sdbReadFile(SSdb *pSdb); */ 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 * diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 6045ff80f6..dec37bfbf1 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -381,7 +381,7 @@ int32_t sdbReadFile(SSdb *pSdb) { return code; } -static int32_t sdbWriteFileImp(SSdb *pSdb) { +static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { int32_t code = 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) { + if (i == skip_type) continue; SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; @@ -550,7 +551,7 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) { } } if (code == 0) { - code = sdbWriteFileImp(pSdb); + code = sdbWriteFileImp(pSdb, -1); } if (code == 0) { if (pSdb->pWal != NULL) { @@ -566,6 +567,14 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) { return code; } +int32_t sdbWriteFileForDump(SSdb *pSdb) { + int32_t code = 0; + + code = sdbWriteFileImp(pSdb, 0); + + return code; +} + int32_t sdbDeploy(SSdb *pSdb) { int32_t code = 0; code = sdbDeployData(pSdb);