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