diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index 200a310e18..dd437e4a36 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -57,6 +57,8 @@ void tsdbInitMFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver); void tsdbInitMFileEx(SMFile* pMFile, SMFile* pOMFile); int tsdbEncodeSMFile(void** buf, SMFile* pMFile); void* tsdbDecodeSMFile(void* buf, SMFile* pMFile); +int tsdbEncodeSMFileEx(void** buf, SMFile* pMFile); +void* tsdbDecodeSMFileEx(void* buf, SMFile* pMFile); int tsdbApplyMFileChange(SMFile* from, SMFile* to); int tsdbCreateMFile(SMFile* pMFile, bool updateHeader); int tsdbUpdateMFileHeader(SMFile* pMFile); @@ -301,6 +303,8 @@ void tsdbInitDFileSet(SDFileSet* pSet, SDiskID did, int vid, int fid, uint32_t void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); void* tsdbDecodeDFileSet(void* buf, SDFileSet* pSet); +int tsdbEncodeDFileSetEx(void** buf, SDFileSet* pSet); +void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet); int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to); int tsdbCreateDFileSet(SDFileSet* pSet, bool updateHeader); int tsdbUpdateDFileSetHeader(SDFileSet* pSet); diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 74dee5e98b..09d212e377 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -64,6 +64,27 @@ void *tsdbDecodeSMFile(void *buf, SMFile *pMFile) { return buf; } +int tsdbEncodeSMFileEx(void **buf, SMFile *pMFile) { + int tlen = 0; + + tlen += tsdbEncodeMFInfo(buf, &(pMFile->info)); + tlen += taosEncodeString(buf, TSDB_FILE_FULL_NAME(pMFile)); + + return tlen; +} + +void *tsdbDecodeSMFileEx(void *buf, SMFile *pMFile) { + char *aname; + buf = tsdbDecodeMFInfo(buf, &(pMFile->info)); + buf = taosDecodeString(buf, &aname); + strncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN); + TSDB_FILE_SET_CLOSED(pMFile); + + tfree(aname); + + return buf; +} + int tsdbApplyMFileChange(SMFile *from, SMFile *to) { ASSERT(from != NULL || to != NULL); @@ -262,6 +283,27 @@ void *tsdbDecodeSDFile(void *buf, SDFile *pDFile) { return buf; } +static int tsdbEncodeSDFileEx(void **buf, SDFile *pDFile) { + int tlen = 0; + + tlen += tsdbEncodeDFInfo(buf, &(pDFile->info)); + tlen += taosEncodeString(buf, TSDB_FILE_FULL_NAME(pDFile)); + + return tlen; +} + +static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { + char *aname; + + buf = tsdbDecodeDFInfo(buf, &(pDFile->info)); + buf = taosDecodeString(buf, &aname); + strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); + TSDB_FILE_SET_CLOSED(pDFile); + tfree(aname); + + return buf; +} + int tsdbCreateDFile(SDFile *pDFile, bool updateHeader) { ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC); @@ -451,6 +493,28 @@ void *tsdbDecodeDFileSet(void *buf, SDFileSet *pSet) { return buf; } +int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) { + int tlen = 0; + + tlen += taosEncodeFixedI32(buf, pSet->fid); + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + tlen += tsdbEncodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype)); + } + + return tlen; +} + +void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet) { + int32_t fid; + + buf = taosDecodeFixedI32(buf, &(fid)); + pSet->fid = fid; + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + buf = tsdbDecodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype)); + } + return buf; +} + int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { SDFile *pDFileFrom = (from) ? TSDB_DFILE_IN_SET(from, ftype) : NULL; diff --git a/src/tsdb/src/tsdbSync.c b/src/tsdb/src/tsdbSync.c index 953b7ca7b1..84c0e5b841 100644 --- a/src/tsdb/src/tsdbSync.c +++ b/src/tsdb/src/tsdbSync.c @@ -205,7 +205,7 @@ static int tsdbSendMetaInfo(SSyncH *pSynch) { SMFile * pMFile = pRepo->fs->cstatus->pmf; if (pMFile) { - tlen = tlen + tsdbEncodeSMFile(NULL, pMFile) + sizeof(TSCKSUM); + tlen = tlen + tsdbEncodeSMFileEx(NULL, pMFile) + sizeof(TSCKSUM); } if (tsdbMakeRoom((void **)(&SYNC_BUFFER(pSynch)), tlen) < 0) { @@ -216,7 +216,7 @@ static int tsdbSendMetaInfo(SSyncH *pSynch) { taosEncodeFixedU32(&ptr, tlen); void *tptr = ptr; if (pMFile) { - tsdbEncodeSMFile(&ptr, pMFile); + tsdbEncodeSMFileEx(&ptr, pMFile); taosCalcChecksumAppend(0, (uint8_t *)tptr, tlen); } @@ -263,7 +263,7 @@ static int tsdbRecvMetaInfo(SSyncH *pSynch) { } pSynch->pmf = &(pSynch->mf); - tsdbDecodeSMFile(SYNC_BUFFER(pSynch), pSynch->pmf); + tsdbDecodeSMFileEx(SYNC_BUFFER(pSynch), pSynch->pmf); return 0; } @@ -496,7 +496,7 @@ static int tsdbSendDFileSetInfo(SSyncH *pSynch, SDFileSet *pSet) { uint32_t tlen = 0; if (pSet) { - tlen = tsdbEncodeDFileSet(NULL, pSet) + sizeof(TSCKSUM); + tlen = tsdbEncodeDFileSetEx(NULL, pSet) + sizeof(TSCKSUM); } if (tsdbMakeRoom((void **)(&SYNC_BUFFER(pSynch)), tlen + sizeof(tlen)) < 0) { @@ -507,7 +507,7 @@ static int tsdbSendDFileSetInfo(SSyncH *pSynch, SDFileSet *pSet) { taosEncodeFixedU32(&ptr, tlen); void *tptr = ptr; if (pSet) { - tsdbEncodeDFileSet(&ptr, pSet); + tsdbEncodeDFileSetEx(&ptr, pSet); taosCalcChecksumAppend(0, (uint8_t *)tptr, tlen); } @@ -551,7 +551,7 @@ static int tsdbRecvDFileSetInfo(SSyncH *pSynch) { } pSynch->pdf = &(pSynch->df); - tsdbDecodeDFileSet(SYNC_BUFFER(pSynch), pSynch->pdf); + tsdbDecodeDFileSetEx(SYNC_BUFFER(pSynch), pSynch->pdf); return 0; } \ No newline at end of file