refactor
This commit is contained in:
parent
35ead50063
commit
c510e513d9
|
@ -193,7 +193,7 @@ static SDisk *tdGetDiskByName(char *dirName) {
|
|||
char fdirName[TSDB_FILENAME_LEN] = "\0";
|
||||
SDiskID *pDiskID = NULL;
|
||||
|
||||
if (tdFormatDir(dirName, fdirName) < 0) {
|
||||
if (tfsFormatDir(dirName, fdirName) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ static void tdDecDiskFiles(SDisk *pDisk, bool lock) {
|
|||
}
|
||||
}
|
||||
|
||||
static int tdFormatDir(char *idir, char *odir) {
|
||||
static int tfsFormatDir(char *idir, char *odir) {
|
||||
wordexp_t wep;
|
||||
|
||||
int code = wordexp(idir, &wep, 0);
|
||||
|
@ -295,7 +295,7 @@ static int tdAddDisk(SDiskCfg *pCfg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (tdFormatDir(pCfg->dir, dirName) < 0) {
|
||||
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
||||
uError("failed to add disk %s to tier %d level since %s", pCfg->dir, pCfg->level, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ IF (TD_LINUX)
|
|||
COMMAND ${CMAKE_COMMAND} -E echo dataDir ${TD_TESTS_OUTPUT_DIR}/data > ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
|
||||
COMMAND ${CMAKE_COMMAND} -E echo logDir ${TD_TESTS_OUTPUT_DIR}/log >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
|
||||
COMMAND ${CMAKE_COMMAND} -E echo charset UTF-8 >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
|
||||
COMMAND ${CMAKE_COMMAND} -E echo monitor 0 >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
|
||||
COMMENT "prepare taosd environment")
|
||||
ADD_CUSTOM_TARGET(${PREPARE_ENV_TARGET} ALL WORKING_DIRECTORY ${TD_EXECUTABLE_OUTPUT_PATH} DEPENDS ${PREPARE_ENV_CMD})
|
||||
ENDIF ()
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
#include "dnodeMPeer.h"
|
||||
#include "dnodeShell.h"
|
||||
#include "dnodeTelemetry.h"
|
||||
#include "tpath.h"
|
||||
#include "tmount.h"
|
||||
#include "tfs.h"
|
||||
|
||||
static SRunStatus tsRunStatus = TSDB_RUN_STATUS_STOPPED;
|
||||
|
||||
|
@ -183,46 +182,36 @@ static void dnodeCheckDataDirOpenned(char *dir) {
|
|||
}
|
||||
|
||||
static int32_t dnodeInitStorage() {
|
||||
if (tdInitMount(tsDiskCfg, tsDiskCfgNum) < 0) {
|
||||
dError("failed to add disks to dnode tier since %s", tstrerror(terrno));
|
||||
if (tfsInit(tsDiskCfg, tsDiskCfgNum) < 0) {
|
||||
dError("failed to init TFS since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
tdGetPrimaryPath(tsDataDir);
|
||||
tdGetVnodeRootDir(tsDataDir, tsVnodeDir);
|
||||
tfsPrimaryPath(tsDataDir);
|
||||
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
|
||||
tdGetMnodeRootDir(tsDataDir, tsMnodeDir);
|
||||
if (dnodeCreateDir(tsMnodeDir) < 0) {
|
||||
dError("failed to create mnode dir: %s, reason: %s", tsMnodeDir, strerror(errno));
|
||||
dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdGetDnodeRootDir(tsDataDir, tsDnodeDir);
|
||||
if (dnodeCreateDir(tsDnodeDir) < 0) {
|
||||
dError("failed to create dnode dir: %s, reason: %s", tsDnodeDir, strerror(errno));
|
||||
dError("failed to create dir: %s, reason: %s", tsDnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < tsDnodeTier->nTiers; i++) {
|
||||
char dirName[TSDB_FILENAME_LEN];
|
||||
|
||||
STier *pTier = tsDnodeTier->tiers + i;
|
||||
for (int j = 0; j < pTier->nDisks; j++) {
|
||||
SDisk *pDisk = tdGetDisk(tsDnodeTier, i, j);
|
||||
|
||||
tdGetVnodeRootDir(pDisk->dir, dirName);
|
||||
if (dnodeCreateDir(dirName) < 0) {
|
||||
dError("failed to create vnode dir: %s, reason: %s", dirName, strerror(errno));
|
||||
if (tfsCreateDir("vnode") < 0) {
|
||||
dError("failed to create vnode dir since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdGetVnodeBackRootDir(pDisk->dir, dirName);
|
||||
if (dnodeCreateDir(dirName) < 0) {
|
||||
dError("failed to create vnode back dir: %s, reason: %s", dirName, strerror(errno));
|
||||
if (tfsCreateDir("vnode_bak") < 0) {
|
||||
dError("failed to create vnode_bak dir since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dnodeCheckDataDirOpenned(tsDnodeDir);
|
||||
|
||||
|
@ -230,7 +219,7 @@ static int32_t dnodeInitStorage() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupStorage() { tdDestroyMount(); }
|
||||
static void dnodeCleanupStorage() { tfsDestroy(); }
|
||||
|
||||
bool dnodeIsFirstDeploy() {
|
||||
return strcmp(tsFirst, tsLocalEp) == 0;
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "hash.h"
|
||||
#include "taoserror.h"
|
||||
#include "trpc.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
|
|
|
@ -80,14 +80,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, 0, 0x0107, "Ref ID is
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_INVALID_ID, 0, 0x0108, "Invalid Ref ID")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_ALREADY_EXIST, 0, 0x0109, "Ref is already there")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_NOT_EXIST, 0, 0x010A, "Ref is not there")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_INVALID_DISK_TIER, 0, 0x010B, "Invalid disk tier setting")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_TOO_MANY_DISKS, 0, 0x010C, "Too many disks in one tier")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_DISK_ALREADY_EXISTS, 0, 0x010D, "Disk already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_DISK_NOT_DIRECTORY, 0, 0x010E, "Disk is not a directory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_NO_DISK_SPACE, 0, 0x010F, "Dnode no disk space")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_DUPLICATE_PRIMARY_DISK, 0, 0x0110, "Duplicate primary disk")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_LACK_PRIMARY_DISK, 0, 0x0111, "Lack primary disk")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COM_NO_DISK_AT_TIER, 0, 0x0112, "No disk at tier")
|
||||
|
||||
//client
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_SQL, 0, 0x0200, "Invalid SQL statement")
|
||||
|
|
|
@ -24,6 +24,9 @@ extern "C" {
|
|||
|
||||
int tfsInit(SDiskCfg *pDiskCfg, int ndisk);
|
||||
void tfsDestroy();
|
||||
int tfsUpdateInfo();
|
||||
void tfsPrimaryPath(char *dst);
|
||||
int tfsCreateDir(char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -38,8 +38,9 @@ typedef struct {
|
|||
SDiskMeta dmeta;
|
||||
} SDisk;
|
||||
|
||||
SDisk *tdNewDisk(SDiskID did, char *dir);
|
||||
SDisk *tdNewDisk(int level, int id, char *dir);
|
||||
void tdFreeDisk(SDisk *pDisk);
|
||||
int tdUpdateDiskInfo(SDisk *pDisk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,9 +30,12 @@ typedef struct {
|
|||
SDisk *disks[TSDB_MAX_DISK_PER_TIER];
|
||||
} STier;
|
||||
|
||||
#define DISK_AT_TIER(pTier, id) ((pTier)->disks + (id))
|
||||
|
||||
void tdInitTier(STier *pTier, int level);
|
||||
void tdDestroyTier(STier *pTier);
|
||||
SDisk *tdAddDiskToTier(STier *pTier, SDiskCfg *pCfg);
|
||||
int tdUpdateTierInfo(STier *pTier);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
|
||||
#include "tdisk.h"
|
||||
|
||||
SDisk *tdNewDisk(SDiskID did, char *dir) {
|
||||
SDisk *tdNewDisk(int level, int id, char *dir) {
|
||||
SDisk *pDisk = (SDisk *)calloc(1, sizeof(*pDisk));
|
||||
if (pDisk == NULL) {
|
||||
terrno = TSDB_CODE_FS_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pDisk->level = did.level;
|
||||
pDisk->id = did.id;
|
||||
pDisk->level = level;
|
||||
pDisk->id = id;
|
||||
strncpy(pDisk->dir, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
return pDisk;
|
||||
|
@ -34,3 +34,17 @@ void tdFreeDisk(SDisk *pDisk) {
|
|||
free(pDisk)
|
||||
}
|
||||
}
|
||||
|
||||
int tdUpdateDiskInfo(SDisk *pDisk) {
|
||||
SysDiskSize dstat;
|
||||
if (taosGetDiskSize(pDisk->dir, &dstat) < 0) {
|
||||
fError("failed to get dir %s information since %s", pDisk->dir, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pDisk->dmeta.size = dstat.tsize;
|
||||
pDisk->dmeta.free = dstat.avail;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -45,6 +45,7 @@ static SFS tdFileSystem = {0};
|
|||
static SFS *pfs = &tdFileSystem;
|
||||
|
||||
#define TIER_AT(level) (pfs->tiers + (level))
|
||||
#define DISK_AT(level, id) DISK_AT_TIER(TIER_AT(level), id)
|
||||
|
||||
int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
|
||||
ASSERT(ndisk > 0);
|
||||
|
@ -68,13 +69,13 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
|
|||
}
|
||||
|
||||
for (int idisk = 0; idisk < ndisk; idisk++) {
|
||||
if (tdAddDiskToFS(pDiskCfg + idisk) < 0) {
|
||||
if (tfsAddDisk(pDiskCfg + idisk) < 0) {
|
||||
tfsDestroy();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (tdCheckFS() < 0) {
|
||||
if (tfsCheck() < 0) {
|
||||
tfsDestroy();
|
||||
return -1;
|
||||
}
|
||||
|
@ -92,8 +93,46 @@ void tfsDestroy() {
|
|||
}
|
||||
}
|
||||
|
||||
static int tdAddDiskToFS(SDiskCfg *pCfg) {
|
||||
if (tdCheckAndFormatCfg(pCfg) < 0) return -1;
|
||||
int tfsUpdateInfo() {
|
||||
tfsLock();
|
||||
|
||||
for (int level = 0; level < pfs->nlevel; level++) {
|
||||
if (tdUpdateTierInfo(TIER_AT(level)) < 0) {
|
||||
// TODO: deal with the error here
|
||||
}
|
||||
}
|
||||
|
||||
tfsUnLock();
|
||||
}
|
||||
|
||||
void tfsPrimaryPath(char *dst) {
|
||||
strncpy(dst, DISK_AT)
|
||||
}
|
||||
|
||||
int tfsCreateDir(char *name) {
|
||||
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, name);
|
||||
|
||||
if (mkdir(dirName, 0755) != 0 && errno != EEXIST) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tfsAddDisk(SDiskCfg *pCfg) {
|
||||
if (tfsCheckAndFormatCfg(pCfg) < 0) return -1;
|
||||
|
||||
if (tdAddDiskToTier(pCfg, TIER_AT(pCfg->level)) < 0) {
|
||||
fError("failed to add disk %s to FS since %s", pCfg->dir, tstrerror(terrno));
|
||||
|
@ -105,7 +144,7 @@ static int tdAddDiskToFS(SDiskCfg *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tdCheckAndFormatCfg(SDiskCfg *pCfg) {
|
||||
static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
|
||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||
struct stat pstat;
|
||||
|
||||
|
@ -122,7 +161,7 @@ static int tdCheckAndFormatCfg(SDiskCfg *pCfg) {
|
|||
}
|
||||
|
||||
|
||||
if (tdFormatDir(pCfg->dir, dirName) < 0) {
|
||||
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
||||
fError("failed to add disk %s to FS since invalid dir format", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
|
@ -157,7 +196,7 @@ static int tdCheckAndFormatCfg(SDiskCfg *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tdFormatDir(char *idir, char *odir) {
|
||||
static int tfsFormatDir(char *idir, char *odir) {
|
||||
wordexp_t wep = {0};
|
||||
|
||||
int code = wordexp(idir, &wep, 0);
|
||||
|
@ -177,7 +216,7 @@ static int tdFormatDir(char *idir, char *odir) {
|
|||
|
||||
}
|
||||
|
||||
static int tdCheckFS() {
|
||||
static int tfsCheck() {
|
||||
if (DISK_AT(0, 0) == NULL) {
|
||||
fError("no primary disk is set");
|
||||
terrno = TSDB_CODE_FS_NO_PRIMARY_DISK;
|
||||
|
@ -194,3 +233,23 @@ static int tdCheckFS() {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tfsLock() {
|
||||
int code = pthread_mutex_lock(&(pfs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tfsUnLock() {
|
||||
int code = pthread_mutex_unlock(&(pfs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -16,8 +16,6 @@
|
|||
#include "ttier.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
#define DISK_AT_TIER(pTier, id) ((pTier)->disks + (id))
|
||||
|
||||
void tdInitTier(STier *pTier, int level) {
|
||||
pTier->level = level;
|
||||
}
|
||||
|
@ -59,8 +57,16 @@ SDisk *tdAddDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
|||
}
|
||||
}
|
||||
|
||||
pTier->disks[id] = tdNewDisk({pCfg->level, id}, pCfg->dir);
|
||||
pTier->disks[id] = tdNewDisk(pCfg->level, id, pCfg->dir);
|
||||
if (pTier->disks[id] == NULL) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdUpdateTierInfo(STier *pTier) {
|
||||
for (int id = 0; id < pTier->ndisk; id++) {
|
||||
if (tdUpdateDiskInfo(DISK_AT_TIER(pTier, id)) < 0) {
|
||||
// TODO: deal with the error here
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue