[TD-1920]add mnode compact wal functions
This commit is contained in:
parent
99f7359390
commit
9958b3d8d2
|
@ -149,6 +149,8 @@ extern char configDir[];
|
|||
extern char tsVnodeDir[];
|
||||
extern char tsDnodeDir[];
|
||||
extern char tsMnodeDir[];
|
||||
extern char tsMnodeBakDir[];
|
||||
extern char tsMnodeTmpDir[];
|
||||
extern char tsDataDir[];
|
||||
extern char tsLogDir[];
|
||||
extern char tsScriptDir[];
|
||||
|
|
|
@ -183,6 +183,8 @@ char configDir[TSDB_FILENAME_LEN] = {0};
|
|||
char tsVnodeDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsDnodeDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsMnodeDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsMnodeTmpDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsMnodeBakDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsDataDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsScriptDir[TSDB_FILENAME_LEN] = {0};
|
||||
char tsTempDir[TSDB_FILENAME_LEN] = "/tmp/";
|
||||
|
|
|
@ -217,6 +217,17 @@ static int32_t dnodeInitStorage() {
|
|||
sprintf(tsDnodeDir, "%s/dnode", tsDataDir);
|
||||
// sprintf(tsVnodeBakDir, "%s/vnode_bak", tsDataDir);
|
||||
|
||||
if (tsCompactMnodeWal == 1) {
|
||||
sprintf(tsMnodeTmpDir, "%s/mnode_tmp", tsDataDir);
|
||||
tfsRmdir(tsMnodeTmpDir);
|
||||
if (dnodeCreateDir(tsMnodeTmpDir) < 0) {
|
||||
dError("failed to create dir: %s, reason: %s", tsMnodeTmpDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(tsMnodeBakDir, "%s/mnode_bak", tsDataDir);
|
||||
//tfsRmdir(tsMnodeBakDir);
|
||||
}
|
||||
//TODO(dengyihao): no need to init here
|
||||
if (dnodeCreateDir(tsMnodeDir) < 0) {
|
||||
dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno));
|
||||
|
|
|
@ -59,8 +59,6 @@ static SStep tsMnodeSteps[] = {
|
|||
|
||||
static SStep tsMnodeCompactSteps[] = {
|
||||
{"cluster", mnodeCompactCluster, NULL},
|
||||
|
||||
/*
|
||||
{"dnodes", mnodeCompactDnodes, NULL},
|
||||
{"mnodes", mnodeCompactMnodes, NULL},
|
||||
{"accts", mnodeCompactAccts, NULL},
|
||||
|
@ -68,7 +66,7 @@ static SStep tsMnodeCompactSteps[] = {
|
|||
{"dbs", mnodeCompactDbs, NULL},
|
||||
{"vgroups", mnodeCompactVgroups, NULL},
|
||||
{"tables", mnodeCompactTables, NULL},
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
static void mnodeInitTimer();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "tutil.h"
|
||||
#include "tref.h"
|
||||
#include "tbn.h"
|
||||
#include "tfs.h"
|
||||
#include "tqueue.h"
|
||||
#include "twal.h"
|
||||
#include "tsync.h"
|
||||
|
@ -1154,26 +1155,42 @@ int32_t sdbGetReplicaNum() {
|
|||
int32_t mnodeCompactWal() {
|
||||
sdbInfo("vgId:1, start compact mnode wal...");
|
||||
|
||||
// close wal
|
||||
// close old wal
|
||||
walFsync(tsSdbMgmt.wal, true);
|
||||
walClose(tsSdbMgmt.wal);
|
||||
|
||||
// change wal to wal_bak dir
|
||||
char temp[TSDB_FILENAME_LEN] = {0};
|
||||
// reset version,then compacted wal log can start from version 1
|
||||
tsSdbMgmt.version = 0;
|
||||
|
||||
// change wal to wal_tmp dir
|
||||
SWalCfg walCfg = {.vgId = 1, .walLevel = TAOS_WAL_FSYNC, .keep = TAOS_WAL_KEEP, .fsyncPeriod = 0};
|
||||
sprintf(temp, "%s/wal_tmp", tsMnodeDir);
|
||||
if (mkdir(temp, 0755) != 0 && errno != EEXIST) {
|
||||
return -1;
|
||||
}
|
||||
char temp[TSDB_FILENAME_LEN] = {0};
|
||||
sprintf(temp, "%s/wal", tsMnodeTmpDir);
|
||||
tsSdbMgmt.wal = walOpen(temp, &walCfg);
|
||||
walRenew(tsSdbMgmt.wal);
|
||||
|
||||
// compact memory tables info to wal tmp dir
|
||||
mnodeCompactComponents();
|
||||
if (mnodeCompactComponents() != 0) {
|
||||
tfsRmdir(tsMnodeTmpDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// close wal
|
||||
walFsync(tsSdbMgmt.wal, true);
|
||||
walClose(tsSdbMgmt.wal);
|
||||
|
||||
// rename old wal to wal_bak
|
||||
if (taosRename(tsMnodeDir, tsMnodeBakDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// rename wal_tmp to wal
|
||||
if (taosRename(tsMnodeTmpDir, tsMnodeDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// del wal_tmp dir
|
||||
sdbInfo("vgId:1, compact mnode wal success");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue