finish more code
This commit is contained in:
parent
d6d1532b0a
commit
8517faaefa
|
@ -38,6 +38,13 @@ typedef struct {
|
||||||
} SDiskMeta;
|
} SDiskMeta;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uint64_t tsize;
|
||||||
|
uint64_t avail; // bytes
|
||||||
|
} STiersMeta;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int level;
|
||||||
|
int did;
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
SDiskMeta dmeta;
|
SDiskMeta dmeta;
|
||||||
} SDisk;
|
} SDisk;
|
||||||
|
@ -50,6 +57,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct SDnodeTier {
|
typedef struct SDnodeTier {
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
STiersMeta meta;
|
||||||
int nTiers;
|
int nTiers;
|
||||||
STier tiers[TSDB_MAX_TIERS];
|
STier tiers[TSDB_MAX_TIERS];
|
||||||
SHashObj * map;
|
SHashObj * map;
|
||||||
|
@ -58,7 +66,7 @@ typedef struct SDnodeTier {
|
||||||
extern struct SDnodeTier *tsDnodeTier;
|
extern struct SDnodeTier *tsDnodeTier;
|
||||||
#define DNODE_PRIMARY_DISK(pDnodeTier) (pDnodeTier)->tiers[0].disks[0]
|
#define DNODE_PRIMARY_DISK(pDnodeTier) (pDnodeTier)->tiers[0].disks[0]
|
||||||
|
|
||||||
static FORCE_INLINE int dnodeLockTiers(SDnodeTier *pDnodeTier) {
|
static FORCE_INLINE int tdLockTiers(SDnodeTier *pDnodeTier) {
|
||||||
int code = pthread_mutex_lock(&(pDnodeTier->lock));
|
int code = pthread_mutex_lock(&(pDnodeTier->lock));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -67,7 +75,7 @@ static FORCE_INLINE int dnodeLockTiers(SDnodeTier *pDnodeTier) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int dnodeUnLockTiers(SDnodeTier *pDnodeTier) {
|
static FORCE_INLINE int tdUnLockTiers(SDnodeTier *pDnodeTier) {
|
||||||
int code = pthread_mutex_unlock(&(pDnodeTier->lock));
|
int code = pthread_mutex_unlock(&(pDnodeTier->lock));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -76,7 +84,7 @@ static FORCE_INLINE int dnodeUnLockTiers(SDnodeTier *pDnodeTier) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE SDisk *dnodeGetDisk(SDnodeTier *pDnodeTier, int level, int did) {
|
static FORCE_INLINE SDisk *tdGetDisk(SDnodeTier *pDnodeTier, int level, int did) {
|
||||||
if (level < 0 || level >= pDnodeTier->nTiers) return NULL;
|
if (level < 0 || level >= pDnodeTier->nTiers) return NULL;
|
||||||
|
|
||||||
if (did < 0 || did >= pDnodeTier->tiers[level].nDisks) return NULL;
|
if (did < 0 || did >= pDnodeTier->tiers[level].nDisks) return NULL;
|
||||||
|
@ -84,15 +92,15 @@ static FORCE_INLINE SDisk *dnodeGetDisk(SDnodeTier *pDnodeTier, int level, int d
|
||||||
return pDnodeTier->tiers[level].disks[did];
|
return pDnodeTier->tiers[level].disks[did];
|
||||||
}
|
}
|
||||||
|
|
||||||
SDnodeTier *dnodeNewTier();
|
SDnodeTier *tdNewTier();
|
||||||
void * dnodeCloseTier(SDnodeTier *pDnodeTier);
|
void * tdCloseTier(SDnodeTier *pDnodeTier);
|
||||||
int dnodeAddDisks(SDnodeTier *pDnodeTier, SDiskCfg *pDiskCfgs, int ndisks);
|
int tdAddDisks(SDnodeTier *pDnodeTier, SDiskCfg *pDiskCfgs, int ndisks);
|
||||||
int dnodeUpdateTiersInfo(SDnodeTier *pDnodeTier);
|
int tdUpdateTiersInfo(SDnodeTier *pDnodeTier);
|
||||||
int dnodeCheckTiers(SDnodeTier *pDnodeTier);
|
int tdCheckTiers(SDnodeTier *pDnodeTier);
|
||||||
SDisk * dnodeAssignDisk(SDnodeTier *pDnodeTier, int level);
|
SDisk * tdAssignDisk(SDnodeTier *pDnodeTier, int level);
|
||||||
SDisk * dnodeGetDiskByName(SDnodeTier *pDnodeTier, char *dirName);
|
SDisk * tdGetDiskByName(SDnodeTier *pDnodeTier, char *dirName);
|
||||||
void dnodeIncDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock);
|
void tdIncDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock);
|
||||||
void dnodeDecDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock);
|
void tdDecDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
#define DISK_MIN_FREE_SPACE 30 * 1024 * 1024 // disk free space less than 100M will not create new file again
|
#define DISK_MIN_FREE_SPACE 30 * 1024 * 1024 // disk free space less than 100M will not create new file again
|
||||||
#define DNODE_DISK_AVAIL(pDisk) ((pDisk)->dmeta.free > DISK_MIN_FREE_SPACE)
|
#define DNODE_DISK_AVAIL(pDisk) ((pDisk)->dmeta.free > DISK_MIN_FREE_SPACE)
|
||||||
|
|
||||||
static int dnodeFormatDir(char *idir, char *odir);
|
static int tdFormatDir(char *idir, char *odir);
|
||||||
static int dnodeCheckDisk(char *dirName, int level, int primary);
|
static int tdCheckDisk(char *dirName, int level, int primary);
|
||||||
static int dnodeUpdateDiskMeta(SDisk *pDisk);
|
static int tdUpdateDiskMeta(SDisk *pDisk);
|
||||||
static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary);
|
static int tdAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary);
|
||||||
|
|
||||||
struct SDnodeTier *tsDnodeTier = NULL;
|
struct SDnodeTier *tsDnodeTier = NULL;
|
||||||
|
|
||||||
SDnodeTier *dnodeNewTier() {
|
SDnodeTier *tdNewTier() {
|
||||||
SDnodeTier *pDnodeTier = (SDnodeTier *)calloc(1, sizeof(*pDnodeTier));
|
SDnodeTier *pDnodeTier = (SDnodeTier *)calloc(1, sizeof(*pDnodeTier));
|
||||||
if (pDnodeTier == NULL) {
|
if (pDnodeTier == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
@ -37,7 +37,7 @@ SDnodeTier *dnodeNewTier() {
|
||||||
int ret = pthread_mutex_init(&(pDnodeTier->lock), NULL);
|
int ret = pthread_mutex_init(&(pDnodeTier->lock), NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||||
dnodeCloseTier(pDnodeTier);
|
tdCloseTier(pDnodeTier);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ SDnodeTier *dnodeNewTier() {
|
||||||
taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||||
if (pDnodeTier->map == NULL) {
|
if (pDnodeTier->map == NULL) {
|
||||||
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
|
||||||
dnodeCloseTier(pDnodeTier);
|
tdCloseTier(pDnodeTier);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pDnodeTier;
|
return pDnodeTier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *dnodeCloseTier(SDnodeTier *pDnodeTier) {
|
void *tdCloseTier(SDnodeTier *pDnodeTier) {
|
||||||
if (pDnodeTier) {
|
if (pDnodeTier) {
|
||||||
if (pDnodeTier->map) {
|
if (pDnodeTier->map) {
|
||||||
taosHashCleanup(pDnodeTier->map);
|
taosHashCleanup(pDnodeTier->map);
|
||||||
|
@ -75,32 +75,42 @@ void *dnodeCloseTier(SDnodeTier *pDnodeTier) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dnodeAddDisks(SDnodeTier *pDnodeTier, SDiskCfg *pDiskCfgs, int ndisks) {
|
int tdAddDisks(SDnodeTier *pDnodeTier, SDiskCfg *pDiskCfgs, int ndisks) {
|
||||||
ASSERT(ndisks > 0);
|
ASSERT(ndisks > 0);
|
||||||
|
|
||||||
for (int i = 0; i < ndisks; i++) {
|
for (int i = 0; i < ndisks; i++) {
|
||||||
SDiskCfg *pCfg = pDiskCfgs + i;
|
SDiskCfg *pCfg = pDiskCfgs + i;
|
||||||
dnodeAddDisk(pDnodeTier, pCfg->dir, pCfg->level, pCfg->primary);
|
tdAddDisk(pDnodeTier, pCfg->dir, pCfg->level, pCfg->primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeCheckTiers(pDnodeTier) < 0) return -1;
|
if (tdCheckTiers(pDnodeTier) < 0) return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dnodeUpdateTiersInfo(SDnodeTier *pDnodeTier) {
|
int tdUpdateTiersInfo(SDnodeTier *pDnodeTier) {
|
||||||
|
tdLockTiers(pDnodeTier);
|
||||||
|
|
||||||
|
pDnodeTier->meta.tsize = 0;
|
||||||
|
pDnodeTier->meta.avail = 0;
|
||||||
|
|
||||||
for (int i = 0; i < pDnodeTier->nTiers; i++) {
|
for (int i = 0; i < pDnodeTier->nTiers; i++) {
|
||||||
STier *pTier = pDnodeTier->tiers + i;
|
STier *pTier = pDnodeTier->tiers + i;
|
||||||
|
|
||||||
for (int j = 0; j < pTier->nDisks; j++) {
|
for (int j = 0; j < pTier->nDisks; j++) {
|
||||||
SDisk *pDisk = pTier->disks[j];
|
SDisk *pDisk = pTier->disks[j];
|
||||||
if (dnodeUpdateDiskMeta(pDisk) < 0) return -1;
|
if (tdUpdateDiskMeta(pDisk) < 0) return -1;
|
||||||
|
|
||||||
|
pDnodeTier->meta.tsize += pDisk->dmeta.size;
|
||||||
|
pDnodeTier->meta.avail += pDisk->dmeta.free;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdUnLockTiers(pDnodeTier);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dnodeCheckTiers(SDnodeTier *pDnodeTier) {
|
int tdCheckTiers(SDnodeTier *pDnodeTier) {
|
||||||
ASSERT(pDnodeTier->nTiers > 0);
|
ASSERT(pDnodeTier->nTiers > 0);
|
||||||
if (DNODE_PRIMARY_DISK(pDnodeTier) == NULL) {
|
if (DNODE_PRIMARY_DISK(pDnodeTier) == NULL) {
|
||||||
terrno = TSDB_CODE_DND_LACK_PRIMARY_DISK;
|
terrno = TSDB_CODE_DND_LACK_PRIMARY_DISK;
|
||||||
|
@ -117,7 +127,7 @@ int dnodeCheckTiers(SDnodeTier *pDnodeTier) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDisk *dnodeAssignDisk(SDnodeTier *pDnodeTier, int level) {
|
SDisk *tdAssignDisk(SDnodeTier *pDnodeTier, int level) {
|
||||||
ASSERT(level < pDnodeTier->nTiers);
|
ASSERT(level < pDnodeTier->nTiers);
|
||||||
|
|
||||||
STier *pTier = pDnodeTier->tiers + level;
|
STier *pTier = pDnodeTier->tiers + level;
|
||||||
|
@ -125,11 +135,11 @@ SDisk *dnodeAssignDisk(SDnodeTier *pDnodeTier, int level) {
|
||||||
|
|
||||||
ASSERT(pTier->nDisks > 0);
|
ASSERT(pTier->nDisks > 0);
|
||||||
|
|
||||||
dnodeLockTiers(pDnodeTier);
|
tdLockTiers(pDnodeTier);
|
||||||
|
|
||||||
for (int i = 0; i < pTier->nDisks; i++) {
|
for (int i = 0; i < pTier->nDisks; i++) {
|
||||||
SDisk *iDisk = pTier->disks[i];
|
SDisk *iDisk = pTier->disks[i];
|
||||||
if (dnodeUpdateDiskMeta(iDisk) < 0) return NULL;
|
if (tdUpdateDiskMeta(iDisk) < 0) return NULL;
|
||||||
if (DNODE_DISK_AVAIL(iDisk)) {
|
if (DNODE_DISK_AVAIL(iDisk)) {
|
||||||
if (pDisk == NULL || pDisk->dmeta.nfiles > iDisk->dmeta.nfiles) {
|
if (pDisk == NULL || pDisk->dmeta.nfiles > iDisk->dmeta.nfiles) {
|
||||||
pDisk = iDisk;
|
pDisk = iDisk;
|
||||||
|
@ -139,22 +149,22 @@ SDisk *dnodeAssignDisk(SDnodeTier *pDnodeTier, int level) {
|
||||||
|
|
||||||
if (pDisk == NULL) {
|
if (pDisk == NULL) {
|
||||||
terrno = TSDB_CODE_DND_NO_DISK_SPACE;
|
terrno = TSDB_CODE_DND_NO_DISK_SPACE;
|
||||||
dnodeUnLockTiers(pDnodeTier);
|
tdUnLockTiers(pDnodeTier);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dnodeIncDiskFiles(pDnodeTier, pDisk, false);
|
tdIncDiskFiles(pDnodeTier, pDisk, false);
|
||||||
|
|
||||||
dnodeUnLockTiers(pDnodeTier);
|
tdUnLockTiers(pDnodeTier);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDisk *dnodeGetDiskByName(SDnodeTier *pDnodeTier, char *dirName) {
|
SDisk *tdGetDiskByName(SDnodeTier *pDnodeTier, char *dirName) {
|
||||||
char fdirName[TSDB_FILENAME_LEN] = "\0";
|
char fdirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
SDiskID *pDiskID = NULL;
|
SDiskID *pDiskID = NULL;
|
||||||
|
|
||||||
if (dnodeFormatDir(dirName, fdirName) < 0) {
|
if (tdFormatDir(dirName, fdirName) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,34 +172,34 @@ SDisk *dnodeGetDiskByName(SDnodeTier *pDnodeTier, char *dirName) {
|
||||||
if (ptr == NULL) return NULL;
|
if (ptr == NULL) return NULL;
|
||||||
pDiskID = (SDiskID *)ptr;
|
pDiskID = (SDiskID *)ptr;
|
||||||
|
|
||||||
return dnodeGetDisk(pDnodeTier, pDiskID->level, pDiskID->did);
|
return tdGetDisk(pDnodeTier, pDiskID->level, pDiskID->did);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeIncDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock) {
|
void tdIncDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock) {
|
||||||
if (lock) {
|
if (lock) {
|
||||||
dnodeLockTiers(pDnodeTier);
|
tdLockTiers(pDnodeTier);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDisk->dmeta.nfiles++;
|
pDisk->dmeta.nfiles++;
|
||||||
|
|
||||||
if (lock) {
|
if (lock) {
|
||||||
dnodeUnLockTiers(pDnodeTier);
|
tdUnLockTiers(pDnodeTier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeDecDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock) {
|
void tdDecDiskFiles(SDnodeTier *pDnodeTier, SDisk *pDisk, bool lock) {
|
||||||
if (lock) {
|
if (lock) {
|
||||||
dnodeLockTiers(pDnodeTier);
|
tdLockTiers(pDnodeTier);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDisk->dmeta.nfiles--;
|
pDisk->dmeta.nfiles--;
|
||||||
|
|
||||||
if (lock) {
|
if (lock) {
|
||||||
dnodeUnLockTiers(pDnodeTier);
|
tdUnLockTiers(pDnodeTier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dnodeFormatDir(char *idir, char *odir) {
|
static int tdFormatDir(char *idir, char *odir) {
|
||||||
wordexp_t wep;
|
wordexp_t wep;
|
||||||
|
|
||||||
int code = wordexp(idir, &wep, 0);
|
int code = wordexp(idir, &wep, 0);
|
||||||
|
@ -210,7 +220,7 @@ static int dnodeFormatDir(char *idir, char *odir) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dnodeCheckDisk(char *dirName, int level, int primary) {
|
static int tdCheckDisk(char *dirName, int level, int primary) {
|
||||||
if (access(dirName, W_OK | R_OK | F_OK) != 0) {
|
if (access(dirName, W_OK | R_OK | F_OK) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -230,7 +240,7 @@ static int dnodeCheckDisk(char *dirName, int level, int primary) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dnodeUpdateDiskMeta(SDisk *pDisk) {
|
static int tdUpdateDiskMeta(SDisk *pDisk) {
|
||||||
struct statvfs dstat;
|
struct statvfs dstat;
|
||||||
if (statvfs(pDisk->dir, &dstat) < 0) {
|
if (statvfs(pDisk->dir, &dstat) < 0) {
|
||||||
uError("failed to get dir %s information since %s", pDisk->dir, strerror(errno));
|
uError("failed to get dir %s information since %s", pDisk->dir, strerror(errno));
|
||||||
|
@ -244,7 +254,7 @@ static int dnodeUpdateDiskMeta(SDisk *pDisk) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary) {
|
static int tdAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary) {
|
||||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
STier * pTier = NULL;
|
STier * pTier = NULL;
|
||||||
SDiskID diskid = {0};
|
SDiskID diskid = {0};
|
||||||
|
@ -256,7 +266,7 @@ static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primar
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeFormatDir(dir, dirName) < 0) {
|
if (tdFormatDir(dir, dirName) < 0) {
|
||||||
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -270,13 +280,13 @@ static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primar
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeGetDiskByName(pDnodeTier, dirName) != NULL) {
|
if (tdGetDiskByName(pDnodeTier, dirName) != NULL) {
|
||||||
terrno = TSDB_CODE_DND_DISK_ALREADY_EXISTS;
|
terrno = TSDB_CODE_DND_DISK_ALREADY_EXISTS;
|
||||||
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeCheckDisk(dirName, level, primary) < 0) {
|
if (tdCheckDisk(dirName, level, primary) < 0) {
|
||||||
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
uError("failed to add disk %s to tier %d level since %s", dir, level, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -320,6 +330,8 @@ static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primar
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(pDisk->dir, dirName, TSDB_FILENAME_LEN);
|
strncpy(pDisk->dir, dirName, TSDB_FILENAME_LEN);
|
||||||
|
pDisk->level = diskid.level;
|
||||||
|
pDisk->did = diskid.did;
|
||||||
|
|
||||||
if (taosHashPut(pDnodeTier->map, (void *)dirName, strnlen(dirName, TSDB_FILENAME_LEN), (void *)(&diskid),
|
if (taosHashPut(pDnodeTier->map, (void *)dirName, strnlen(dirName, TSDB_FILENAME_LEN), (void *)(&diskid),
|
||||||
sizeof(diskid)) < 0) {
|
sizeof(diskid)) < 0) {
|
||||||
|
@ -331,7 +343,7 @@ static int dnodeAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primar
|
||||||
|
|
||||||
pTier->nDisks++;
|
pTier->nDisks++;
|
||||||
pTier->disks[diskid.did] = pDisk;
|
pTier->disks[diskid.did] = pDisk;
|
||||||
pDnodeTier->nTiers = MAX(pDnodeTier->nTiers, level);
|
pDnodeTier->nTiers = MAX(pDnodeTier->nTiers, level + 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -170,13 +170,13 @@ static void dnodeCheckDataDirOpenned(char *dir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeInitStorage() {
|
static int32_t dnodeInitStorage() {
|
||||||
tsDnodeTier = dnodeNewTier();
|
tsDnodeTier = tdNewTier();
|
||||||
if (tsDnodeTier == NULL) {
|
if (tsDnodeTier == NULL) {
|
||||||
dError("failed to create new dnode tier since %s", tstrerror(terrno));
|
dError("failed to create new dnode tier since %s", tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeAddDisks(tsDnodeTier, tsDiskCfg, tsDiskCfgNum) < 0) {
|
if (tdAddDisks(tsDnodeTier, tsDiskCfg, tsDiskCfgNum) < 0) {
|
||||||
dError("failed to add disks to dnode tier since %s", tstrerror(terrno));
|
dError("failed to add disks to dnode tier since %s", tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ static int32_t dnodeInitStorage() {
|
||||||
|
|
||||||
STier *pTier = tsDnodeTier->tiers + i;
|
STier *pTier = tsDnodeTier->tiers + i;
|
||||||
for (int j = 0; j < pTier->nDisks; j++) {
|
for (int j = 0; j < pTier->nDisks; j++) {
|
||||||
SDisk *pDisk = dnodeGetDisk(tsDnodeTier, i, j);
|
SDisk *pDisk = tdGetDisk(tsDnodeTier, i, j);
|
||||||
|
|
||||||
tdGetVnodeRootDir(dirName, pDisk->dir);
|
tdGetVnodeRootDir(dirName, pDisk->dir);
|
||||||
if (dnodeCreateDir(dirName) < 0) {
|
if (dnodeCreateDir(dirName) < 0) {
|
||||||
|
@ -225,7 +225,7 @@ static int32_t dnodeInitStorage() {
|
||||||
|
|
||||||
static void dnodeCleanupStorage() {
|
static void dnodeCleanupStorage() {
|
||||||
if (tsDnodeTier) {
|
if (tsDnodeTier) {
|
||||||
dnodeCloseTier(tsDnodeTier);
|
tdCloseTier(tsDnodeTier);
|
||||||
tsDnodeTier = NULL;
|
tsDnodeTier = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,14 @@ typedef struct {
|
||||||
|
|
||||||
// ------------------ tsdbFile.c
|
// ------------------ tsdbFile.c
|
||||||
extern const char* tsdbFileSuffix[];
|
extern const char* tsdbFileSuffix[];
|
||||||
|
|
||||||
|
// minFid <= midFid <= maxFid
|
||||||
|
typedef struct {
|
||||||
|
int minFid; // >= minFid && < midFid, at level 2
|
||||||
|
int midFid; // >= midFid && < maxFid, at level 1
|
||||||
|
int maxFid; // >= maxFid, at level 0
|
||||||
|
} SFidGroup;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_FILE_TYPE_HEAD = 0,
|
TSDB_FILE_TYPE_HEAD = 0,
|
||||||
TSDB_FILE_TYPE_DATA,
|
TSDB_FILE_TYPE_DATA,
|
||||||
|
@ -189,7 +197,9 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fileId;
|
int fileId;
|
||||||
int state; // 0 for health, 1 for problem
|
int state; // 0 for health, 1 for problem
|
||||||
|
int level;
|
||||||
|
int did;
|
||||||
SFile files[TSDB_FILE_TYPE_MAX];
|
SFile files[TSDB_FILE_TYPE_MAX];
|
||||||
} SFileGroup;
|
} SFileGroup;
|
||||||
|
|
||||||
|
@ -483,17 +493,17 @@ int tsdbOpenFile(SFile* pFile, int oflag);
|
||||||
void tsdbCloseFile(SFile* pFile);
|
void tsdbCloseFile(SFile* pFile);
|
||||||
int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type, SDisk* pDisk);
|
int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type, SDisk* pDisk);
|
||||||
SFileGroup* tsdbSearchFGroup(STsdbFileH* pFileH, int fid, int flags);
|
SFileGroup* tsdbSearchFGroup(STsdbFileH* pFileH, int fid, int flags);
|
||||||
void tsdbRemoveFilesBeyondRetention(STsdbRepo* pRepo, int mfid);
|
void tsdbRemoveFilesBeyondRetention(STsdbRepo* pRepo, SFidGroup* pFidGroup);
|
||||||
int tsdbUpdateFileHeader(SFile* pFile);
|
int tsdbUpdateFileHeader(SFile* pFile);
|
||||||
int tsdbEncodeSFileInfo(void** buf, const STsdbFileInfo* pInfo);
|
int tsdbEncodeSFileInfo(void** buf, const STsdbFileInfo* pInfo);
|
||||||
void* tsdbDecodeSFileInfo(void* buf, STsdbFileInfo* pInfo);
|
void* tsdbDecodeSFileInfo(void* buf, STsdbFileInfo* pInfo);
|
||||||
void tsdbRemoveFileGroup(STsdbRepo* pRepo, SFileGroup* pFGroup);
|
void tsdbRemoveFileGroup(STsdbRepo* pRepo, SFileGroup* pFGroup);
|
||||||
int tsdbLoadFileHeader(SFile* pFile, uint32_t* version);
|
int tsdbLoadFileHeader(SFile* pFile, uint32_t* version);
|
||||||
void tsdbGetFileInfoImpl(char* fname, uint32_t* magic, int64_t* size);
|
void tsdbGetFileInfoImpl(char* fname, uint32_t* magic, int64_t* size);
|
||||||
|
void tsdbGetFidGroup(STsdbCfg* pCfg, SFidGroup* pFidGroup);
|
||||||
void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TSKEY *minKey, TSKEY *maxKey);
|
void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TSKEY *minKey, TSKEY *maxKey);
|
||||||
int tsdbGetCurrMinFid(int8_t precision, int32_t keep, int32_t days);
|
|
||||||
int tsdbGetBaseDirFromFile(char* fname, char* baseDir);
|
int tsdbGetBaseDirFromFile(char* fname, char* baseDir);
|
||||||
int tsdbApplyRetention(STsdbRepo* pRepo);
|
int tsdbApplyRetention(STsdbRepo* pRepo, SFidGroup *pFidGroup);
|
||||||
|
|
||||||
// ------------------ tsdbRWHelper.c
|
// ------------------ tsdbRWHelper.c
|
||||||
#define TSDB_HELPER_CLEAR_STATE 0x0 // Clear state
|
#define TSDB_HELPER_CLEAR_STATE 0x0 // Clear state
|
||||||
|
|
|
@ -31,10 +31,11 @@ const char * tsdbFileSuffix[] = {".head", ".data", ".last", ".stat", ".h",
|
||||||
static void tsdbDestroyFile(SFile *pFile);
|
static void tsdbDestroyFile(SFile *pFile);
|
||||||
static int compFGroup(const void *arg1, const void *arg2);
|
static int compFGroup(const void *arg1, const void *arg2);
|
||||||
static int keyFGroupCompFunc(const void *key, const void *fgroup);
|
static int keyFGroupCompFunc(const void *key, const void *fgroup);
|
||||||
static TSKEY tsdbGetCurrMinKey(int8_t precision, int32_t keep);
|
|
||||||
static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk);
|
static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk);
|
||||||
static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName);
|
static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName);
|
||||||
static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup);
|
static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup);
|
||||||
|
static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup);
|
||||||
|
static int tsdbCreateVnodeDataDir(char *baseDir, int vid);
|
||||||
|
|
||||||
// ---------------- INTERNAL FUNCTIONS ----------------
|
// ---------------- INTERNAL FUNCTIONS ----------------
|
||||||
STsdbFileH *tsdbNewFileH(STsdbCfg *pCfg) {
|
STsdbFileH *tsdbNewFileH(STsdbCfg *pCfg) {
|
||||||
|
@ -115,13 +116,15 @@ SFileGroup *tsdbCreateFGroup(STsdbRepo *pRepo, int fid) {
|
||||||
ASSERT(tsdbSearchFGroup(pFileH, fid, TD_EQ) == NULL);
|
ASSERT(tsdbSearchFGroup(pFileH, fid, TD_EQ) == NULL);
|
||||||
|
|
||||||
// TODO: think about if (level == 0) is correct
|
// TODO: think about if (level == 0) is correct
|
||||||
SDisk *pDisk = dnodeAssignDisk(tsDnodeTier, 0);
|
SDisk *pDisk = tdAssignDisk(tsDnodeTier, 0);
|
||||||
if (pDisk == NULL) {
|
if (pDisk == NULL) {
|
||||||
tsdbError("vgId:%d failed to create file group %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
|
tsdbError("vgId:%d failed to create file group %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fGroup.fileId = fid;
|
fGroup.fileId = fid;
|
||||||
|
fGroup.level = pDisk->level;
|
||||||
|
fGroup.did = pDisk->did;
|
||||||
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
if (tsdbCreateFile(&(fGroup.files[type]), pRepo, fid, type, pDisk) < 0) goto _err;
|
if (tsdbCreateFile(&(fGroup.files[type]), pRepo, fid, type, pDisk) < 0) goto _err;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +139,7 @@ _err:
|
||||||
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
tsdbDestroyFile(&(fGroup.files[type]));
|
tsdbDestroyFile(&(fGroup.files[type]));
|
||||||
}
|
}
|
||||||
dnodeDecDiskFiles(tsDnodeTier, pDisk, true);
|
tdDecDiskFiles(tsDnodeTier, pDisk, true);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,13 +273,13 @@ SFileGroup *tsdbSearchFGroup(STsdbFileH *pFileH, int fid, int flags) {
|
||||||
return (SFileGroup *)ptr;
|
return (SFileGroup *)ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbRemoveFilesBeyondRetention(STsdbRepo *pRepo, int mfid) {
|
void tsdbRemoveFilesBeyondRetention(STsdbRepo *pRepo, SFidGroup *pFidGroup) {
|
||||||
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||||
SFileGroup *pGroup = pFileH->pFGroup;
|
SFileGroup *pGroup = pFileH->pFGroup;
|
||||||
|
|
||||||
pthread_rwlock_wrlock(&(pFileH->fhlock));
|
pthread_rwlock_wrlock(&(pFileH->fhlock));
|
||||||
|
|
||||||
while (pFileH->nFGroups > 0 && pGroup[0].fileId < mfid) {
|
while (pFileH->nFGroups > 0 && pGroup[0].fileId < pFidGroup->minFid) {
|
||||||
tsdbRemoveFileGroup(pRepo, pGroup);
|
tsdbRemoveFileGroup(pRepo, pGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +342,7 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) {
|
||||||
|
|
||||||
SFileGroup fileGroup = *pFGroup;
|
SFileGroup fileGroup = *pFGroup;
|
||||||
tsdbGetBaseDirFromFile(fileGroup.files[0].fname, baseDir);
|
tsdbGetBaseDirFromFile(fileGroup.files[0].fname, baseDir);
|
||||||
pDisk = dnodeGetDiskByName(tsDnodeTier, baseDir);
|
pDisk = tdGetDiskByName(tsDnodeTier, baseDir);
|
||||||
ASSERT(pDisk != NULL);
|
ASSERT(pDisk != NULL);
|
||||||
|
|
||||||
int nFilesLeft = pFileH->nFGroups - (int)(POINTER_DISTANCE(pFGroup, pFileH->pFGroup) / sizeof(SFileGroup) + 1);
|
int nFilesLeft = pFileH->nFGroups - (int)(POINTER_DISTANCE(pFGroup, pFileH->pFGroup) / sizeof(SFileGroup) + 1);
|
||||||
|
@ -357,7 +360,7 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) {
|
||||||
tsdbDestroyFile(&fileGroup.files[type]);
|
tsdbDestroyFile(&fileGroup.files[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDisk->dmeta.nfiles--;
|
tdDecDiskFiles(tsDnodeTier, pDisk, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbLoadFileHeader(SFile *pFile, uint32_t *version) {
|
int tsdbLoadFileHeader(SFile *pFile, uint32_t *version) {
|
||||||
|
@ -415,8 +418,15 @@ _err:
|
||||||
*size = 0;
|
*size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbGetCurrMinFid(int8_t precision, int32_t keep, int32_t days) {
|
void tsdbGetFidGroup(STsdbCfg *pCfg, SFidGroup *pFidGroup) {
|
||||||
return (int)(TSDB_KEY_FILEID(tsdbGetCurrMinKey(precision, keep), days, precision));
|
TSKEY now = taosGetTimestamp(pCfg->precision);
|
||||||
|
|
||||||
|
pFidGroup->minFid =
|
||||||
|
TSDB_KEY_FILEID(now - pCfg->keep * tsMsPerDay[pCfg->precision], pCfg->daysPerFile, pCfg->precision);
|
||||||
|
pFidGroup->midFid =
|
||||||
|
TSDB_KEY_FILEID(now - pCfg->keep2 * tsMsPerDay[pCfg->precision], pCfg->daysPerFile, pCfg->precision);
|
||||||
|
pFidGroup->maxFid =
|
||||||
|
TSDB_KEY_FILEID(now - pCfg->keep1 * tsMsPerDay[pCfg->precision], pCfg->daysPerFile, pCfg->precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbGetBaseDirFromFile(char *fname, char *baseDir) {
|
int tsdbGetBaseDirFromFile(char *fname, char *baseDir) {
|
||||||
|
@ -435,8 +445,54 @@ int tsdbGetBaseDirFromFile(char *fname, char *baseDir) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbApplyRetention(STsdbRepo *pRepo) {
|
int tsdbApplyRetention(STsdbRepo *pRepo, SFidGroup *pFidGroup) {
|
||||||
// TODO
|
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||||
|
SFileGroup *pGroup = NULL;
|
||||||
|
SFileGroup nFileGroup = {0};
|
||||||
|
SFileGroup oFileGroup = {0};
|
||||||
|
int level = 0;
|
||||||
|
|
||||||
|
if (tsDnodeTier->nTiers == 1 || (pFidGroup->minFid == pFidGroup->midFid && pFidGroup->midFid == pFidGroup->maxFid)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int gidx = pFileH->nFGroups - 1; gidx >= 0; gidx--) {
|
||||||
|
pGroup = pFileH->pFGroup + gidx;
|
||||||
|
|
||||||
|
level = tsdbGetFidLevel(pGroup->fileId, pFidGroup);
|
||||||
|
|
||||||
|
if (level == pGroup->level) continue;
|
||||||
|
if (level > pGroup->level && level < tsDnodeTier->nTiers) {
|
||||||
|
SDisk *pODisk = tdGetDisk(tsDnodeTier, pGroup->level, pGroup->did);
|
||||||
|
SDisk *pDisk = tdAssignDisk(tsDnodeTier, level);
|
||||||
|
tsdbCreateVnodeDataDir(pDisk->dir, REPO_ID(pRepo));
|
||||||
|
oFileGroup = *pGroup;
|
||||||
|
nFileGroup = *pGroup;
|
||||||
|
nFileGroup.level = level;
|
||||||
|
nFileGroup.did = pDisk->did;
|
||||||
|
|
||||||
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
|
// TODO fileGroup.files[type].fname
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_rwlock_wrlock(&(pFileH->fhlock));
|
||||||
|
*pGroup = nFileGroup;
|
||||||
|
pthread_rwlock_unlock(&(pFileH->fhlock));
|
||||||
|
|
||||||
|
for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
|
||||||
|
(void)remove(oFileGroup.files[type].fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
tdLockTiers(tsDnodeTier);
|
||||||
|
tdDecDiskFiles(tsDnodeTier, pODisk, false);
|
||||||
|
tdIncDiskFiles(tsDnodeTier, pDisk, false);
|
||||||
|
tdUnLockTiers(tsDnodeTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,10 +522,6 @@ static int keyFGroupCompFunc(const void *key, const void *fgroup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TSKEY tsdbGetCurrMinKey(int8_t precision, int32_t keep) {
|
|
||||||
return (TSKEY)(taosGetTimestamp(precision) - keep * tsMsPerDay[precision]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) {
|
static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) {
|
||||||
char tsdbDataDir[TSDB_FILENAME_LEN] = "\0";
|
char tsdbDataDir[TSDB_FILENAME_LEN] = "\0";
|
||||||
char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
|
char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
@ -479,6 +531,7 @@ static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) {
|
||||||
STsdbFileH * pFileH = pRepo->tsdbFileH;
|
STsdbFileH * pFileH = pRepo->tsdbFileH;
|
||||||
SFileGroup fgroup = {0};
|
SFileGroup fgroup = {0};
|
||||||
STsdbCfg * pCfg = &(pRepo->config);
|
STsdbCfg * pCfg = &(pRepo->config);
|
||||||
|
SFidGroup fidGroup = {0};
|
||||||
int mfid = 0;
|
int mfid = 0;
|
||||||
|
|
||||||
tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir);
|
tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir);
|
||||||
|
@ -494,7 +547,8 @@ static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
mfid = tsdbGetCurrMinFid(pCfg->precision, pCfg->keep, pCfg->daysPerFile);
|
tsdbGetFidGroup(pCfg, &fidGroup);
|
||||||
|
mfid = fidGroup.minFid;
|
||||||
|
|
||||||
while (taosHashIterNext(pIter)) {
|
while (taosHashIterNext(pIter)) {
|
||||||
int32_t fid = *(int32_t *)taosHashIterGet(pIter);
|
int32_t fid = *(int32_t *)taosHashIterGet(pIter);
|
||||||
|
@ -677,4 +731,45 @@ _err:
|
||||||
if (dir != NULL) closedir(dir);
|
if (dir != NULL) closedir(dir);
|
||||||
regfree(®ex);
|
regfree(®ex);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup) {
|
||||||
|
if (fid >= pFidGroup->maxFid) {
|
||||||
|
return 0;
|
||||||
|
} else if (fid >= pFidGroup->midFid && fid < pFidGroup->maxFid) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbCreateVnodeDataDir(char *baseDir, int vid) {
|
||||||
|
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
|
||||||
|
tdGetVnodeRootDir(baseDir, dirName);
|
||||||
|
if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdGetVnodeDir(baseDir, vid, dirName);
|
||||||
|
if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdGetTsdbRootDir(baseDir, vid, tsdbRootDir);
|
||||||
|
if (taosMkDir(tsdbRootDir, 0755) < 0 && errno != EEXIST) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdGetTsdbDataDir(baseDir, vid, dirName);
|
||||||
|
if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -471,6 +471,7 @@ static void *tsdbCommitData(void *arg) {
|
||||||
SDataCols * pDataCols = NULL;
|
SDataCols * pDataCols = NULL;
|
||||||
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
||||||
SCommitIter *iters = NULL;
|
SCommitIter *iters = NULL;
|
||||||
|
SFidGroup fidGroup = {0};
|
||||||
SRWHelper whelper = {0};
|
SRWHelper whelper = {0};
|
||||||
TSKEY minKey = 0, maxKey = 0;
|
TSKEY minKey = 0, maxKey = 0;
|
||||||
ASSERT(pRepo->commit == 1);
|
ASSERT(pRepo->commit == 1);
|
||||||
|
@ -479,9 +480,9 @@ static void *tsdbCommitData(void *arg) {
|
||||||
tsdbInfo("vgId:%d start to commit! keyFirst %" PRId64 " keyLast %" PRId64 " numOfRows %" PRId64, REPO_ID(pRepo),
|
tsdbInfo("vgId:%d start to commit! keyFirst %" PRId64 " keyLast %" PRId64 " numOfRows %" PRId64, REPO_ID(pRepo),
|
||||||
pMem->keyFirst, pMem->keyLast, pMem->numOfRows);
|
pMem->keyFirst, pMem->keyLast, pMem->numOfRows);
|
||||||
|
|
||||||
int mfid = tsdbGetCurrMinFid(pCfg->precision, pCfg->keep, pCfg->daysPerFile);
|
tsdbGetFidGroup(pCfg, &fidGroup);
|
||||||
tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, mfid, &minKey, &maxKey);
|
tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, fidGroup.minFid, &minKey, &maxKey);
|
||||||
tsdbRemoveFilesBeyondRetention(pRepo, mfid);
|
tsdbRemoveFilesBeyondRetention(pRepo, &fidGroup);
|
||||||
|
|
||||||
// Create the iterator to read from cache
|
// Create the iterator to read from cache
|
||||||
if (pMem->numOfRows > 0) {
|
if (pMem->numOfRows > 0) {
|
||||||
|
@ -510,7 +511,7 @@ static void *tsdbCommitData(void *arg) {
|
||||||
|
|
||||||
// Loop to commit to each file
|
// Loop to commit to each file
|
||||||
for (int fid = sfid; fid <= efid; fid++) {
|
for (int fid = sfid; fid <= efid; fid++) {
|
||||||
if (fid < mfid) continue;
|
if (fid < fidGroup.minFid) continue;
|
||||||
|
|
||||||
if (tsdbCommitToFile(pRepo, fid, iters, &whelper, pDataCols) < 0) {
|
if (tsdbCommitToFile(pRepo, fid, iters, &whelper, pDataCols) < 0) {
|
||||||
tsdbError("vgId:%d failed to commit to file %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
|
tsdbError("vgId:%d failed to commit to file %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
|
||||||
|
@ -519,7 +520,7 @@ static void *tsdbCommitData(void *arg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbApplyRetention(pRepo);
|
tsdbApplyRetention(pRepo, &fidGroup);
|
||||||
|
|
||||||
// Commit to update meta file
|
// Commit to update meta file
|
||||||
if (tsdbCommitMeta(pRepo) < 0) {
|
if (tsdbCommitMeta(pRepo) < 0) {
|
||||||
|
|
Loading…
Reference in New Issue