refact
This commit is contained in:
parent
aaa1c1ccbb
commit
cb98cd3f91
|
@ -389,6 +389,14 @@ TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_BAD_SEQ, 0, 0x2113, "src bad se
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_INCOMPLETE, 0, 0x2114, "src incomplete")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_GENERAL, 0, 0x2115, "src general")
|
||||
|
||||
// tfs
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_OUT_OF_MEMORY, 0, 0x2200, "tfs out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG 0, 0x2201, "tfs invalid mount config")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_TOO_MANY_MOUNT 0, 0x2202, "tfs too many mount")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_DUP_PRIMARY 0, 0x2203, "tfs duplicate primary mount")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_NO_PRIMARY_DISK 0, 0x2204, "tfs no primary mount")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_NO_MOUNT_AT_TIER 0, 0x2205, "tfs no mount at tier")
|
||||
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
};
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef TD_TDISK_H
|
||||
#define TD_TDISK_H
|
||||
|
||||
#include "tfslog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TD_TFSLOG_H
|
||||
#define TD_TFSLOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("FS FATAL ", 255, __VA_ARGS__); }}
|
||||
#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("FS ERROR ", 255, __VA_ARGS__); }}
|
||||
#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("FS WARN ", 255, __VA_ARGS__); }}
|
||||
#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("FS ", 255, __VA_ARGS__); }}
|
||||
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
|
||||
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -30,7 +30,7 @@ typedef struct {
|
|||
SDisk *disks[TSDB_MAX_DISK_PER_TIER];
|
||||
} STier;
|
||||
|
||||
#define DISK_AT_TIER(pTier, id) ((pTier)->disks + (id))
|
||||
#define DISK_AT_TIER(pTier, id) ((pTier)->disks[id])
|
||||
|
||||
void tdInitTier(STier *pTier, int level);
|
||||
void tdDestroyTier(STier *pTier);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "tdisk.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
SDisk *tdNewDisk(int level, int id, char *dir) {
|
||||
SDisk *pDisk = (SDisk *)calloc(1, sizeof(*pDisk));
|
||||
|
|
|
@ -14,17 +14,12 @@
|
|||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "hash.h"
|
||||
#include "ttier.h"
|
||||
#include "tglobal.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("FS FATAL ", 255, __VA_ARGS__); }}
|
||||
#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("FS ERROR ", 255, __VA_ARGS__); }}
|
||||
#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("FS WARN ", 255, __VA_ARGS__); }}
|
||||
#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("FS ", 255, __VA_ARGS__); }}
|
||||
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
|
||||
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
|
||||
#include "hash.h"
|
||||
#include "taoserror.h"
|
||||
#include "tfs.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttier.h"
|
||||
|
||||
#define TSDB_MAX_TIER 3
|
||||
|
||||
|
@ -69,7 +64,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
|
|||
}
|
||||
|
||||
for (int idisk = 0; idisk < ndisk; idisk++) {
|
||||
if (tfsAddDisk(pDiskCfg + idisk) < 0) {
|
||||
if (tfsMount(pDiskCfg + idisk) < 0) {
|
||||
tfsDestroy();
|
||||
return -1;
|
||||
}
|
||||
|
@ -106,7 +101,7 @@ int tfsUpdateInfo() {
|
|||
}
|
||||
|
||||
void tfsPrimaryPath(char *dst) {
|
||||
strncpy(dst, DISK_AT)
|
||||
strncpy(dst, DISK_AT(0, 0)->dir, TSDB_FILENAME_LEN);
|
||||
}
|
||||
|
||||
int tfsCreateDir(char *name) {
|
||||
|
@ -131,16 +126,23 @@ int tfsCreateDir(char *name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tfsAddDisk(SDiskCfg *pCfg) {
|
||||
static int tfsMount(SDiskCfg *pCfg) {
|
||||
SDiskID did;
|
||||
|
||||
if (tfsCheckAndFormatCfg(pCfg) < 0) return -1;
|
||||
|
||||
if (tdAddDiskToTier(pCfg, TIER_AT(pCfg->level)) < 0) {
|
||||
did.level = pCfg->level;
|
||||
did.id = tdAddDiskToTier(TIER_AT(pCfg->level), pCfg);
|
||||
if (did.id < 0) {
|
||||
fError("failed to add disk %s to FS since %s", pCfg->dir, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosHashPut(pTiers->map, (void *)dirName, strnlen(dirName, TSDB_FILENAME_LEN), (void *)(&diskid), sizeof(diskid));
|
||||
taosHashPut(pTiers->map, pCfg->dir, strnlen(pCfg->dir, TSDB_FILENAME_LEN), (void *)(&did), sizeof(did));
|
||||
if (pfs->nlevel < pCfg->level + 1) pfs->nlevel = pCfg->level + 1;
|
||||
|
||||
// TODO: update meta info
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -154,12 +156,19 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->primary && pCfg->level != 0) {
|
||||
if (pCfg->primary) {
|
||||
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);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (DISK_AT(0, 0) != NULL) {
|
||||
fError("failed to add disk %s to FS since duplicate primary mount", pCfg->dir, pCfg->level);
|
||||
terrno = TSDB_CODE_FS_DUP_PRIMARY;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
||||
fError("failed to add disk %s to FS since invalid dir format", pCfg->dir);
|
||||
|
@ -167,14 +176,14 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (tdGetDiskByName(dirName)) {
|
||||
fError("failed to add disk %s to FS since duplicate add", pCfg->dir);
|
||||
if (tfsGetDiskByName(dirName) != NULL) {
|
||||
fError("failed to add disk %s to FS since duplicate mount", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (access(dirName, W_OK | R_OK | F_OK) != 0) {
|
||||
fError("failed to add disk %s to FS since no enough access rights", pCfg->dir);
|
||||
fError("failed to add disk %s to FS since no R/W access rights", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
@ -223,13 +232,14 @@ static int tfsCheck() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
for (int level = 0; level < pfs->nlevel; level++) {
|
||||
int level = 0;
|
||||
do {
|
||||
if (TIER_AT(level)->ndisk == 0) {
|
||||
fError("no disk at level %d", level);
|
||||
terrno = TSDB_CODE_FS_NO_DISK_AT_TIER;
|
||||
terrno = TSDB_CODE_FS_NO_MOUNT_AT_TIER;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} while (level < pfs->nlevel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -253,3 +263,8 @@ static tfsUnLock() {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tfsGetDiskByName(char *dirName) {
|
||||
}
|
||||
|
||||
static SDisk *tfsGetDiskByID(SDiskID did) { return DISK_AT(did.level, did.id); }
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "ttier.h"
|
||||
#include "tglobal.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
void tdInitTier(STier *pTier, int level) {
|
||||
pTier->level = level;
|
||||
|
@ -23,8 +24,9 @@ void tdInitTier(STier *pTier, int level) {
|
|||
void tdDestroyTier(STier *pTier) {
|
||||
for (int id = 0; id < TSDB_MAX_DISK_PER_TIER; id++) {
|
||||
tdFreeDisk(DISK_AT_TIER(pTier, id));
|
||||
DISK_AT_TIER(pTier, id) = NULL;
|
||||
pTier->disks[id] = NULL;
|
||||
}
|
||||
pTier->ndisk = 0;
|
||||
}
|
||||
|
||||
SDisk *tdAddDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
||||
|
@ -32,35 +34,29 @@ SDisk *tdAddDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
|||
int id = 0;
|
||||
|
||||
if (pTier->ndisk >= TSDB_MAX_DISK_PER_TIER) {
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_DISKS;
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->primary) {
|
||||
if (DISK_AT(0, 0) != NULL) {
|
||||
terrno = TSDB_CODE_FS_DUP_PRIMARY;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (pTier->level == 0) {
|
||||
if (DISK_AT_TIER(pTier, 0) != NULL) {
|
||||
id = pTier->ndisk;
|
||||
} else {
|
||||
id = pTier->ndisk + 1;
|
||||
if (id >= TSDB_MAX_DISK_PER_TIER) {
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_DISKS;
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
id = pTier->ndisk;
|
||||
}
|
||||
}
|
||||
|
||||
pTier->disks[id] = tdNewDisk(pCfg->level, id, pCfg->dir);
|
||||
if (pTier->disks[id] == NULL) return -1;
|
||||
pTier->ndisk++;
|
||||
|
||||
return 0;
|
||||
return id;
|
||||
}
|
||||
|
||||
int tdUpdateTierInfo(STier *pTier) {
|
||||
|
|
Loading…
Reference in New Issue