提交 7087e442 编写于 作者: S Shengliang Guan

minor changes

上级 9e4141fa
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TD_TFS_H #ifndef _TD_TFS_H_
#define TD_TFS_H #define _TD_TFS_H_
#include "tglobal.h" #include "tglobal.h"
...@@ -23,8 +23,8 @@ extern "C" { ...@@ -23,8 +23,8 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
int level; int32_t level;
int id; int32_t id;
} SDiskID; } SDiskID;
#define TFS_UNDECIDED_LEVEL -1 #define TFS_UNDECIDED_LEVEL -1
...@@ -48,21 +48,21 @@ typedef struct { ...@@ -48,21 +48,21 @@ typedef struct {
int16_t nAvailDisks; // # of Available disks int16_t nAvailDisks; // # of Available disks
} STierMeta; } STierMeta;
int tfsInit(SDiskCfg *pDiskCfg, int ndisk); int32_t tfsInit(SDiskCfg *pDiskCfg, int32_t ndisk);
void tfsCleanup(); void tfsCleanup();
void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numLevels); void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numLevels);
void tfsGetMeta(SFSMeta *pMeta); void tfsGetMeta(SFSMeta *pMeta);
void tfsAllocDisk(int expLevel, int *level, int *id); void tfsAllocDisk(int32_t expLevel, int32_t *level, int32_t *id);
const char *TFS_PRIMARY_PATH(); const char *TFS_PRIMARY_PATH();
const char *TFS_DISK_PATH(int level, int id); const char *TFS_DISK_PATH(int32_t level, int32_t id);
// TFILE APIs ==================================== // TFILE APIs ====================================
typedef struct { typedef struct {
int level; int32_t level;
int id; int32_t id;
char rname[TSDB_FILENAME_LEN]; // REL name char rname[TSDB_FILENAME_LEN]; // REL name
char aname[TSDB_FILENAME_LEN]; // ABS name char aname[TSDB_FILENAME_LEN]; // ABS name
} TFILE; } TFILE;
#define TFILE_LEVEL(pf) ((pf)->level) #define TFILE_LEVEL(pf) ((pf)->level)
...@@ -76,23 +76,23 @@ typedef struct { ...@@ -76,23 +76,23 @@ typedef struct {
#define tfscopy(sf, df) taosCopyFile(TFILE_NAME(sf), TFILE_NAME(df)) #define tfscopy(sf, df) taosCopyFile(TFILE_NAME(sf), TFILE_NAME(df))
#define tfsrename(sf, df) taosRename(TFILE_NAME(sf), TFILE_NAME(df)) #define tfsrename(sf, df) taosRename(TFILE_NAME(sf), TFILE_NAME(df))
void tfsInitFile(TFILE *pf, int level, int id, const char *bname); void tfsInitFile(TFILE *pf, int32_t level, int32_t id, const char *bname);
bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2); bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2);
int tfsEncodeFile(void **buf, TFILE *pf); int32_t tfsEncodeFile(void **buf, TFILE *pf);
void *tfsDecodeFile(void *buf, TFILE *pf); void *tfsDecodeFile(void *buf, TFILE *pf);
void tfsbasename(const TFILE *pf, char *dest); void tfsbasename(const TFILE *pf, char *dest);
void tfsdirname(const TFILE *pf, char *dest); void tfsdirname(const TFILE *pf, char *dest);
// DIR APIs ==================================== // DIR APIs ====================================
int tfsMkdirAt(const char *rname, int level, int id); int32_t tfsMkdirAt(const char *rname, int32_t level, int32_t id);
int tfsMkdirRecurAt(const char *rname, int level, int id); int32_t tfsMkdirRecurAt(const char *rname, int32_t level, int32_t id);
int tfsMkdir(const char *rname); int32_t tfsMkdir(const char *rname);
int tfsRmdir(const char *rname); int32_t tfsRmdir(const char *rname);
int tfsRename(char *orname, char *nrname); int32_t tfsRename(char *orname, char *nrname);
typedef struct TDIR TDIR; typedef struct TDIR TDIR;
TDIR * tfsOpendir(const char *rname); TDIR *tfsOpendir(const char *rname);
const TFILE *tfsReaddir(TDIR *tdir); const TFILE *tfsReaddir(TDIR *tdir);
void tfsClosedir(TDIR *tdir); void tfsClosedir(TDIR *tdir);
...@@ -100,4 +100,4 @@ void tfsClosedir(TDIR *tdir); ...@@ -100,4 +100,4 @@ void tfsClosedir(TDIR *tdir);
} }
#endif #endif
#endif #endif /*_TD_TFS_H_*/
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TD_TFSINT_H #ifndef _TD_TFSINT_H_
#define TD_TFSINT_H #define _TD_TFSINT_H_
#include "os.h" #include "os.h"
...@@ -88,10 +88,10 @@ void tfsDestroyTier(STier *pTier); ...@@ -88,10 +88,10 @@ 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);
int32_t tfsAllocDiskOnTier(STier *pTier); int32_t tfsAllocDiskOnTier(STier *pTier);
void tfsPosNextId(STier *pTier); void tfsPosNextId(STier *pTier);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif /*_TD_TFSINT_H_*/
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
typedef struct { typedef struct {
pthread_spinlock_t lock; pthread_spinlock_t lock;
SFSMeta meta; SFSMeta meta;
int nlevel; int32_t nlevel;
STier tiers[TSDB_MAX_TIERS]; STier tiers[TSDB_MAX_TIERS];
SHashObj * map; // name to did map SHashObj *map; // name to did map
} SFS; } SFS;
typedef struct { typedef struct {
...@@ -47,21 +47,21 @@ static SFS tfs = {0}; ...@@ -47,21 +47,21 @@ static SFS tfs = {0};
static SFS *pfs = &tfs; static SFS *pfs = &tfs;
// STATIC DECLARATION // STATIC DECLARATION
static int tfsMount(SDiskCfg *pCfg); static int32_t tfsMount(SDiskCfg *pCfg);
static int tfsCheck(); static int32_t tfsCheck();
static int tfsCheckAndFormatCfg(SDiskCfg *pCfg); static int32_t tfsCheckAndFormatCfg(SDiskCfg *pCfg);
static int tfsFormatDir(char *idir, char *odir); static int32_t tfsFormatDir(char *idir, char *odir);
static SDisk *tfsGetDiskByID(SDiskID did); static SDisk *tfsGetDiskByID(SDiskID did);
static SDisk *tfsGetDiskByName(const char *dir); static SDisk *tfsGetDiskByName(const char *dir);
static int tfsOpendirImpl(TDIR *tdir); static int32_t tfsOpendirImpl(TDIR *tdir);
static void tfsInitDiskIter(SDiskIter *pIter); static void tfsInitDiskIter(SDiskIter *pIter);
static SDisk *tfsNextDisk(SDiskIter *pIter); static SDisk *tfsNextDisk(SDiskIter *pIter);
// FS APIs ==================================== // FS APIs ====================================
int tfsInit(SDiskCfg *pDiskCfg, int ndisk) { int32_t tfsInit(SDiskCfg *pDiskCfg, int32_t ndisk) {
ASSERT(ndisk > 0); ASSERT(ndisk > 0);
for (int level = 0; level < TSDB_MAX_TIERS; level++) { for (int32_t level = 0; level < TSDB_MAX_TIERS; level++) {
if (tfsInitTier(TFS_TIER_AT(level), level) < 0) { if (tfsInitTier(TFS_TIER_AT(level), level) < 0) {
while (true) { while (true) {
level--; level--;
...@@ -84,7 +84,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) { ...@@ -84,7 +84,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
return -1; return -1;
} }
for (int idisk = 0; idisk < ndisk; idisk++) { for (int32_t idisk = 0; idisk < ndisk; idisk++) {
if (tfsMount(pDiskCfg + idisk) < 0) { if (tfsMount(pDiskCfg + idisk) < 0) {
tfsCleanup(); tfsCleanup();
return -1; return -1;
...@@ -97,7 +97,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) { ...@@ -97,7 +97,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
} }
tfsUpdateInfo(NULL, NULL, 0); tfsUpdateInfo(NULL, NULL, 0);
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
tfsPosNextId(TFS_TIER_AT(level)); tfsPosNextId(TFS_TIER_AT(level));
} }
...@@ -109,7 +109,7 @@ void tfsCleanup() { ...@@ -109,7 +109,7 @@ void tfsCleanup() {
pfs->map = NULL; pfs->map = NULL;
pthread_spin_destroy(&(pfs->lock)); pthread_spin_destroy(&(pfs->lock));
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
tfsDestroyTier(TFS_TIER_AT(level)); tfsDestroyTier(TFS_TIER_AT(level));
} }
} }
...@@ -124,7 +124,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numTiers) { ...@@ -124,7 +124,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numTiers) {
memset(pFSMeta, 0, sizeof(*pFSMeta)); memset(pFSMeta, 0, sizeof(*pFSMeta));
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
STierMeta *pTierMeta = &tierMeta; STierMeta *pTierMeta = &tierMeta;
if (tierMetas && level < numTiers) { if (tierMetas && level < numTiers) {
pTierMeta = tierMetas + level; pTierMeta = tierMetas + level;
...@@ -152,7 +152,7 @@ void tfsGetMeta(SFSMeta *pMeta) { ...@@ -152,7 +152,7 @@ void tfsGetMeta(SFSMeta *pMeta) {
/* Allocate an existing available tier level /* Allocate an existing available tier level
*/ */
void tfsAllocDisk(int expLevel, int *level, int *id) { void tfsAllocDisk(int32_t expLevel, int32_t *level, int32_t *id) {
ASSERT(expLevel >= 0); ASSERT(expLevel >= 0);
*level = expLevel; *level = expLevel;
...@@ -177,10 +177,10 @@ void tfsAllocDisk(int expLevel, int *level, int *id) { ...@@ -177,10 +177,10 @@ void tfsAllocDisk(int expLevel, int *level, int *id) {
} }
const char *TFS_PRIMARY_PATH() { return DISK_DIR(TFS_PRIMARY_DISK()); } const char *TFS_PRIMARY_PATH() { return DISK_DIR(TFS_PRIMARY_DISK()); }
const char *TFS_DISK_PATH(int level, int id) { return DISK_DIR(TFS_DISK_AT(level, id)); } const char *TFS_DISK_PATH(int32_t level, int32_t id) { return DISK_DIR(TFS_DISK_AT(level, id)); }
// TFILE APIs ==================================== // TFILE APIs ====================================
void tfsInitFile(TFILE *pf, int level, int id, const char *bname) { void tfsInitFile(TFILE *pf, int32_t level, int32_t id, const char *bname) {
ASSERT(TFS_IS_VALID_DISK(level, id)); ASSERT(TFS_IS_VALID_DISK(level, id));
SDisk *pDisk = TFS_DISK_AT(level, id); SDisk *pDisk = TFS_DISK_AT(level, id);
...@@ -203,8 +203,8 @@ bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2) { ...@@ -203,8 +203,8 @@ bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2) {
return true; return true;
} }
int tfsEncodeFile(void **buf, TFILE *pf) { int32_t tfsEncodeFile(void **buf, TFILE *pf) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeVariantI32(buf, pf->level); tlen += taosEncodeVariantI32(buf, pf->level);
tlen += taosEncodeVariantI32(buf, pf->id); tlen += taosEncodeVariantI32(buf, pf->id);
...@@ -215,7 +215,7 @@ int tfsEncodeFile(void **buf, TFILE *pf) { ...@@ -215,7 +215,7 @@ int tfsEncodeFile(void **buf, TFILE *pf) {
void *tfsDecodeFile(void *buf, TFILE *pf) { void *tfsDecodeFile(void *buf, TFILE *pf) {
int32_t level, id; int32_t level, id;
char * rname; char *rname;
buf = taosDecodeVariantI32(buf, &(level)); buf = taosDecodeVariantI32(buf, &(level));
buf = taosDecodeVariantI32(buf, &(id)); buf = taosDecodeVariantI32(buf, &(id));
...@@ -242,7 +242,7 @@ void tfsdirname(const TFILE *pf, char *dest) { ...@@ -242,7 +242,7 @@ void tfsdirname(const TFILE *pf, char *dest) {
} }
// DIR APIs ==================================== // DIR APIs ====================================
int tfsMkdirAt(const char *rname, int level, int id) { int32_t tfsMkdirAt(const char *rname, int32_t level, int32_t id) {
SDisk *pDisk = TFS_DISK_AT(level, id); SDisk *pDisk = TFS_DISK_AT(level, id);
char aname[TMPNAME_LEN]; char aname[TMPNAME_LEN];
...@@ -255,7 +255,7 @@ int tfsMkdirAt(const char *rname, int level, int id) { ...@@ -255,7 +255,7 @@ int tfsMkdirAt(const char *rname, int level, int id) {
return 0; return 0;
} }
int tfsMkdirRecurAt(const char *rname, int level, int id) { int32_t tfsMkdirRecurAt(const char *rname, int32_t level, int32_t id) {
if (tfsMkdirAt(rname, level, id) < 0) { if (tfsMkdirAt(rname, level, id) < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
// Try to create upper // Try to create upper
...@@ -288,10 +288,10 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) { ...@@ -288,10 +288,10 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) {
return 0; return 0;
} }
int tfsMkdir(const char *rname) { int32_t tfsMkdir(const char *rname) {
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
STier *pTier = TFS_TIER_AT(level); STier *pTier = TFS_TIER_AT(level);
for (int id = 0; id < TIER_NDISKS(pTier); id++) { for (int32_t id = 0; id < TIER_NDISKS(pTier); id++) {
if (tfsMkdirAt(rname, level, id) < 0) { if (tfsMkdirAt(rname, level, id) < 0) {
return -1; return -1;
} }
...@@ -301,12 +301,12 @@ int tfsMkdir(const char *rname) { ...@@ -301,12 +301,12 @@ int tfsMkdir(const char *rname) {
return 0; return 0;
} }
int tfsRmdir(const char *rname) { int32_t tfsRmdir(const char *rname) {
char aname[TMPNAME_LEN] = "\0"; char aname[TMPNAME_LEN] = "\0";
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
STier *pTier = TFS_TIER_AT(level); STier *pTier = TFS_TIER_AT(level);
for (int id = 0; id < TIER_NDISKS(pTier); id++) { for (int32_t id = 0; id < TIER_NDISKS(pTier); id++) {
SDisk *pDisk = DISK_AT_TIER(pTier, id); SDisk *pDisk = DISK_AT_TIER(pTier, id);
snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname); snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname);
...@@ -318,13 +318,13 @@ int tfsRmdir(const char *rname) { ...@@ -318,13 +318,13 @@ int tfsRmdir(const char *rname) {
return 0; return 0;
} }
int tfsRename(char *orname, char *nrname) { int32_t tfsRename(char *orname, char *nrname) {
char oaname[TMPNAME_LEN] = "\0"; char oaname[TMPNAME_LEN] = "\0";
char naname[TMPNAME_LEN] = "\0"; char naname[TMPNAME_LEN] = "\0";
for (int level = 0; level < pfs->nlevel; level++) { for (int32_t level = 0; level < pfs->nlevel; level++) {
STier *pTier = TFS_TIER_AT(level); STier *pTier = TFS_TIER_AT(level);
for (int id = 0; id < TIER_NDISKS(pTier); id++) { for (int32_t id = 0; id < TIER_NDISKS(pTier); id++) {
SDisk *pDisk = DISK_AT_TIER(pTier, id); SDisk *pDisk = DISK_AT_TIER(pTier, id);
snprintf(oaname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), orname); snprintf(oaname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), orname);
...@@ -339,11 +339,11 @@ int tfsRename(char *orname, char *nrname) { ...@@ -339,11 +339,11 @@ int tfsRename(char *orname, char *nrname) {
struct TDIR { struct TDIR {
SDiskIter iter; SDiskIter iter;
int level; int32_t level;
int id; int32_t id;
char dirname[TSDB_FILENAME_LEN]; char dirname[TSDB_FILENAME_LEN];
TFILE tfile; TFILE tfile;
DIR * dir; DIR *dir;
}; };
TDIR *tfsOpendir(const char *rname) { TDIR *tfsOpendir(const char *rname) {
...@@ -402,9 +402,9 @@ void tfsClosedir(TDIR *tdir) { ...@@ -402,9 +402,9 @@ void tfsClosedir(TDIR *tdir) {
} }
// private // private
static int tfsMount(SDiskCfg *pCfg) { static int32_t tfsMount(SDiskCfg *pCfg) {
SDiskID did; SDiskID did;
SDisk * pDisk = NULL; SDisk *pDisk = NULL;
if (tfsCheckAndFormatCfg(pCfg) < 0) return -1; if (tfsCheckAndFormatCfg(pCfg) < 0) return -1;
...@@ -422,7 +422,7 @@ static int tfsMount(SDiskCfg *pCfg) { ...@@ -422,7 +422,7 @@ static int tfsMount(SDiskCfg *pCfg) {
return 0; return 0;
} }
static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) { static int32_t tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
char dirName[TSDB_FILENAME_LEN] = "\0"; char dirName[TSDB_FILENAME_LEN] = "\0";
struct stat pstat; struct stat pstat;
...@@ -481,10 +481,10 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) { ...@@ -481,10 +481,10 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
return 0; return 0;
} }
static int tfsFormatDir(char *idir, char *odir) { static int32_t tfsFormatDir(char *idir, char *odir) {
wordexp_t wep = {0}; wordexp_t wep = {0};
int code = wordexp(idir, &wep, 0); int32_t code = wordexp(idir, &wep, 0);
if (code != 0) { if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code); terrno = TAOS_SYSTEM_ERROR(code);
return -1; return -1;
...@@ -502,14 +502,14 @@ static int tfsFormatDir(char *idir, char *odir) { ...@@ -502,14 +502,14 @@ static int tfsFormatDir(char *idir, char *odir) {
return 0; return 0;
} }
static int tfsCheck() { static int32_t tfsCheck() {
if (TFS_PRIMARY_DISK() == NULL) { if (TFS_PRIMARY_DISK() == NULL) {
fError("no primary disk is set"); fError("no primary disk is set");
terrno = TSDB_CODE_FS_NO_PRIMARY_DISK; terrno = TSDB_CODE_FS_NO_PRIMARY_DISK;
return -1; return -1;
} }
for (int level = 0; level < TFS_NLEVEL(); level++) { for (int32_t level = 0; level < TFS_NLEVEL(); level++) {
if (TIER_NDISKS(TFS_TIER_AT(level)) == 0) { if (TIER_NDISKS(TFS_TIER_AT(level)) == 0) {
fError("no disk at level %d", level); fError("no disk at level %d", level);
terrno = TSDB_CODE_FS_NO_MOUNT_AT_TIER; terrno = TSDB_CODE_FS_NO_MOUNT_AT_TIER;
...@@ -523,8 +523,8 @@ static int tfsCheck() { ...@@ -523,8 +523,8 @@ static int tfsCheck() {
static SDisk *tfsGetDiskByID(SDiskID did) { return TFS_DISK_AT(did.level, did.id); } static SDisk *tfsGetDiskByID(SDiskID did) { return TFS_DISK_AT(did.level, did.id); }
static SDisk *tfsGetDiskByName(const char *dir) { static SDisk *tfsGetDiskByName(const char *dir) {
SDiskID did; SDiskID did;
SDisk * pDisk = NULL; SDisk *pDisk = NULL;
void * pr = NULL; void *pr = NULL;
pr = taosHashGet(pfs->map, (void *)dir, strnlen(dir, TSDB_FILENAME_LEN)); pr = taosHashGet(pfs->map, (void *)dir, strnlen(dir, TSDB_FILENAME_LEN));
if (pr == NULL) return NULL; if (pr == NULL) return NULL;
...@@ -536,7 +536,7 @@ static SDisk *tfsGetDiskByName(const char *dir) { ...@@ -536,7 +536,7 @@ static SDisk *tfsGetDiskByName(const char *dir) {
return pDisk; return pDisk;
} }
static int tfsOpendirImpl(TDIR *tdir) { static int32_t tfsOpendirImpl(TDIR *tdir) {
SDisk *pDisk = NULL; SDisk *pDisk = NULL;
char adir[TMPNAME_LEN * 2] = "\0"; char adir[TMPNAME_LEN * 2] = "\0";
...@@ -567,8 +567,8 @@ static SDisk *tfsNextDisk(SDiskIter *pIter) { ...@@ -567,8 +567,8 @@ static SDisk *tfsNextDisk(SDiskIter *pIter) {
if (pDisk == NULL) return NULL; if (pDisk == NULL) return NULL;
int level = DISK_LEVEL(pDisk); int32_t level = DISK_LEVEL(pDisk);
int id = DISK_ID(pDisk); int32_t id = DISK_ID(pDisk);
id++; id++;
if (id < TIER_NDISKS(TFS_TIER_AT(level))) { if (id < TIER_NDISKS(TFS_TIER_AT(level))) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册