提交 3da2af00 编写于 作者: H Hongze Cheng

refactor

上级 072d42e0
......@@ -101,13 +101,13 @@ const char *tfsRelName(TFSFILE *pfile) { return pfile->rname; }
void tfsDirName(TFSFILE *pfile, char dest[]) {
char fname[TSDB_FILENAME_LEN] = "\0";
tfsAbsFname(pfile, fname);
strncpy(fname, tfsAbsName(pfile), TSDB_FILENAME_LEN);
strncpy(dest, dirname(fname), TSDB_FILENAME_LEN);
}
void tfsBaseName(TFSFILE *pfile, char dest[]) {
char fname[TSDB_FILENAME_LEN] = "\0";
memcpy((void *)fname, (void *)pfile->rname, TSDB_FILENAME_LEN);
strncpy(fname, tfsAbsName(pfile), TSDB_FILENAME_LEN);
strncpy(dest, basename(fname), TSDB_FILENAME_LEN);
}
......
......@@ -118,9 +118,10 @@ int tfsCreateDir(char *dirname) {
ASSERT(pDisk != NULL);
snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, dirname);
snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", pDisk->name, dirname);
if (mkdir(dirName, 0755) != 0 && errno != EEXIST) {
fError("failed to create directory %s since %s", dirName, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
......
......@@ -64,7 +64,7 @@ void tsdbFreeFileH(STsdbFileH *pFileH) {
}
}
int tsdbOpenFileH(STsdbRepo *pRepo) {
int tsdbOpenFileH(STsdbRepo *pRepo) { // TODO
ASSERT(pRepo != NULL && pRepo->tsdbFileH != NULL);
char dataDir[TSDB_FILENAME_LEN] = "\0";
......
......@@ -52,7 +52,10 @@ static void tsdbStopStream(STsdbRepo *pRepo);
// Function declaration
int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg) {
DIR *dir = opendir(rootDir);
char tsdbDir[TSDB_FILENAME_LEN] = "\0";
snprintf(tsdbDir, TSDB_FILENAME_LEN, "%s/%s", tfsPrimaryPath(), rootDir);
DIR *dir = tfs(tsdbDir);
if (dir) {
tsdbDebug("repository %s already exists", rootDir);
closedir(dir);
......@@ -65,12 +68,6 @@ int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg) {
}
}
if (mkdir(rootDir, 0755) < 0) {
tsdbError("vgId:%d failed to create rootDir %s since %s", pCfg->tsdbId, rootDir, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return -1;
if (tsdbSetRepoEnv(rootDir, pCfg) < 0) return -1;
......@@ -306,14 +303,14 @@ int tsdbGetState(TSDB_REPO_T *repo) {
// ----------------- INTERNAL FUNCTIONS -----------------
char *tsdbGetMetaFileName(char *rootDir) {
int tlen = (int)(strlen(rootDir) + strlen(TSDB_META_FILE_NAME) + 2);
int tlen = (int)(strlen(tfsPrimaryPath()) + strlen(rootDir) + strlen(TSDB_META_FILE_NAME) + 2);
char *fname = calloc(1, tlen);
if (fname == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return NULL;
}
snprintf(fname, tlen, "%s/%s", rootDir, TSDB_META_FILE_NAME);
snprintf(fname, tlen, "%s/%s/%s", tfsPrimaryPath(), rootDir, TSDB_META_FILE_NAME);
return fname;
}
......@@ -483,6 +480,11 @@ _err:
}
static int32_t tsdbSetRepoEnv(char *rootDir, STsdbCfg *pCfg) {
if (tfsCreateDir(rootDir) < 0) {
tsdbError("vgId:%d failed to create rootDir %s since %s", pCfg->tsdbId, rootDir, tstrerror(terrno));
return -1;
}
if (tsdbSaveConfig(rootDir, pCfg) < 0) {
tsdbError("vgId:%d failed to set TSDB environment since %s", pCfg->tsdbId, tstrerror(terrno));
return -1;
......@@ -491,9 +493,8 @@ static int32_t tsdbSetRepoEnv(char *rootDir, STsdbCfg *pCfg) {
char *dirName = tsdbGetDataDirName(rootDir);
if (dirName == NULL) return -1;
if (mkdir(dirName, 0755) < 0) {
if (tfsCreateDir(dirName) < 0) {
tsdbError("vgId:%d failed to create directory %s since %s", pCfg->tsdbId, dirName, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
free(dirName);
return -1;
}
......@@ -513,7 +514,7 @@ static int32_t tsdbSetRepoEnv(char *rootDir, STsdbCfg *pCfg) {
}
static int32_t tsdbUnsetRepoEnv(char *rootDir) {
taosRemoveDir(rootDir);
tfsRemoveDir(rootDir);
tsdbDebug("repository %s is removed", rootDir);
return 0;
}
......@@ -609,14 +610,14 @@ _err:
}
static char *tsdbGetCfgFname(char *rootDir) {
int tlen = (int)(strlen(rootDir) + strlen(TSDB_CFG_FILE_NAME) + 2);
int tlen = (int)(strlen(tfsPrimaryPath()) + strlen(rootDir) + strlen(TSDB_CFG_FILE_NAME) + 3);
char *fname = calloc(1, tlen);
if (fname == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return NULL;
}
snprintf(fname, tlen, "%s/%s", rootDir, TSDB_CFG_FILE_NAME);
snprintf(fname, tlen, "%s/%s/%s", tfsPrimaryPath(), rootDir, TSDB_CFG_FILE_NAME);
return fname;
}
......
......@@ -136,7 +136,7 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
tsdbCfg.update = pVnodeCfg->cfg.update;
char tsdbDir[TSDB_FILENAME_LEN] = {0};
sprintf(tsdbDir, "%s/vnode%d/tsdb", tsVnodeDir, pVnodeCfg->cfg.vgId);
sprintf(tsdbDir, "vnode/vnode%d/tsdb", pVnodeCfg->cfg.vgId);
if (tsdbCreateRepo(tsdbDir, &tsdbCfg) < 0) {
vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
return TSDB_CODE_VND_INIT_FAILED;
......@@ -274,7 +274,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
appH.cqH = pVnode->cq;
appH.cqCreateFunc = cqCreate;
appH.cqDropFunc = cqDrop;
sprintf(temp, "%s/tsdb", rootDir);
sprintf(temp, "vnode/vnode%d/tsdb", vnode);
terrno = 0;
pVnode->tsdb = tsdbOpenRepo(temp, &appH);
......@@ -684,7 +684,7 @@ static void vnodeCtrlFlow(int32_t vgId, int32_t mseconds) {
static int32_t vnodeResetTsdb(SVnodeObj *pVnode) {
char rootDir[128] = "\0";
sprintf(rootDir, "%s/tsdb", pVnode->rootDir);
sprintf(rootDir, "vnode/vnode%d/tsdb", pVnode->vgId);
if (pVnode->status != TAOS_VN_STATUS_CLOSING && pVnode->status != TAOS_VN_STATUS_INIT) {
pVnode->status = TAOS_VN_STATUS_RESET;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册