diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index af1d7dd44187449af02c75dc1b80e6d7e2657ac3..e7927605cbfe9b0d07efe351dd67e308d5b74173 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -117,6 +117,7 @@ extern char tsDataDir[]; extern char tsLogDir[]; extern char tsScriptDir[]; extern int64_t tsMsPerDay[3]; +extern char tsVnodeBakDir[]; // system info extern char tsOsName[]; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 0fb63c04767a61c3b66df0a2e27342d81077590e..225f12a2100f0e3204ff6525ecfc2c6a62ab10f1 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -153,6 +153,7 @@ char tsDnodeDir[TSDB_FILENAME_LEN] = {0}; char tsMnodeDir[TSDB_FILENAME_LEN] = {0}; char tsDataDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; char tsScriptDir[TSDB_FILENAME_LEN] = "/etc/taos"; +char tsVnodeBakDir[TSDB_FILENAME_LEN] = {0}; /* * minimum scale for whole system, millisecond by default diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 2ec87cbdd4598e6a20bb33c7009e3dd94dd07d23..8d1ae0a50ee90993d8d8d0a1b87a50c3f51bfe75 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -171,6 +171,7 @@ static int32_t dnodeInitStorage() { sprintf(tsMnodeDir, "%s/mnode", tsDataDir); sprintf(tsVnodeDir, "%s/vnode", tsDataDir); sprintf(tsDnodeDir, "%s/dnode", tsDataDir); + sprintf(tsVnodeBakDir, "%s/vnode_bak", tsDataDir); //TODO(dengyihao): no need to init here if (dnodeCreateDir(tsMnodeDir) < 0) { @@ -186,6 +187,10 @@ static int32_t dnodeInitStorage() { dError("failed to create dir: %s, reason: %s", tsDnodeDir, strerror(errno)); return -1; } + if (dnodeCreateDir(tsVnodeBakDir) < 0) { + dError("failed to create dir: %s, reason: %s", tsVnodeBakDir, strerror(errno)); + return -1; + } dnodeCheckDataDirOpenned(tsDnodeDir); diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index 35d2236001cf27f29864baf2e48e725ab5f4a507..58e255f7bc95ed0b1bf322554980c0efe432d9e9 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -236,6 +236,9 @@ void taosSetCoreDump(); void taosBlockSIGPIPE(); +int tSystem(const char * cmd) ; + + #ifdef _ALPINE typedef int(*__compar_fn_t)(const void *, const void *); void error (int, int, const char *); diff --git a/src/os/linux/src/linuxPlatform.c b/src/os/linux/src/linuxPlatform.c index a8ecf43c46a63841fc659b043958adb9cdc6d960..9a38c98f81c36ad779c990fd40ca1d7395ffd3f8 100644 --- a/src/os/linux/src/linuxPlatform.c +++ b/src/os/linux/src/linuxPlatform.c @@ -241,3 +241,32 @@ void taosBlockSIGPIPE() { uError("failed to block SIGPIPE"); } } + +int tSystem(const char * cmd) +{ + FILE * fp; + int res; + char buf[1024]; + if (cmd == NULL) { + uError("tSystem cmd is NULL!\n"); + return -1; + } + + if ((fp = popen(cmd, "r") ) == NULL) { + uError("popen cmd:%s error: %s/n", cmd, strerror(errno)); + return -1; + } else { + while(fgets(buf, sizeof(buf), fp)) { + uDebug("popen result:%s", buf); + } + + if ((res = pclose(fp)) == -1) { + uError("close popen file pointer fp error!\n"); + } else { + uDebug("popen res is :%d\n", res); + } + + return res; + } +} + diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 949e9eb10972657e8bd72e49124c217bdb1679a0..1ba57bbaaa670cbd9aca7b19252a3bd745187130 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -184,6 +184,7 @@ uint32_t ip2uint(const char *const ip_addr); void taosRemoveDir(char *rootDir); int tmkdir(const char *pathname, mode_t mode); +void taosMvDir(char* destDir, char *srcDir); #define TAOS_ALLOC_MODE_DEFAULT 0 #define TAOS_ALLOC_MODE_RANDOM_FAIL 1 diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index cc720eb5f79cee2e66dbc9dd45bf2f280a1dfba4..9c5bffef953b1bd2fc48b8ffc20a60d0e0fa126f 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -799,3 +799,13 @@ int tmkdir(const char *path, mode_t mode) { if (code < 0 && errno == EEXIST) code = 0; return code; } + +void taosMvDir(char* destDir, char *srcDir) { + char shellCmd[1024+1] = {0}; + + //(void)snprintf(shellCmd, 1024, "cp -rf %s %s", srcDir, destDir); + (void)snprintf(shellCmd, 1024, "mv %s %s", srcDir, destDir); + tSystem(shellCmd); + uInfo("shell cmd:%s is executed", shellCmd); +} + diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index cbd79530729da06254a1879ec00fcb5c80ad75a0..f71f6adefbe3923aa877bdbc0ad3a93ffb5a8cc8 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -347,6 +347,7 @@ void vnodeRelease(void *pVnodeRaw) { if (pVnode->status == TAOS_VN_STATUS_DELETING) { char rootDir[TSDB_FILENAME_LEN] = {0}; sprintf(rootDir, "%s/vnode%d", tsVnodeDir, vgId); + taosMvDir(tsVnodeBakDir, rootDir); taosRemoveDir(rootDir); }