more refact

This commit is contained in:
Hongze Cheng 2022-06-05 08:42:18 +00:00
parent 5a8591052d
commit c59b52855b
3 changed files with 45 additions and 48 deletions

View File

@ -263,12 +263,12 @@ struct TSDBKEY {
};
typedef struct {
uint64_t suid;
uint64_t uid;
uint32_t len;
uint32_t offset;
uint32_t hasLast : 2;
uint32_t numOfBlocks : 30;
uint64_t suid;
uint64_t uid;
TSDBKEY maxKey;
} SBlockIdx;

View File

@ -20,6 +20,9 @@ typedef struct {
int32_t minutes;
int8_t precision;
TSKEY nCommitKey;
int32_t fid;
TSKEY minKey;
TSKEY maxKey;
SReadH readh;
SDFileSet wSet;
SArray *aBlkIdx;
@ -180,11 +183,11 @@ static int32_t tsdbCommitTable(SCommitH *pCHandle, SMemData *pMemData, SBlockIdx
// commit table impl
if (pMemData && pBlockIdx) {
// merge
// TODO
} else if (pMemData) {
// new one
// TODO
} else {
// save old ones
// TODO
}
// commit table end
@ -224,9 +227,13 @@ static int32_t tsdbWriteBlockIdx(SDFile *pFile, SArray *pArray, uint8_t **ppBuf)
return code;
}
static int32_t tsdbCommitFileStart(SCommitH *pCHandle, int32_t fid) {
static int32_t tsdbCommitFileStart(SCommitH *pCHandle) {
int32_t code = 0;
// TODO
STsdb *pTsdb = pCHandle->pMemTable->pTsdb;
SDFileSet *pSet = NULL;
taosArrayClear(pCHandle->aBlkIdx);
return code;
}
@ -236,61 +243,50 @@ static int32_t tsdbCommitFileEnd(SCommitH *pCHandle) {
return code;
}
static int32_t tsdbCommitFile(SCommitH *pCHandle, int32_t fid) {
static int32_t tsdbCommitFile(SCommitH *pCHandle) {
int32_t code = 0;
SMemDataIter iter = {0};
TSDBROW *pRow = NULL;
int8_t hasData = 0;
TSKEY fidSKey;
TSKEY fidEKey;
SMemData *pMemData;
SBlockIdx *pBlockIdx;
int32_t iMemData;
int32_t nMemData;
int32_t iBlockIdx;
int32_t nBlockIdx;
pCHandle->nCommitKey = TSKEY_MAX;
// create or open the file to commit(todo)
code = tsdbCommitFileStart(pCHandle, fid);
// commit file start
code = tsdbCommitFileStart(pCHandle);
if (code) {
goto _err;
}
// loop to commit each table data
// commit file impl
iMemData = 0;
nMemData = taosArrayGetSize(pCHandle->pMemTable->aMemData);
iBlockIdx = 0;
nBlockIdx = 0;
for (;;) {
if (iBlockIdx >= nBlockIdx && iMemData >= nMemData) {
// code = tsdbWriteBlockIdx();
// if (code) {
// goto _err;
// }
break;
}
nBlockIdx = 0; // todo
SMemData *pMemData = NULL;
SBlockIdx *pBlockIdx = NULL;
for (;;) {
if (iMemData >= nMemData && iBlockIdx >= nBlockIdx) break;
pMemData = NULL;
pBlockIdx = NULL;
if (iMemData < nMemData) {
pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iBlockIdx);
pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iMemData);
}
if (iBlockIdx < nBlockIdx) {
// pBlockIdx
// pBlockIdx = ;
}
if (pMemData && pBlockIdx) {
int32_t c = tsdbTableIdCmprFn(&(TABLEID){.suid = pMemData->suid, .uid = pMemData->uid},
&(TABLEID){.suid = pBlockIdx->suid, .uid = pBlockIdx->uid});
if (c == 0) {
int32_t c = tsdbTableIdCmprFn(pMemData, pBlockIdx);
if (c < 0) {
iMemData++;
iBlockIdx++;
} else if (c < 0) {
pBlockIdx = NULL;
} else if (c == 0) {
iMemData++;
} else {
pMemData = NULL;
iBlockIdx++;
} else {
iBlockIdx++;
pMemData = NULL;
}
} else {
if (pMemData) {
@ -306,7 +302,7 @@ static int32_t tsdbCommitFile(SCommitH *pCHandle, int32_t fid) {
}
}
// close file
// commit file end
code = tsdbCommitFileEnd(pCHandle);
if (code) {
goto _err;
@ -328,8 +324,9 @@ static int32_t tsdbCommitData(SCommitH *pCHandle) {
for (;;) {
if (pCHandle->nCommitKey == TSKEY_MAX) break;
fid = TSDB_KEY_FID(pCHandle->nCommitKey, pCHandle->minutes, pCHandle->precision);
code = tsdbCommitFile(pCHandle, fid);
pCHandle->fid = TSDB_KEY_FID(pCHandle->nCommitKey, pCHandle->minutes, pCHandle->precision);
tsdbGetFidKeyRange(pCHandle->minutes, pCHandle->precision, pCHandle->fid, &pCHandle->minKey, &pCHandle->maxKey);
code = tsdbCommitFile(pCHandle);
if (code) {
goto _err;
}

View File

@ -25,7 +25,7 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"meta", // TSDB_FILE_META
};
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char* dname, char *fname);
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname);
// static int tsdbRollBackMFile(SMFile *pMFile);
static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo);
static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo);