refact: rename snap range to fset range in tsdbSnapInfo.c

This commit is contained in:
Benguang Zhao 2023-12-01 17:21:27 +08:00
parent 3550347f0c
commit ed39c9a572
2 changed files with 98 additions and 95 deletions

View File

@ -690,12 +690,12 @@ int32_t tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
// fset partition // fset partition
enum { enum {
TSDB_SNAP_RANGE_TYP_HEAD = 0, TSDB_FSET_RANGE_TYP_HEAD = 0,
TSDB_SNAP_RANGE_TYP_DATA, TSDB_FSET_RANGE_TYP_DATA,
TSDB_SNAP_RANGE_TYP_SMA, TSDB_FSET_RANGE_TYP_SMA,
TSDB_SNAP_RANGE_TYP_TOMB, TSDB_FSET_RANGE_TYP_TOMB,
TSDB_SNAP_RANGE_TYP_STT, TSDB_FSET_RANGE_TYP_STT,
TSDB_SNAP_RANGE_TYP_MAX, TSDB_FSET_RANGE_TYP_MAX,
}; };
typedef TARRAY2(SVersionRange) SVerRangeList; typedef TARRAY2(SVersionRange) SVerRangeList;
@ -703,7 +703,7 @@ typedef TARRAY2(SVersionRange) SVerRangeList;
struct STsdbFSetPartition { struct STsdbFSetPartition {
int64_t fid; int64_t fid;
int8_t stat; int8_t stat;
SVerRangeList verRanges[TSDB_SNAP_RANGE_TYP_MAX]; SVerRangeList verRanges[TSDB_FSET_RANGE_TYP_MAX];
}; };
typedef struct STsdbFSetPartition STsdbFSetPartition; typedef struct STsdbFSetPartition STsdbFSetPartition;

View File

@ -31,7 +31,7 @@ static int32_t tVersionRangeCmprFn(SVersionRange* x, SVersionRange* y) {
return 0; return 0;
} }
static int32_t tsdbFileSetRangeCmprFn(STFileSetRange* x, STFileSetRange* y) { static int32_t tsdbTFileSetRangeCmprFn(STFileSetRange* x, STFileSetRange* y) {
if (x->fid < y->fid) return -1; if (x->fid < y->fid) return -1;
if (x->fid > y->fid) return 1; if (x->fid > y->fid) return 1;
return 0; return 0;
@ -43,7 +43,7 @@ STsdbFSetPartition* tsdbFSetPartitionCreate() {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
for (int32_t i = 0; i < TSDB_SNAP_RANGE_TYP_MAX; i++) { for (int32_t i = 0; i < TSDB_FSET_RANGE_TYP_MAX; i++) {
TARRAY2_INIT(&pSP->verRanges[i]); TARRAY2_INIT(&pSP->verRanges[i]);
} }
return pSP; return pSP;
@ -53,30 +53,30 @@ void tsdbFSetPartitionClear(STsdbFSetPartition** ppSP) {
if (ppSP == NULL || ppSP[0] == NULL) { if (ppSP == NULL || ppSP[0] == NULL) {
return; return;
} }
for (int32_t i = 0; i < TSDB_SNAP_RANGE_TYP_MAX; i++) { for (int32_t i = 0; i < TSDB_FSET_RANGE_TYP_MAX; i++) {
TARRAY2_DESTROY(&ppSP[0]->verRanges[i], NULL); TARRAY2_DESTROY(&ppSP[0]->verRanges[i], NULL);
} }
taosMemoryFree(ppSP[0]); taosMemoryFree(ppSP[0]);
ppSP[0] = NULL; ppSP[0] = NULL;
} }
static int32_t tsdbFTypeToSRangeTyp(tsdb_ftype_t ftype) { static int32_t tsdbFTypeToFRangeType(tsdb_ftype_t ftype) {
switch (ftype) { switch (ftype) {
case TSDB_FTYPE_HEAD: case TSDB_FTYPE_HEAD:
return TSDB_SNAP_RANGE_TYP_HEAD; return TSDB_FSET_RANGE_TYP_HEAD;
case TSDB_FTYPE_DATA: case TSDB_FTYPE_DATA:
return TSDB_SNAP_RANGE_TYP_DATA; return TSDB_FSET_RANGE_TYP_DATA;
case TSDB_FTYPE_SMA: case TSDB_FTYPE_SMA:
return TSDB_SNAP_RANGE_TYP_SMA; return TSDB_FSET_RANGE_TYP_SMA;
case TSDB_FTYPE_TOMB: case TSDB_FTYPE_TOMB:
return TSDB_SNAP_RANGE_TYP_TOMB; return TSDB_FSET_RANGE_TYP_TOMB;
case TSDB_FTYPE_STT: case TSDB_FTYPE_STT:
return TSDB_SNAP_RANGE_TYP_STT; return TSDB_FSET_RANGE_TYP_STT;
} }
return TSDB_SNAP_RANGE_TYP_MAX; return TSDB_FSET_RANGE_TYP_MAX;
} }
static int32_t tsdbTFileSetToSnapPart(STFileSet* fset, STsdbFSetPartition** ppSP) { static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** ppSP) {
STsdbFSetPartition* p = tsdbFSetPartitionCreate(); STsdbFSetPartition* p = tsdbFSetPartitionCreate();
if (p == NULL) { if (p == NULL) {
goto _err; goto _err;
@ -90,8 +90,8 @@ static int32_t tsdbTFileSetToSnapPart(STFileSet* fset, STsdbFSetPartition** ppSP
int32_t count = 0; int32_t count = 0;
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if (fset->farr[ftype] == NULL) continue; if (fset->farr[ftype] == NULL) continue;
typ = tsdbFTypeToSRangeTyp(ftype); typ = tsdbFTypeToFRangeType(ftype);
ASSERT(typ < TSDB_SNAP_RANGE_TYP_MAX); ASSERT(typ < TSDB_FSET_RANGE_TYP_MAX);
STFile* f = fset->farr[ftype]->f; STFile* f = fset->farr[ftype]->f;
if (f->maxVer > fset->maxVerValid) { if (f->maxVer > fset->maxVerValid) {
corrupt = true; corrupt = true;
@ -106,7 +106,7 @@ static int32_t tsdbTFileSetToSnapPart(STFileSet* fset, STsdbFSetPartition** ppSP
ASSERT(code == 0); ASSERT(code == 0);
} }
typ = TSDB_SNAP_RANGE_TYP_STT; typ = TSDB_FSET_RANGE_TYP_STT;
const SSttLvl* lvl; const SSttLvl* lvl;
TARRAY2_FOREACH(fset->lvlArr, lvl) { TARRAY2_FOREACH(fset->lvlArr, lvl) {
STFileObj* fobj; STFileObj* fobj;
@ -149,35 +149,61 @@ STsdbFSetPartList* tsdbFSetPartListCreate() {
return pList; return pList;
} }
static STsdbFSetPartList* tsdbGetSnapPartList(STFileSystem* fs) { void tsdbFSetPartListDestroy(STsdbFSetPartList** ppList) {
STsdbFSetPartList* pList = tsdbFSetPartListCreate(); if (ppList == NULL || ppList[0] == NULL) return;
if (pList == NULL) {
return NULL;
}
int32_t code = 0; TARRAY2_DESTROY(ppList[0], tsdbFSetPartitionClear);
taosThreadMutexLock(&fs->tsdb->mutex); taosMemoryFree(ppList[0]);
STFileSet* fset; ppList[0] = NULL;
TARRAY2_FOREACH(fs->fSetArr, fset) {
STsdbFSetPartition* pItem = NULL;
if (tsdbTFileSetToSnapPart(fset, &pItem) < 0) {
code = -1;
break;
}
ASSERT(pItem != NULL);
code = TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn);
ASSERT(code == 0);
}
taosThreadMutexUnlock(&fs->tsdb->mutex);
if (code) {
TARRAY2_DESTROY(pList, tsdbFSetPartitionClear);
taosMemoryFree(pList);
pList = NULL;
}
return pList;
} }
int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray** ppRanges) {
TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray));
if (pDiff == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
TARRAY2_INIT(pDiff);
STsdbFSetPartition* part;
TARRAY2_FOREACH(pList, part) {
STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange));
if (r == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
int64_t maxVerValid = -1;
int32_t typMax = TSDB_FSET_RANGE_TYP_MAX;
for (int32_t i = 0; i < typMax; i++) {
SVerRangeList* iList = &part->verRanges[i];
SVersionRange vr = {0};
TARRAY2_FOREACH(iList, vr) {
if (vr.maxVer < vr.minVer) {
continue;
}
maxVerValid = TMAX(maxVerValid, vr.maxVer);
}
}
r->fid = part->fid;
r->sver = maxVerValid + 1;
r->ever = VERSION_MAX;
tsdbDebug("range diff fid:%" PRId64 ", sver:%" PRId64 ", ever:%" PRId64, part->fid, r->sver, r->ever);
int32_t code = TARRAY2_SORT_INSERT(pDiff, r, tsdbTFileSetRangeCmprFn);
ASSERT(code == 0);
}
ppRanges[0] = pDiff;
tsdbInfo("pDiff size:%d", TARRAY2_SIZE(pDiff));
return 0;
_err:
if (pDiff) {
tsdbTFileSetRangeArrayDestroy(&pDiff);
}
return -1;
}
// serialization
int32_t tTsdbFSetPartListDataLenCalc(STsdbFSetPartList* pList) { int32_t tTsdbFSetPartListDataLenCalc(STsdbFSetPartList* pList) {
int32_t hdrLen = sizeof(int32_t); int32_t hdrLen = sizeof(int32_t);
int32_t datLen = 0; int32_t datLen = 0;
@ -190,7 +216,7 @@ int32_t tTsdbFSetPartListDataLenCalc(STsdbFSetPartList* pList) {
for (int32_t u = 0; u < len; u++) { for (int32_t u = 0; u < len; u++) {
STsdbFSetPartition* p = TARRAY2_GET(pList, u); STsdbFSetPartition* p = TARRAY2_GET(pList, u);
int32_t typMax = TSDB_SNAP_RANGE_TYP_MAX; int32_t typMax = TSDB_FSET_RANGE_TYP_MAX;
int32_t uItem = 0; int32_t uItem = 0;
uItem += sizeof(STsdbFSetPartition); uItem += sizeof(STsdbFSetPartition);
uItem += sizeof(typMax); uItem += sizeof(typMax);
@ -229,7 +255,7 @@ int32_t tSerializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartList*
if (tEncodeI8(&encoder, reserved8) < 0) goto _err; if (tEncodeI8(&encoder, reserved8) < 0) goto _err;
if (tEncodeI16(&encoder, reserved16) < 0) goto _err; if (tEncodeI16(&encoder, reserved16) < 0) goto _err;
int32_t typMax = TSDB_SNAP_RANGE_TYP_MAX; int32_t typMax = TSDB_FSET_RANGE_TYP_MAX;
if (tEncodeI32(&encoder, typMax) < 0) goto _err; if (tEncodeI32(&encoder, typMax) < 0) goto _err;
for (int32_t i = 0; i < typMax; i++) { for (int32_t i = 0; i < typMax; i++) {
@ -311,58 +337,34 @@ _err:
return -1; return -1;
} }
int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray** ppRanges) { // fs state
TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray)); static STsdbFSetPartList* tsdbSnapGetFSetPartList(STFileSystem* fs) {
if (pDiff == NULL) { STsdbFSetPartList* pList = tsdbFSetPartListCreate();
terrno = TSDB_CODE_OUT_OF_MEMORY; if (pList == NULL) {
goto _err; return NULL;
} }
TARRAY2_INIT(pDiff);
STsdbFSetPartition* part; int32_t code = 0;
TARRAY2_FOREACH(pList, part) { taosThreadMutexLock(&fs->tsdb->mutex);
STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange)); STFileSet* fset;
if (r == NULL) { TARRAY2_FOREACH(fs->fSetArr, fset) {
terrno = TSDB_CODE_OUT_OF_MEMORY; STsdbFSetPartition* pItem = NULL;
goto _err; if (tsdbTFileSetToFSetPartition(fset, &pItem) < 0) {
code = -1;
break;
} }
int64_t maxVerValid = -1; ASSERT(pItem != NULL);
int32_t typMax = TSDB_SNAP_RANGE_TYP_MAX; code = TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn);
for (int32_t i = 0; i < typMax; i++) {
SVerRangeList* iList = &part->verRanges[i];
SVersionRange vr = {0};
TARRAY2_FOREACH(iList, vr) {
if (vr.maxVer < vr.minVer) {
continue;
}
maxVerValid = TMAX(maxVerValid, vr.maxVer);
}
}
r->fid = part->fid;
r->sver = maxVerValid + 1;
r->ever = VERSION_MAX;
tsdbDebug("range diff fid:%" PRId64 ", sver:%" PRId64 ", ever:%" PRId64, part->fid, r->sver, r->ever);
int32_t code = TARRAY2_SORT_INSERT(pDiff, r, tsdbFileSetRangeCmprFn);
ASSERT(code == 0); ASSERT(code == 0);
} }
ppRanges[0] = pDiff; taosThreadMutexUnlock(&fs->tsdb->mutex);
tsdbInfo("pDiff size:%d", TARRAY2_SIZE(pDiff)); if (code) {
return 0; TARRAY2_DESTROY(pList, tsdbFSetPartitionClear);
taosMemoryFree(pList);
_err: pList = NULL;
if (pDiff) {
tsdbTFileSetRangeArrayDestroy(&pDiff);
} }
return -1; return pList;
}
void tsdbFSetPartListDestroy(STsdbFSetPartList** ppList) {
if (ppList == NULL || ppList[0] == NULL) return;
TARRAY2_DESTROY(ppList[0], tsdbFSetPartitionClear);
taosMemoryFree(ppList[0]);
ppList[0] = NULL;
} }
ETsdbFsState tsdbSnapGetFsState(SVnode* pVnode) { ETsdbFsState tsdbSnapGetFsState(SVnode* pVnode) {
@ -378,6 +380,7 @@ ETsdbFsState tsdbSnapGetFsState(SVnode* pVnode) {
return TSDB_FS_STATE_NORMAL; return TSDB_FS_STATE_NORMAL;
} }
// description
int32_t tsdbSnapGetDetails(SVnode* pVnode, SSnapshot* pSnap) { int32_t tsdbSnapGetDetails(SVnode* pVnode, SSnapshot* pSnap) {
int code = -1; int code = -1;
int32_t tsdbMaxCnt = (!VND_IS_RSMA(pVnode) ? 1 : TSDB_RETENTION_MAX); int32_t tsdbMaxCnt = (!VND_IS_RSMA(pVnode) ? 1 : TSDB_RETENTION_MAX);
@ -387,7 +390,7 @@ int32_t tsdbSnapGetDetails(SVnode* pVnode, SSnapshot* pSnap) {
// get part list // get part list
for (int32_t j = 0; j < tsdbMaxCnt; ++j) { for (int32_t j = 0; j < tsdbMaxCnt; ++j) {
STsdb* pTsdb = SMA_RSMA_GET_TSDB(pVnode, j); STsdb* pTsdb = SMA_RSMA_GET_TSDB(pVnode, j);
pLists[j] = tsdbGetSnapPartList(pTsdb->pFS); pLists[j] = tsdbSnapGetFSetPartList(pTsdb->pFS);
if (pLists[j] == NULL) goto _out; if (pLists[j] == NULL) goto _out;
} }