提交 f1f7d556 编写于 作者: L lichuang

[TD-1920]add mnode_bak and mnode_tmp dir exist check when start up

上级 6b3e339c
...@@ -219,14 +219,20 @@ static int32_t dnodeInitStorage() { ...@@ -219,14 +219,20 @@ static int32_t dnodeInitStorage() {
if (tsCompactMnodeWal == 1) { if (tsCompactMnodeWal == 1) {
sprintf(tsMnodeTmpDir, "%s/mnode_tmp", tsDataDir); sprintf(tsMnodeTmpDir, "%s/mnode_tmp", tsDataDir);
tfsRmdir(tsMnodeTmpDir); if (taosDirExist(tsMnodeTmpDir)) {
dError("mnode_tmp dir already exist in %s,quit compact job", tsMnodeTmpDir);
return -1;
}
if (dnodeCreateDir(tsMnodeTmpDir) < 0) { if (dnodeCreateDir(tsMnodeTmpDir) < 0) {
dError("failed to create dir: %s, reason: %s", tsMnodeTmpDir, strerror(errno)); dError("failed to create dir: %s, reason: %s", tsMnodeTmpDir, strerror(errno));
return -1; return -1;
} }
sprintf(tsMnodeBakDir, "%s/mnode_bak", tsDataDir); sprintf(tsMnodeBakDir, "%s/mnode_bak", tsDataDir);
//tfsRmdir(tsMnodeBakDir); if (taosDirExist(tsMnodeBakDir)) {
dError("mnode_bak dir already exist in %s,quit compact job", tsMnodeBakDir);
return -1;
}
} }
//TODO(dengyihao): no need to init here //TODO(dengyihao): no need to init here
if (dnodeCreateDir(tsMnodeDir) < 0) { if (dnodeCreateDir(tsMnodeDir) < 0) {
......
...@@ -21,6 +21,7 @@ extern "C" { ...@@ -21,6 +21,7 @@ extern "C" {
#endif #endif
void taosRemoveDir(char *rootDir); void taosRemoveDir(char *rootDir);
bool taosDirExist(const char* dirname);
int32_t taosMkDir(const char *pathname, mode_t mode); int32_t taosMkDir(const char *pathname, mode_t mode);
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays); void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
int32_t taosRename(char *oldName, char *newName); int32_t taosRename(char *oldName, char *newName);
......
...@@ -45,6 +45,10 @@ void taosRemoveDir(char *rootDir) { ...@@ -45,6 +45,10 @@ void taosRemoveDir(char *rootDir) {
uInfo("dir:%s is removed", rootDir); uInfo("dir:%s is removed", rootDir);
} }
bool taosDirExist(const char* dirname) {
return access(dirname, F_OK) == 0;
}
int taosMkDir(const char *path, mode_t mode) { int taosMkDir(const char *path, mode_t mode) {
int code = mkdir(path, 0755); int code = mkdir(path, 0755);
if (code < 0 && errno == EEXIST) code = 0; if (code < 0 && errno == EEXIST) code = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册