refactor more
This commit is contained in:
parent
bf33887d0c
commit
702ec72e6f
|
@ -36,7 +36,9 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk);
|
||||||
void tfsDestroy();
|
void tfsDestroy();
|
||||||
int tfsUpdateInfo();
|
int tfsUpdateInfo();
|
||||||
void tfsPrimaryPath(char *dst);
|
void tfsPrimaryPath(char *dst);
|
||||||
int tfsCreateDir(char *name);
|
int tfsCreateDir(char *dirname);
|
||||||
|
int tfsRemoveDir(char *dirname);
|
||||||
|
int tfsRename(char *oldpath, char *newpath);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ void tfsPrimaryPath(char *dst) {
|
||||||
strncpy(dst, DISK_AT(0, 0)->dir, TSDB_FILENAME_LEN);
|
strncpy(dst, DISK_AT(0, 0)->dir, TSDB_FILENAME_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tfsCreateDir(char *name) {
|
int tfsCreateDir(char *dirname) {
|
||||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
for (int level = 0; level < pfs->nlevel; level++) {
|
for (int level = 0; level < pfs->nlevel; level++) {
|
||||||
|
@ -114,7 +114,7 @@ int tfsCreateDir(char *name) {
|
||||||
|
|
||||||
ASSERT(pDisk != NULL);
|
ASSERT(pDisk != NULL);
|
||||||
|
|
||||||
snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, name);
|
snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, dirname);
|
||||||
|
|
||||||
if (mkdir(dirName, 0755) != 0 && errno != EEXIST) {
|
if (mkdir(dirName, 0755) != 0 && errno != EEXIST) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
@ -126,6 +126,46 @@ int tfsCreateDir(char *name) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tfsRemoveDir(char *dirname) {
|
||||||
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
for (int level = 0; level < pfs->nlevel; level++) {
|
||||||
|
STier *pTier = TIER_AT(level);
|
||||||
|
for (int id = 0; id < pTier->ndisk; id++) {
|
||||||
|
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
||||||
|
|
||||||
|
ASSERT(pDisk != NULL);
|
||||||
|
|
||||||
|
snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, dirname);
|
||||||
|
|
||||||
|
taosRemoveDir(dirName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tfsRename(char *oldpath, char *newpath) {
|
||||||
|
char oldName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
char newName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
for (int level = 0; level < pfs->nlevel; level++) {
|
||||||
|
STier *pTier = TIER_AT(level);
|
||||||
|
for (int id = 0; id < pTier->ndisk; id++) {
|
||||||
|
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
||||||
|
|
||||||
|
ASSERT(pDisk != NULL);
|
||||||
|
|
||||||
|
snprintf(oldName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, oldpath);
|
||||||
|
snprintf(newName, TSDB_FILENAME_LEN, "%s/%s", pDisk->dir, newpath);
|
||||||
|
|
||||||
|
taosRename(oldName, newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int tfsMount(SDiskCfg *pCfg) {
|
static int tfsMount(SDiskCfg *pCfg) {
|
||||||
SDiskID did;
|
SDiskID did;
|
||||||
|
|
||||||
|
@ -134,7 +174,7 @@ static int tfsMount(SDiskCfg *pCfg) {
|
||||||
did.level = pCfg->level;
|
did.level = pCfg->level;
|
||||||
did.id = tdAddDiskToTier(TIER_AT(pCfg->level), pCfg);
|
did.id = tdAddDiskToTier(TIER_AT(pCfg->level), pCfg);
|
||||||
if (did.id < 0) {
|
if (did.id < 0) {
|
||||||
fError("failed to add disk %s to FS since %s", pCfg->dir, tstrerror(terrno));
|
fError("failed to mount %s to FS since %s", pCfg->dir, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,51 +191,51 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
|
||||||
struct stat pstat;
|
struct stat pstat;
|
||||||
|
|
||||||
if (pCfg->level < 0 || pCfg->level >= TSDB_MAX_TIER) {
|
if (pCfg->level < 0 || pCfg->level >= TSDB_MAX_TIER) {
|
||||||
fError("failed to add disk %s to FS since invalid level %d", pCfg->dir, pCfg->level);
|
fError("failed to mount %s to FS since invalid level %d", pCfg->dir, pCfg->level);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCfg->primary) {
|
if (pCfg->primary) {
|
||||||
if (pCfg->level != 0) {
|
if (pCfg->level != 0) {
|
||||||
fError("failed to add disk %s to FS since disk is primary but level %d not 0", pCfg->dir, pCfg->level);
|
fError("failed to mount %s to FS since disk is primary but level %d not 0", pCfg->dir, pCfg->level);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DISK_AT(0, 0) != NULL) {
|
if (DISK_AT(0, 0) != NULL) {
|
||||||
fError("failed to add disk %s to FS since duplicate primary mount", pCfg->dir, pCfg->level);
|
fError("failed to mount %s to FS since duplicate primary mount", pCfg->dir, pCfg->level);
|
||||||
terrno = TSDB_CODE_FS_DUP_PRIMARY;
|
terrno = TSDB_CODE_FS_DUP_PRIMARY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
||||||
fError("failed to add disk %s to FS since invalid dir format", pCfg->dir);
|
fError("failed to mount %s to FS since invalid dir format", pCfg->dir);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tfsGetDiskByName(dirName) != NULL) {
|
if (tfsGetDiskByName(dirName) != NULL) {
|
||||||
fError("failed to add disk %s to FS since duplicate mount", pCfg->dir);
|
fError("failed to mount %s to FS since duplicate mount", pCfg->dir);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(dirName, W_OK | R_OK | F_OK) != 0) {
|
if (access(dirName, W_OK | R_OK | F_OK) != 0) {
|
||||||
fError("failed to add disk %s to FS since no R/W access rights", pCfg->dir);
|
fError("failed to mount %s to FS since no R/W access rights", pCfg->dir);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(dirName, &pstat) < 0) {
|
if (stat(dirName, &pstat) < 0) {
|
||||||
fError("failed to add disk %s to FS since %s", pCfg->dir, strerror(errno));
|
fError("failed to mount %s to FS since %s", pCfg->dir, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISDIR(pstat.st_mode)) {
|
if (!S_ISDIR(pstat.st_mode)) {
|
||||||
fError("failed to add disk %s to FS since not a directory", pCfg->dir);
|
fError("failed to mount %s to FS since not a directory", pCfg->dir);
|
||||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,15 @@
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "dnode.h"
|
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
|
#include "query.h"
|
||||||
|
#include "dnode.h"
|
||||||
#include "vnodeCfg.h"
|
#include "vnodeCfg.h"
|
||||||
#include "vnodeVersion.h"
|
#include "vnodeVersion.h"
|
||||||
#include "dnodeVWrite.h"
|
#include "dnodeVWrite.h"
|
||||||
#include "dnodeVRead.h"
|
#include "dnodeVRead.h"
|
||||||
#include "query.h"
|
#include "tfs.h"
|
||||||
|
|
||||||
static SHashObj*tsVnodesHash;
|
static SHashObj*tsVnodesHash;
|
||||||
static void vnodeCleanUp(SVnodeObj *pVnode);
|
static void vnodeCleanUp(SVnodeObj *pVnode);
|
||||||
|
@ -99,32 +100,19 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(tsVnodeDir, 0755) != 0 && errno != EEXIST) {
|
if (tfsCreateDir("vnode") < 0) {
|
||||||
vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), tsVnodeDir);
|
vError("vgId:%d, failed to create vnode dir, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||||
if (errno == EACCES) {
|
return terrno;
|
||||||
return TSDB_CODE_VND_NO_DISK_PERMISSIONS;
|
|
||||||
} else if (errno == ENOSPC) {
|
|
||||||
return TSDB_CODE_VND_NO_DISKSPACE;
|
|
||||||
} else if (errno == ENOENT) {
|
|
||||||
return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR;
|
|
||||||
} else {
|
|
||||||
return TSDB_CODE_VND_INIT_FAILED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char rootDir[TSDB_FILENAME_LEN] = {0};
|
char rootDir[TSDB_FILENAME_LEN] = {0};
|
||||||
tdGetVnodeDir(tsDataDir, pVnodeCfg->cfg.vgId, rootDir);
|
sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId);
|
||||||
if (mkdir(rootDir, 0755) != 0 && errno != EEXIST) {
|
|
||||||
vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir);
|
char vnodeDir[TSDB_FILENAME_LEN] = "\0";
|
||||||
if (errno == EACCES) {
|
snprintf(vnodeDir, TSDB_FILENAME_LEN, "vnode%d", pVnodeCfg->cfg.vgId);
|
||||||
return TSDB_CODE_VND_NO_DISK_PERMISSIONS;
|
if (tfsCreateDir(vnodeDir) < 0) {
|
||||||
} else if (errno == ENOSPC) {
|
vError("vgId:%d, failed to create vnode %d dir, reason:%s", pVnodeCfg->cfg.vgId, strerror(errno));
|
||||||
return TSDB_CODE_VND_NO_DISKSPACE;
|
return terrno;
|
||||||
} else if (errno == ENOENT) {
|
|
||||||
return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR;
|
|
||||||
} else {
|
|
||||||
return TSDB_CODE_VND_INIT_FAILED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = vnodeWriteCfg(pVnodeCfg);
|
code = vnodeWriteCfg(pVnodeCfg);
|
||||||
|
@ -146,7 +134,7 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
||||||
tsdbCfg.update = pVnodeCfg->cfg.update;
|
tsdbCfg.update = pVnodeCfg->cfg.update;
|
||||||
|
|
||||||
char tsdbDir[TSDB_FILENAME_LEN] = {0};
|
char tsdbDir[TSDB_FILENAME_LEN] = {0};
|
||||||
tdGetTsdbRootDir(tsDataDir, pVnodeCfg->cfg.vgId, tsdbDir);
|
sprintf(tsdbDir, "%s/vnode%d/tsdb", tsVnodeDir, pVnodeCfg->cfg.vgId);
|
||||||
if (tsdbCreateRepo(tsdbDir, &tsdbCfg) < 0) {
|
if (tsdbCreateRepo(tsdbDir, &tsdbCfg) < 0) {
|
||||||
vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||||
return TSDB_CODE_VND_INIT_FAILED;
|
return TSDB_CODE_VND_INIT_FAILED;
|
||||||
|
@ -445,28 +433,17 @@ void vnodeRelease(void *vparam) {
|
||||||
if (pVnode->dropped) {
|
if (pVnode->dropped) {
|
||||||
char rootDir[TSDB_FILENAME_LEN] = {0};
|
char rootDir[TSDB_FILENAME_LEN] = {0};
|
||||||
char newDir[TSDB_FILENAME_LEN] = {0};
|
char newDir[TSDB_FILENAME_LEN] = {0};
|
||||||
|
sprintf(rootDir, "%s/vnode%d", "vnode", vgId);
|
||||||
|
sprintf(newDir, "%s/vnode%d", "vnode_bak", vgId);
|
||||||
|
|
||||||
for (int i = 0; i < tsDnodeTier->nTiers; i++) {
|
|
||||||
STier *pTier = tsDnodeTier->tiers + i;
|
|
||||||
for (int j = 0; j < pTier->nDisks; j++) {
|
|
||||||
SDisk *pDisk = pTier->disks[j];
|
|
||||||
|
|
||||||
tdGetVnodeDir(pDisk->dir, vgId, rootDir);
|
|
||||||
tdGetVnodeBackDir(pDisk->dir, vgId, newDir);
|
|
||||||
|
|
||||||
if (access(rootDir, F_OK) == 0) {
|
|
||||||
if (0 == tsEnableVnodeBak) {
|
if (0 == tsEnableVnodeBak) {
|
||||||
vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId);
|
vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId);
|
||||||
} else {
|
} else {
|
||||||
taosRemoveDir(newDir);
|
tfsRemoveDir(newDir);
|
||||||
taosRename(rootDir, newDir);
|
tfsRename(rootDir, newDir);
|
||||||
}
|
|
||||||
|
|
||||||
taosRemoveDir(rootDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tfsRemoveDir(rootDir);
|
||||||
dnodeSendStatusMsgToMnode();
|
dnodeSendStatusMsgToMnode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue