[TD-4352]fix tsdb meta compact bug
This commit is contained in:
parent
2d0bca4290
commit
543b17cb84
|
@ -57,7 +57,6 @@ typedef struct {
|
||||||
} SMFile;
|
} SMFile;
|
||||||
|
|
||||||
void tsdbInitMFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver, bool tmp);
|
void tsdbInitMFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver, bool tmp);
|
||||||
void tsdbRenameOrDeleleTempMetaFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver, int code);
|
|
||||||
void tsdbInitMFileEx(SMFile* pMFile, const SMFile* pOMFile);
|
void tsdbInitMFileEx(SMFile* pMFile, const SMFile* pOMFile);
|
||||||
int tsdbEncodeSMFile(void** buf, SMFile* pMFile);
|
int tsdbEncodeSMFile(void** buf, SMFile* pMFile);
|
||||||
void* tsdbDecodeSMFile(void* buf, SMFile* pMFile);
|
void* tsdbDecodeSMFile(void* buf, SMFile* pMFile);
|
||||||
|
|
|
@ -460,6 +460,11 @@ static int tsdbCompactMetaFile(STsdbRepo *pRepo, STsdbFS *pfs, SMFile *pMFile) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tsdbOpenMFile(pMFile, O_RDONLY) < 0) {
|
||||||
|
tsdbError("open meta file %s compact fail", pMFile->f.rname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tsdbInfo("begin compact tsdb meta file, nDels:%" PRId64 ",nRecords:%" PRId64 ",tombSize:%" PRId64 ",size:%" PRId64,
|
tsdbInfo("begin compact tsdb meta file, nDels:%" PRId64 ",nRecords:%" PRId64 ",tombSize:%" PRId64 ",size:%" PRId64,
|
||||||
pMFile->info.nDels,pMFile->info.nRecords,pMFile->info.tombSize,pMFile->info.size);
|
pMFile->info.nDels,pMFile->info.nRecords,pMFile->info.tombSize,pMFile->info.size);
|
||||||
|
|
||||||
|
@ -530,10 +535,19 @@ static int tsdbCompactMetaFile(STsdbRepo *pRepo, STsdbFS *pfs, SMFile *pMFile) {
|
||||||
_err:
|
_err:
|
||||||
TSDB_FILE_FSYNC(&mf);
|
TSDB_FILE_FSYNC(&mf);
|
||||||
tsdbCloseMFile(&mf);
|
tsdbCloseMFile(&mf);
|
||||||
|
tsdbCloseMFile(pMFile);
|
||||||
|
|
||||||
tsdbRenameOrDeleleTempMetaFile(&mf, did, REPO_ID(pRepo), FS_TXN_VERSION(REPO_FS(pRepo)), code);
|
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
|
// rename meta.tmp -> meta
|
||||||
|
taosRename(mf.f.aname,pMFile->f.aname);
|
||||||
|
tstrncpy(mf.f.aname, pMFile->f.aname, TSDB_FILENAME_LEN);
|
||||||
|
tstrncpy(mf.f.rname, pMFile->f.rname, TSDB_FILENAME_LEN);
|
||||||
|
// update current meta file info
|
||||||
|
pfs->nstatus->pmf = NULL;
|
||||||
tsdbUpdateMFile(pfs, &mf);
|
tsdbUpdateMFile(pfs, &mf);
|
||||||
|
} else {
|
||||||
|
// remove meta.tmp file
|
||||||
|
remove(mf.f.aname);
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(pBuf);
|
tfree(pBuf);
|
||||||
|
|
|
@ -20,8 +20,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
|
||||||
"data", // TSDB_FILE_DATA
|
"data", // TSDB_FILE_DATA
|
||||||
"last", // TSDB_FILE_LAST
|
"last", // TSDB_FILE_LAST
|
||||||
"", // TSDB_FILE_MAX
|
"", // TSDB_FILE_MAX
|
||||||
"meta" // TSDB_FILE_META
|
"meta", // TSDB_FILE_META
|
||||||
"meta.tmp" // TSDB_FILE_META_TMP
|
"meta.tmp", // TSDB_FILE_META_TMP
|
||||||
};
|
};
|
||||||
|
|
||||||
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
||||||
|
@ -43,22 +43,6 @@ void tsdbInitMFile(SMFile *pMFile, SDiskID did, int vid, uint32_t ver, bool tmp)
|
||||||
tfsInitFile(TSDB_FILE_F(pMFile), did.level, did.id, fname);
|
tfsInitFile(TSDB_FILE_F(pMFile), did.level, did.id, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbRenameOrDeleleTempMetaFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver, int code) {
|
|
||||||
char mfname[TSDB_FILENAME_LEN] = {'\0'};
|
|
||||||
char tfname[TSDB_FILENAME_LEN] = {'\0'};
|
|
||||||
|
|
||||||
tsdbGetFilename(vid, 0, ver, TSDB_FILE_META_TMP, tfname);
|
|
||||||
|
|
||||||
if (code != 0) {
|
|
||||||
remove(tfname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tsdbGetFilename(vid, 0, ver, TSDB_FILE_META, mfname);
|
|
||||||
|
|
||||||
(void)taosRename(tfname, mfname);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tsdbInitMFileEx(SMFile *pMFile, const SMFile *pOMFile) {
|
void tsdbInitMFileEx(SMFile *pMFile, const SMFile *pOMFile) {
|
||||||
*pMFile = *pOMFile;
|
*pMFile = *pOMFile;
|
||||||
TSDB_FILE_SET_CLOSED(pMFile);
|
TSDB_FILE_SET_CLOSED(pMFile);
|
||||||
|
|
Loading…
Reference in New Issue