add error codes
This commit is contained in:
parent
ba42f8cd93
commit
9e4141fa6d
|
@ -406,7 +406,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) //"WAL out of memory")
|
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) //"WAL out of memory")
|
||||||
|
|
||||||
// tfs
|
// tfs
|
||||||
#define TSDB_CODE_FS_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory")
|
#define TSDB_CODE_FS_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory")
|
||||||
#define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) //"tfs invalid mount config")
|
#define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) //"tfs invalid mount config")
|
||||||
#define TSDB_CODE_FS_TOO_MANY_MOUNT TAOS_DEF_ERROR_CODE(0, 0x2202) //"tfs too many mount")
|
#define TSDB_CODE_FS_TOO_MANY_MOUNT TAOS_DEF_ERROR_CODE(0, 0x2202) //"tfs too many mount")
|
||||||
#define TSDB_CODE_FS_DUP_PRIMARY TAOS_DEF_ERROR_CODE(0, 0x2203) //"tfs duplicate primary mount")
|
#define TSDB_CODE_FS_DUP_PRIMARY TAOS_DEF_ERROR_CODE(0, 0x2203) //"tfs duplicate primary mount")
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
extern int fsDebugFlag;
|
extern int32_t fsDebugFlag;
|
||||||
|
|
||||||
// For debug purpose
|
// For debug purpose
|
||||||
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", 255, __VA_ARGS__); }}
|
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", 255, __VA_ARGS__); }}
|
||||||
|
@ -47,8 +47,8 @@ typedef struct {
|
||||||
} SDiskMeta;
|
} SDiskMeta;
|
||||||
|
|
||||||
typedef struct SDisk {
|
typedef struct SDisk {
|
||||||
int level;
|
int32_t level;
|
||||||
int id;
|
int32_t id;
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
SDiskMeta dmeta;
|
SDiskMeta dmeta;
|
||||||
} SDisk;
|
} SDisk;
|
||||||
|
@ -61,19 +61,19 @@ typedef struct SDisk {
|
||||||
#define DISK_USED_SIZE(pd) ((pd)->dmeta.used)
|
#define DISK_USED_SIZE(pd) ((pd)->dmeta.used)
|
||||||
#define DISK_FREE_SIZE(pd) ((pd)->dmeta.free)
|
#define DISK_FREE_SIZE(pd) ((pd)->dmeta.free)
|
||||||
|
|
||||||
SDisk *tfsNewDisk(int level, int id, const char *dir);
|
SDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir);
|
||||||
SDisk *tfsFreeDisk(SDisk *pDisk);
|
SDisk *tfsFreeDisk(SDisk *pDisk);
|
||||||
int tfsUpdateDiskInfo(SDisk *pDisk);
|
int32_t tfsUpdateDiskInfo(SDisk *pDisk);
|
||||||
|
|
||||||
// ttier.c ======================================================
|
// ttier.c ======================================================
|
||||||
|
|
||||||
typedef struct STier {
|
typedef struct STier {
|
||||||
pthread_spinlock_t lock;
|
pthread_spinlock_t lock;
|
||||||
int level;
|
int32_t level;
|
||||||
int16_t ndisk; // # of disks mounted to this tier
|
int16_t ndisk; // # of disks mounted to this tier
|
||||||
int16_t nextid; // next disk id to allocate
|
int16_t nextid; // next disk id to allocate
|
||||||
STierMeta tmeta;
|
STierMeta tmeta;
|
||||||
SDisk * disks[TSDB_MAX_DISKS_PER_TIER];
|
SDisk *disks[TSDB_MAX_DISKS_PER_TIER];
|
||||||
} STier;
|
} STier;
|
||||||
|
|
||||||
#define TIER_LEVEL(pt) ((pt)->level)
|
#define TIER_LEVEL(pt) ((pt)->level)
|
||||||
|
@ -83,12 +83,11 @@ typedef struct STier {
|
||||||
#define TIER_AVAIL_DISKS(pt) ((pt)->tmeta.nAvailDisks)
|
#define TIER_AVAIL_DISKS(pt) ((pt)->tmeta.nAvailDisks)
|
||||||
#define DISK_AT_TIER(pt, id) ((pt)->disks[id])
|
#define DISK_AT_TIER(pt, id) ((pt)->disks[id])
|
||||||
|
|
||||||
int tfsInitTier(STier *pTier, int level);
|
int32_t tfsInitTier(STier *pTier, int32_t level);
|
||||||
void tfsDestroyTier(STier *pTier);
|
void tfsDestroyTier(STier *pTier);
|
||||||
SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg);
|
SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg);
|
||||||
void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta);
|
void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta);
|
||||||
int tfsAllocDiskOnTier(STier *pTier);
|
int32_t tfsAllocDiskOnTier(STier *pTier);
|
||||||
void tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta);
|
|
||||||
void tfsPosNextId(STier *pTier);
|
void tfsPosNextId(STier *pTier);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
SDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir) {
|
SDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir) {
|
||||||
SDisk *pDisk = calloc(1, sizeof(SDisk));
|
SDisk *pDisk = calloc(1, sizeof(SDisk));
|
||||||
if (pDisk == NULL) {
|
if (pDisk == NULL) {
|
||||||
terrno = TSDB_CODE_FS_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ SDisk *tfsFreeDisk(SDisk *pDisk) {
|
||||||
if (pDisk != NULL) {
|
if (pDisk != NULL) {
|
||||||
free(pDisk);
|
free(pDisk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,17 +45,15 @@ int32_t tfsUpdateDiskInfo(SDisk *pDisk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SysDiskSize diskSize = {0};
|
SysDiskSize diskSize = {0};
|
||||||
|
if (taosGetDiskSize(pDisk->dir, &diskSize) != 0) {
|
||||||
int32_t code = taosGetDiskSize(pDisk->dir, &diskSize);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
if (code != 0) {
|
|
||||||
fError("failed to update disk information at level %d id %d dir %s since %s", pDisk->level, pDisk->id, pDisk->dir,
|
fError("failed to update disk information at level %d id %d dir %s since %s", pDisk->level, pDisk->id, pDisk->dir,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
pDisk->dmeta.size = diskSize.tsize;
|
pDisk->dmeta.size = diskSize.tsize;
|
||||||
pDisk->dmeta.used = diskSize.used;
|
pDisk->dmeta.used = diskSize.used;
|
||||||
pDisk->dmeta.free = diskSize.avail;
|
pDisk->dmeta.free = diskSize.avail;
|
||||||
|
return 0;
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,45 +16,50 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "tfsInt.h"
|
#include "tfsInt.h"
|
||||||
|
|
||||||
#define tfsLockTier(pTier) pthread_spin_lock(&((pTier)->lock))
|
#define tfsLockTier(pTier) pthread_spin_lock(&(pTier)->lock)
|
||||||
#define tfsUnLockTier(pTier) pthread_spin_unlock(&((pTier)->lock))
|
#define tfsUnLockTier(pTier) pthread_spin_unlock(&(pTier)->lock)
|
||||||
|
|
||||||
// PROTECTED ==========================================
|
int32_t tfsInitTier(STier *pTier, int32_t level) {
|
||||||
int tfsInitTier(STier *pTier, int level) {
|
if (pTier == NULL) {
|
||||||
memset((void *)pTier, 0, sizeof(*pTier));
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int code = pthread_spin_init(&(pTier->lock), 0);
|
memset(pTier, 0, sizeof(STier));
|
||||||
if (code) {
|
|
||||||
|
int32_t code = pthread_spin_init(&pTier->lock, 0);
|
||||||
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTier->level = level;
|
pTier->level = level;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsDestroyTier(STier *pTier) {
|
void tfsDestroyTier(STier *pTier) {
|
||||||
for (int id = 0; id < TSDB_MAX_DISKS_PER_TIER; id++) {
|
if (pTier == NULL) return;
|
||||||
|
|
||||||
|
for (int32_t id = 0; id < TSDB_MAX_DISKS_PER_TIER; id++) {
|
||||||
DISK_AT_TIER(pTier, id) = tfsFreeDisk(DISK_AT_TIER(pTier, id));
|
DISK_AT_TIER(pTier, id) = tfsFreeDisk(DISK_AT_TIER(pTier, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
pTier->ndisk = 0;
|
pTier->ndisk = 0;
|
||||||
|
|
||||||
pthread_spin_destroy(&(pTier->lock));
|
pthread_spin_destroy(&(pTier->lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
||||||
ASSERT(pTier->level == pCfg->level);
|
if (pTier == NULL || pCfg == NULL || pTier->level != pCfg->level) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
int id = 0;
|
return -1;
|
||||||
SDisk *pDisk;
|
}
|
||||||
|
|
||||||
if (TIER_NDISKS(pTier) >= TSDB_MAX_DISKS_PER_TIER) {
|
if (TIER_NDISKS(pTier) >= TSDB_MAX_DISKS_PER_TIER) {
|
||||||
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t id = 0;
|
||||||
if (pTier->level == 0) {
|
if (pTier->level == 0) {
|
||||||
if (DISK_AT_TIER(pTier, 0) != NULL) {
|
if (DISK_AT_TIER(pTier, 0) != NULL) {
|
||||||
id = pTier->ndisk;
|
id = pTier->ndisk;
|
||||||
|
@ -73,30 +78,31 @@ SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg) {
|
||||||
id = pTier->ndisk;
|
id = pTier->ndisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDisk = tfsNewDisk(pCfg->level, id, pCfg->dir);
|
SDisk *pDisk = tfsNewDisk(pCfg->level, id, pCfg->dir);
|
||||||
if (pDisk == NULL) return NULL;
|
if (pDisk == NULL) return NULL;
|
||||||
|
|
||||||
DISK_AT_TIER(pTier, id) = pDisk;
|
DISK_AT_TIER(pTier, id) = pDisk;
|
||||||
pTier->ndisk++;
|
pTier->ndisk++;
|
||||||
|
|
||||||
fInfo("disk %s is mounted to tier level %d id %d", pCfg->dir, pCfg->level, id);
|
fInfo("disk %s is mounted to tier level %d id %d", pCfg->dir, pCfg->level, id);
|
||||||
|
|
||||||
return DISK_AT_TIER(pTier, id);
|
return DISK_AT_TIER(pTier, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) {
|
void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) {
|
||||||
STierMeta tmeta;
|
STierMeta tmeta = {0};
|
||||||
|
|
||||||
if (pTierMeta == NULL) {
|
if (pTierMeta == NULL) {
|
||||||
pTierMeta = &tmeta;
|
pTierMeta = &tmeta;
|
||||||
}
|
}
|
||||||
memset(pTierMeta, 0, sizeof(*pTierMeta));
|
memset(pTierMeta, 0, sizeof(STierMeta));
|
||||||
|
|
||||||
tfsLockTier(pTier);
|
tfsLockTier(pTier);
|
||||||
|
|
||||||
for (int id = 0; id < pTier->ndisk; id++) {
|
for (int32_t id = 0; id < pTier->ndisk; id++) {
|
||||||
if (tfsUpdateDiskInfo(DISK_AT_TIER(pTier, id)) < 0) {
|
if (tfsUpdateDiskInfo(DISK_AT_TIER(pTier, id)) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTierMeta->size += DISK_SIZE(DISK_AT_TIER(pTier, id));
|
pTierMeta->size += DISK_SIZE(DISK_AT_TIER(pTier, id));
|
||||||
pTierMeta->used += DISK_USED_SIZE(DISK_AT_TIER(pTier, id));
|
pTierMeta->used += DISK_USED_SIZE(DISK_AT_TIER(pTier, id));
|
||||||
pTierMeta->free += DISK_FREE_SIZE(DISK_AT_TIER(pTier, id));
|
pTierMeta->free += DISK_FREE_SIZE(DISK_AT_TIER(pTier, id));
|
||||||
|
@ -109,22 +115,26 @@ void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round-Robin to allocate disk on a tier
|
// Round-Robin to allocate disk on a tier
|
||||||
int tfsAllocDiskOnTier(STier *pTier) {
|
int32_t tfsAllocDiskOnTier(STier *pTier) {
|
||||||
ASSERT(pTier->ndisk > 0);
|
if (pTier == NULL || pTier->ndisk <= 0) {
|
||||||
int id = TFS_UNDECIDED_ID;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
SDisk *pDisk;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tfsLockTier(pTier);
|
tfsLockTier(pTier);
|
||||||
|
|
||||||
if (TIER_AVAIL_DISKS(pTier) <= 0) {
|
if (TIER_AVAIL_DISKS(pTier) <= 0) {
|
||||||
tfsUnLockTier(pTier);
|
tfsUnLockTier(pTier);
|
||||||
return id;
|
return TFS_UNDECIDED_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = pTier->nextid;
|
int32_t id = pTier->nextid;
|
||||||
while (true) {
|
while (true) {
|
||||||
pDisk = DISK_AT_TIER(pTier, id);
|
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
||||||
ASSERT(pDisk != NULL);
|
if (pDisk == NULL) {
|
||||||
|
tfsUnLockTier(pTier);
|
||||||
|
return TFS_UNDECIDED_ID;
|
||||||
|
}
|
||||||
|
|
||||||
if (DISK_FREE_SIZE(pDisk) < TFS_MIN_DISK_FREE_SIZE) {
|
if (DISK_FREE_SIZE(pDisk) < TFS_MIN_DISK_FREE_SIZE) {
|
||||||
id = (id + 1) % pTier->ndisk;
|
id = (id + 1) % pTier->ndisk;
|
||||||
|
@ -145,7 +155,7 @@ int tfsAllocDiskOnTier(STier *pTier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta) {
|
void tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta) {
|
||||||
ASSERT(pTierMeta != NULL);
|
if (pTierMeta == NULL || pTierMeta == NULL) return;
|
||||||
|
|
||||||
tfsLockTier(pTier);
|
tfsLockTier(pTier);
|
||||||
*pTierMeta = pTier->tmeta;
|
*pTierMeta = pTier->tmeta;
|
||||||
|
@ -153,10 +163,11 @@ void tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfsPosNextId(STier *pTier) {
|
void tfsPosNextId(STier *pTier) {
|
||||||
ASSERT(pTier->ndisk > 0);
|
if (pTier == NULL || pTier->ndisk <= 0) return;
|
||||||
int nextid = 0;
|
|
||||||
|
|
||||||
for (int id = 1; id < pTier->ndisk; id++) {
|
int32_t nextid = 0;
|
||||||
|
|
||||||
|
for (int32_t id = 1; id < pTier->ndisk; id++) {
|
||||||
SDisk *pLDisk = DISK_AT_TIER(pTier, nextid);
|
SDisk *pLDisk = DISK_AT_TIER(pTier, nextid);
|
||||||
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
SDisk *pDisk = DISK_AT_TIER(pTier, id);
|
||||||
if (DISK_FREE_SIZE(pDisk) > TFS_MIN_DISK_FREE_SIZE && DISK_FREE_SIZE(pDisk) > DISK_FREE_SIZE(pLDisk)) {
|
if (DISK_FREE_SIZE(pDisk) > TFS_MIN_DISK_FREE_SIZE && DISK_FREE_SIZE(pDisk) > DISK_FREE_SIZE(pLDisk)) {
|
||||||
|
|
|
@ -387,7 +387,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_SIZE_LIMIT, "WAL size exceeds limit")
|
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_SIZE_LIMIT, "WAL size exceeds limit")
|
||||||
|
|
||||||
// tfs
|
// tfs
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_OUT_OF_MEMORY, "tfs out of memory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FS_APP_ERROR, "tfs out of memory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG, "tfs invalid mount config")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG, "tfs invalid mount config")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_TOO_MANY_MOUNT, "tfs too many mount")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FS_TOO_MANY_MOUNT, "tfs too many mount")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FS_DUP_PRIMARY, "tfs duplicate primary mount")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FS_DUP_PRIMARY, "tfs duplicate primary mount")
|
||||||
|
|
Loading…
Reference in New Issue