From 40a591bdfaf036c11e362412bb2dd62aab286b6c Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 24 Sep 2021 10:37:51 +0800 Subject: [PATCH] sync compatibility for upgrading --- src/tsdb/inc/tsdbFile.h | 2 +- src/tsdb/src/tsdbCommit.c | 4 ++-- src/tsdb/src/tsdbCompact.c | 2 +- src/tsdb/src/tsdbFS.c | 3 ++- src/tsdb/src/tsdbFile.c | 8 ++++---- src/tsdb/src/tsdbSync.c | 11 +++++++---- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index 1713240b29..c92cc43041 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -324,7 +324,7 @@ typedef struct { } \ } while (0); -void tsdbInitDFileSet(SDFileSet* pSet, SDiskID did, int vid, int fid, uint32_t ver); +void tsdbInitDFileSet(SDFileSet* pSet, SDiskID did, int vid, int fid, uint32_t ver, uint8_t nFiles); void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); void* tsdbDecodeDFileSet(void* buf, SDFileSet* pSet, uint32_t sfver); diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 87acea636a..f3833cf0d4 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -139,7 +139,7 @@ int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn) { if (did.level > TSDB_FSET_LEVEL(pSet)) { // Need to move the FSET to higher level - tsdbInitDFileSet(&nSet, did, REPO_ID(pRepo), pSet->fid, FS_TXN_VERSION(pfs)); + tsdbInitDFileSet(&nSet, did, REPO_ID(pRepo), pSet->fid, FS_TXN_VERSION(pfs), TSDB_FILE_MAX); if (tsdbCopyDFileSet(pSet, &nSet) < 0) { tsdbError("vgId:%d failed to copy FSET %d from level %d to level %d since %s", REPO_ID(pRepo), pSet->fid, @@ -1598,7 +1598,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid // Set and open commit FSET if (pSet == NULL || did.level > TSDB_FSET_LEVEL(pSet)) { // Create a new FSET to write data - tsdbInitDFileSet(pWSet, did, REPO_ID(pRepo), fid, FS_TXN_VERSION(REPO_FS(pRepo))); + tsdbInitDFileSet(pWSet, did, REPO_ID(pRepo), fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_MAX); if (tsdbCreateDFileSet(pWSet, true) < 0) { tsdbError("vgId:%d failed to create FSET %d at level %d disk id %d since %s", REPO_ID(pRepo), diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index 0f6502a4f5..1f827e7cdb 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -197,7 +197,7 @@ static int tsdbCompactMeta(STsdbRepo *pRepo) { } tsdbInitDFileSet(TSDB_COMPACT_WSET(pComph), did, REPO_ID(pRepo), TSDB_FSET_FID(pSet), - FS_TXN_VERSION(REPO_FS(pRepo))); + FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_MAX); if (tsdbCreateDFileSet(TSDB_COMPACT_WSET(pComph), true) < 0) { tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); tsdbCompactFSetEnd(pComph); diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index 7f26f06fff..ee7a704991 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -100,7 +100,8 @@ static int tsdbDecodeDFileSetArray(void **originBuf, void *buf, SArray *pArray, buf = taosDecodeFixedU64(buf, &nset); if (pSFSHeader->version == TSDB_FS_VER_0) { - uint64_t extendedSize = pSFSHeader->len + nset * TSDB_FILE_MAX * sizeof(TSDB_FVER_TYPE); + // record fver in new version of 'current' file + uint64_t extendedSize = pSFSHeader->len + nset * TSDB_FILE_MAX * sizeof(TSDB_FVER_TYPE); if (taosTSizeof(*originBuf) < extendedSize) { size_t ptrDistance = POINTER_DISTANCE(buf, *originBuf); if (tsdbMakeRoom(originBuf, (size_t)extendedSize) < 0) { diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index edbf91d845..626756fc39 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -563,12 +563,12 @@ static int tsdbRollBackDFile(SDFile *pDFile) { } // ============== Operations on SDFileSet -void tsdbInitDFileSet(SDFileSet *pSet, SDiskID did, int vid, int fid, uint32_t ver) { +void tsdbInitDFileSet(SDFileSet *pSet, SDiskID did, int vid, int fid, uint32_t ver, uint8_t nFiles) { pSet->fid = fid; pSet->state = 0; - pSet->nFiles = TSDB_FILE_MAX; + pSet->nFiles = nFiles; - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + for (TSDB_FILE_T ftype = 0; ftype < nFiles; ftype++) { SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype); tsdbInitDFile(pDFile, did, vid, fid, ver, ftype); } @@ -651,7 +651,7 @@ int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to) { } int tsdbCreateDFileSet(SDFileSet *pSet, bool updateHeader) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + for (TSDB_FILE_T ftype = 0; ftype < pSet->nFiles; ftype++) { if (tsdbCreateDFile(TSDB_DFILE_IN_SET(pSet, ftype), updateHeader, ftype) < 0) { tsdbCloseDFileSet(pSet); tsdbRemoveDFileSet(pSet); diff --git a/src/tsdb/src/tsdbSync.c b/src/tsdb/src/tsdbSync.c index edcb84d091..debbabd38c 100644 --- a/src/tsdb/src/tsdbSync.c +++ b/src/tsdb/src/tsdbSync.c @@ -466,7 +466,7 @@ static int32_t tsdbSyncRecvDFileSetArray(SSyncH *pSynch) { return -1; } - tsdbInitDFileSet(&fset, did, REPO_ID(pRepo), pSynch->pdf->fid, FS_TXN_VERSION(pfs)); + tsdbInitDFileSet(&fset, did, REPO_ID(pRepo), pSynch->pdf->fid, FS_TXN_VERSION(pfs), pSynch->pdf->nFiles); // Create new FSET if (tsdbCreateDFileSet(&fset, false) < 0) { @@ -474,7 +474,7 @@ static int32_t tsdbSyncRecvDFileSetArray(SSyncH *pSynch) { return -1; } - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + for (TSDB_FILE_T ftype = 0; ftype < pSynch->pdf->nFiles; ftype++) { SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ftype); // local file SDFile *pRDFile = TSDB_DFILE_IN_SET(pSynch->pdf, ftype); // remote file @@ -550,7 +550,10 @@ static int32_t tsdbSyncRecvDFileSetArray(SSyncH *pSynch) { } static bool tsdbIsTowFSetSame(SDFileSet *pSet1, SDFileSet *pSet2) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + if (pSet1->nFiles != pSet2->nFiles) { + return false; + } + for (TSDB_FILE_T ftype = 0; ftype < pSet1->nFiles; ftype++) { SDFile *pDFile1 = TSDB_DFILE_IN_SET(pSet1, ftype); SDFile *pDFile2 = TSDB_DFILE_IN_SET(pSet2, ftype); @@ -592,7 +595,7 @@ static int32_t tsdbSyncSendDFileSet(SSyncH *pSynch, SDFileSet *pSet) { if (toSend) { tsdbInfo("vgId:%d, fileset:%d will be sent", REPO_ID(pRepo), pSet->fid); - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + for (TSDB_FILE_T ftype = 0; ftype < pSet->nFiles; ftype++) { SDFile df = *TSDB_DFILE_IN_SET(pSet, ftype); if (tsdbOpenDFile(&df, O_RDONLY) < 0) { -- GitLab