TDengine/source/dnode/vnode/src/tsdb/tsdbFile.c

458 lines
13 KiB
C
Raw Normal View History

2020-03-05 06:13:20 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2020-06-12 10:52:48 +00:00
2022-04-26 11:04:26 +00:00
#include "tsdb.h"
2020-06-16 09:12:21 +00:00
2021-01-09 08:30:59 +00:00
static const char *TSDB_FNAME_SUFFIX[] = {
2022-01-07 08:21:28 +00:00
"head", // TSDB_FILE_HEAD
"data", // TSDB_FILE_DATA
"last", // TSDB_FILE_LAST
"smad", // TSDB_FILE_SMAD
"smal", // TSDB_FILE_SMAL
2022-01-07 08:21:28 +00:00
"", // TSDB_FILE_MAX
"meta", // TSDB_FILE_META
2022-03-16 11:01:45 +00:00
"tsma", // TSDB_FILE_TSMA
"rsma", // TSDB_FILE_RSMA
2021-01-09 08:30:59 +00:00
};
2020-06-12 10:52:48 +00:00
2022-05-02 10:16:43 +00:00
const char *TSDB_LEVEL_DNAME[] = {
2022-05-01 16:30:47 +00:00
"tsdb",
"rsma1",
"rsma2",
};
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char* dname, char *fname);
2022-01-07 08:21:28 +00:00
// static int tsdbRollBackMFile(SMFile *pMFile);
2021-01-14 15:03:57 +00:00
static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo);
static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo);
static int tsdbRollBackDFile(SDFile *pDFile);
2021-01-04 12:07:54 +00:00
// ============== Operations on SDFile
2022-01-19 06:04:01 +00:00
void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype) {
2021-01-09 08:30:59 +00:00
char fname[TSDB_FILENAME_LEN];
2021-02-02 08:12:26 +00:00
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_OK);
2021-01-04 12:07:54 +00:00
TSDB_FILE_SET_CLOSED(pDFile);
2021-01-09 08:30:59 +00:00
2021-01-12 10:07:36 +00:00
memset(&(pDFile->info), 0, sizeof(pDFile->info));
pDFile->info.magic = TSDB_FILE_INIT_MAGIC;
pDFile->info.fver = tsdbGetDFSVersion(ftype);
2021-01-09 08:30:59 +00:00
2022-05-02 01:37:24 +00:00
tsdbGetFilename(REPO_ID(pRepo), fid, ver, ftype, TSDB_LEVEL_DNAME[pRepo->level], fname);
2022-04-16 12:07:28 +00:00
tfsInitFile(REPO_TFS(pRepo), &(pDFile->f), did, fname);
2020-11-24 16:06:39 +00:00
}
2021-01-12 10:07:36 +00:00
void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile) {
*pDFile = *pODFile;
2021-01-05 11:33:23 +00:00
TSDB_FILE_SET_CLOSED(pDFile);
}
2021-01-09 08:30:59 +00:00
int tsdbEncodeSDFile(void **buf, SDFile *pDFile) {
2021-01-04 12:07:54 +00:00
int tlen = 0;
2021-01-04 12:07:54 +00:00
tlen += tsdbEncodeDFInfo(buf, &(pDFile->info));
tlen += tfsEncodeFile(buf, &(pDFile->f));
2020-03-24 09:48:29 +00:00
2021-01-04 12:07:54 +00:00
return tlen;
2020-03-26 15:26:48 +00:00
}
2022-01-19 06:04:01 +00:00
void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile) {
2021-01-04 12:07:54 +00:00
buf = tsdbDecodeDFInfo(buf, &(pDFile->info));
2022-04-16 12:07:28 +00:00
buf = tfsDecodeFile(REPO_TFS(pRepo), buf, &(pDFile->f));
2021-01-15 06:26:59 +00:00
TSDB_FILE_SET_CLOSED(pDFile);
2020-06-17 04:06:17 +00:00
2021-01-04 12:07:54 +00:00
return buf;
2020-06-17 04:06:17 +00:00
}
2020-06-17 02:45:36 +00:00
2021-01-19 09:21:05 +00:00
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 = NULL;
2021-01-19 09:21:05 +00:00
buf = tsdbDecodeDFInfo(buf, &(pDFile->info));
buf = taosDecodeString(buf, &aname);
strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN);
TSDB_FILE_SET_CLOSED(pDFile);
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(aname);
2021-01-19 09:21:05 +00:00
return buf;
}
int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) {
2021-01-12 10:07:36 +00:00
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
2022-04-11 10:55:43 +00:00
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pDFile->pFile == NULL) {
2021-01-25 10:52:49 +00:00
if (errno == ENOENT) {
// Try to create directory recursively
2022-01-19 06:40:28 +00:00
char *s = strdup(TSDB_FILE_REL_NAME(pDFile));
2022-04-16 12:07:28 +00:00
if (tfsMkdirRecurAt(REPO_TFS(pRepo), taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) {
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(s);
2021-01-25 10:52:49 +00:00
return -1;
}
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(s);
2021-01-25 10:52:49 +00:00
2022-04-11 10:55:43 +00:00
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pDFile->pFile == NULL) {
2021-01-25 10:52:49 +00:00
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
} else {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
2021-01-12 10:07:36 +00:00
}
2021-01-18 10:25:15 +00:00
if (!updateHeader) {
return 0;
}
2021-03-26 09:00:57 +00:00
pDFile->info.size += TSDB_FILE_HEAD_SIZE;
pDFile->info.fver = tsdbGetDFSVersion(fType);
2021-03-26 09:00:57 +00:00
2021-01-25 07:24:41 +00:00
if (tsdbUpdateDFileHeader(pDFile) < 0) {
2021-01-12 10:07:36 +00:00
tsdbCloseDFile(pDFile);
tsdbRemoveDFile(pDFile);
return -1;
}
2021-01-11 09:41:53 +00:00
return 0;
}
2021-01-12 10:07:36 +00:00
int tsdbUpdateDFileHeader(SDFile *pDFile) {
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
if (tsdbSeekDFile(pDFile, 0, SEEK_SET) < 0) {
return -1;
}
2021-01-10 11:41:47 +00:00
2021-01-12 10:07:36 +00:00
void *ptr = buf;
2022-04-09 10:21:03 +00:00
// taosEncodeFixedU32(&ptr, 0); // fver moved to SDFInfo and saved to current
2021-01-12 10:07:36 +00:00
tsdbEncodeDFInfo(&ptr, &(pDFile->info));
2021-01-10 11:41:47 +00:00
2021-01-29 03:49:38 +00:00
taosCalcChecksumAppend(0, (uint8_t *)buf, TSDB_FILE_HEAD_SIZE);
2021-01-12 10:07:36 +00:00
if (tsdbWriteDFile(pDFile, buf, TSDB_FILE_HEAD_SIZE) < 0) {
2021-01-10 11:41:47 +00:00
return -1;
}
2021-01-12 10:07:36 +00:00
return 0;
2021-01-10 11:41:47 +00:00
}
2021-01-25 07:12:54 +00:00
int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) {
2021-01-25 07:24:41 +00:00
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
uint32_t _version;
2021-01-25 07:12:54 +00:00
ASSERT(TSDB_FILE_OPENED(pDFile));
if (tsdbSeekDFile(pDFile, 0, SEEK_SET) < 0) {
return -1;
}
if (tsdbReadDFile(pDFile, buf, TSDB_FILE_HEAD_SIZE) < 0) {
return -1;
}
2021-01-29 03:49:38 +00:00
if (!taosCheckChecksumWhole((uint8_t *)buf, TSDB_FILE_HEAD_SIZE)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
return -1;
}
2021-01-25 07:24:41 +00:00
void *pBuf = buf;
2022-04-09 10:21:03 +00:00
// pBuf = taosDecodeFixedU32(pBuf, &_version);
2021-01-26 02:49:01 +00:00
pBuf = tsdbDecodeDFInfo(pBuf, pInfo);
2021-01-25 07:12:54 +00:00
return 0;
}
2022-01-07 08:21:28 +00:00
static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
2022-04-16 12:07:28 +00:00
SDFile df;
2021-01-29 03:49:38 +00:00
tsdbInitDFileEx(&df, pDFile);
2021-01-17 05:00:04 +00:00
if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pDFile))) {
2021-01-25 10:15:34 +00:00
tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pDFile));
2022-01-07 08:21:28 +00:00
// pRepo->state |= TSDB_STATE_BAD_DATA;
2021-02-02 08:12:26 +00:00
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
2021-01-25 10:15:34 +00:00
return 0;
}
int64_t file_size = 0;
if (taosStatFile(TSDB_FILE_FULL_NAME(&df), &file_size, NULL) < 0) {
2021-01-17 05:00:04 +00:00
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (pDFile->info.size < file_size) {
// if (tsdbOpenDFile(&df, O_WRONLY) < 0) {
if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) {
2021-01-17 05:00:04 +00:00
return -1;
}
if (taosFtruncateFile(df.pFile, df.info.size) < 0) {
2021-01-17 05:00:04 +00:00
terrno = TAOS_SYSTEM_ERROR(errno);
tsdbCloseDFile(&df);
return -1;
}
if (tsdbUpdateDFileHeader(&df) < 0) {
tsdbCloseDFile(&df);
return -1;
}
tsdbCloseDFile(&df);
2021-01-25 10:15:34 +00:00
tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
file_size, pDFile->info.size);
} else if (pDFile->info.size > file_size) {
2021-01-25 10:15:34 +00:00
tsdbError("vgId:%d data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), file_size, pDFile->info.size);
2022-01-07 08:21:28 +00:00
// pRepo->state |= TSDB_STATE_BAD_DATA;
2021-02-02 08:12:26 +00:00
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
2021-01-17 05:00:04 +00:00
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
2021-01-25 10:15:34 +00:00
return 0;
2021-01-29 03:49:38 +00:00
} else {
tsdbDebug("vgId:%d file %s passes the scan", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
2021-01-17 05:00:04 +00:00
}
return 0;
}
2021-01-04 12:07:54 +00:00
static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo) {
2020-06-17 09:39:05 +00:00
int tlen = 0;
2021-01-04 12:07:54 +00:00
2020-07-17 09:32:56 +00:00
tlen += taosEncodeFixedU32(buf, pInfo->magic);
tlen += taosEncodeFixedU32(buf, pInfo->fver);
2020-06-17 09:39:05 +00:00
tlen += taosEncodeFixedU32(buf, pInfo->len);
tlen += taosEncodeFixedU32(buf, pInfo->totalBlocks);
tlen += taosEncodeFixedU32(buf, pInfo->totalSubBlocks);
2020-07-20 08:14:55 +00:00
tlen += taosEncodeFixedU32(buf, pInfo->offset);
tlen += taosEncodeFixedU64(buf, pInfo->size);
tlen += taosEncodeFixedU64(buf, pInfo->tombSize);
2020-06-17 06:28:10 +00:00
2020-06-17 09:39:05 +00:00
return tlen;
2020-06-17 06:28:10 +00:00
}
2021-01-04 12:07:54 +00:00
static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) {
2020-07-17 09:32:56 +00:00
buf = taosDecodeFixedU32(buf, &(pInfo->magic));
buf = taosDecodeFixedU32(buf, &(pInfo->fver));
2020-06-17 06:28:10 +00:00
buf = taosDecodeFixedU32(buf, &(pInfo->len));
buf = taosDecodeFixedU32(buf, &(pInfo->totalBlocks));
buf = taosDecodeFixedU32(buf, &(pInfo->totalSubBlocks));
2020-07-20 08:14:55 +00:00
buf = taosDecodeFixedU32(buf, &(pInfo->offset));
buf = taosDecodeFixedU64(buf, &(pInfo->size));
buf = taosDecodeFixedU64(buf, &(pInfo->tombSize));
2020-06-17 06:28:10 +00:00
return buf;
}
2021-01-14 08:27:54 +00:00
static int tsdbApplyDFileChange(SDFile *from, SDFile *to) {
ASSERT(from != NULL || to != NULL);
if (from != NULL) {
if (to == NULL) {
tsdbRemoveDFile(from);
} else {
if (tfsIsSameFile(TSDB_FILE_F(from), TSDB_FILE_F(to))) {
if (from->info.size > to->info.size) {
2021-01-14 15:03:57 +00:00
tsdbRollBackDFile(to);
2021-01-14 08:27:54 +00:00
}
} else {
(void)tsdbRemoveDFile(from);
2021-01-14 08:27:54 +00:00
}
}
}
return 0;
}
2021-01-14 15:03:57 +00:00
static int tsdbRollBackDFile(SDFile *pDFile) {
2021-01-14 08:27:54 +00:00
SDFile df = *pDFile;
// if (tsdbOpenDFile(&df, O_WRONLY) < 0) {
if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) {
2021-01-14 08:27:54 +00:00
return -1;
}
if (taosFtruncateFile(TSDB_FILE_PFILE(&df), pDFile->info.size) < 0) {
2021-01-14 08:27:54 +00:00
terrno = TAOS_SYSTEM_ERROR(errno);
tsdbCloseDFile(&df);
return -1;
}
if (tsdbUpdateDFileHeader(&df) < 0) {
tsdbCloseDFile(&df);
return -1;
}
2021-01-15 06:26:59 +00:00
TSDB_FILE_FSYNC(&df);
2021-01-14 08:27:54 +00:00
tsdbCloseDFile(&df);
return 0;
}
2021-01-04 12:07:54 +00:00
// ============== Operations on SDFileSet
2022-01-19 06:04:01 +00:00
void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver) {
TSDB_FSET_FID(pSet) = fid;
TSDB_FSET_VER(pSet) = TSDB_LATEST_FSET_VER;
TSDB_FSET_STATE(pSet) = 0;
pSet->reserve = 0;
2020-11-25 09:11:04 +00:00
2021-01-04 12:07:54 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype);
2022-01-19 06:40:28 +00:00
tsdbInitDFile(pRepo, pDFile, did, fid, ver, ftype);
2021-01-06 10:21:26 +00:00
}
}
2021-01-12 10:07:36 +00:00
void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet) {
TSDB_FSET_FID(pSet) = TSDB_FSET_FID(pOSet);
2021-01-06 10:21:26 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
2021-01-12 10:07:36 +00:00
tsdbInitDFileEx(TSDB_DFILE_IN_SET(pSet, ftype), TSDB_DFILE_IN_SET(pOSet, ftype));
2020-11-25 09:11:04 +00:00
}
2020-11-25 14:20:07 +00:00
}
2021-01-12 10:07:36 +00:00
int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet) {
int tlen = 0;
2020-11-25 14:20:07 +00:00
tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet));
// state not included
tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet));
tlen += taosEncodeFixedU16(buf, pSet->reserve);
2021-01-12 10:07:36 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
tlen += tsdbEncodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype));
2020-11-25 14:20:07 +00:00
}
2021-01-12 10:07:36 +00:00
2021-01-14 15:03:57 +00:00
return tlen;
2020-11-25 14:20:07 +00:00
}
2022-01-19 06:04:01 +00:00
void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet) {
buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet)));
TSDB_FSET_STATE(pSet) = 0;
buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet)));
buf = taosDecodeFixedU16(buf, &(pSet->reserve));
2021-01-17 11:59:01 +00:00
2021-01-04 12:07:54 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
2022-01-19 06:40:28 +00:00
buf = tsdbDecodeSDFile(pRepo, buf, TSDB_DFILE_IN_SET(pSet, ftype));
2020-11-26 03:47:11 +00:00
}
2021-01-12 10:07:36 +00:00
return buf;
2020-11-25 14:20:07 +00:00
}
2021-01-19 09:21:05 +00:00
int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) {
int tlen = 0;
tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet));
tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet));
tlen += taosEncodeFixedU16(buf, pSet->reserve);
2021-01-19 09:21:05 +00:00
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) {
buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet)));
buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet)));
buf = taosDecodeFixedU16(buf, &(pSet->reserve));
2021-01-19 09:21:05 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
buf = tsdbDecodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype));
}
return buf;
}
2021-01-14 15:03:57 +00:00
int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to) {
2021-01-14 08:27:54 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
2021-01-16 17:34:21 +00:00
SDFile *pDFileFrom = (from) ? TSDB_DFILE_IN_SET(from, ftype) : NULL;
SDFile *pDFileTo = (to) ? TSDB_DFILE_IN_SET(to, ftype) : NULL;
if (tsdbApplyDFileChange(pDFileFrom, pDFileTo) < 0) {
2021-01-14 08:27:54 +00:00
return -1;
}
}
return 0;
}
2022-01-19 06:40:28 +00:00
int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader) {
2021-01-12 10:07:36 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
if (tsdbCreateDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype), updateHeader, ftype) < 0) {
2021-01-12 10:07:36 +00:00
tsdbCloseDFileSet(pSet);
tsdbRemoveDFileSet(pSet);
return -1;
}
}
2020-11-26 03:47:11 +00:00
return 0;
}
2020-11-25 14:20:07 +00:00
2021-01-12 10:07:36 +00:00
int tsdbUpdateDFileSetHeader(SDFileSet *pSet) {
2021-01-10 11:41:47 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
2021-01-12 10:07:36 +00:00
if (tsdbUpdateDFileHeader(TSDB_DFILE_IN_SET(pSet, ftype)) < 0) {
2021-01-10 11:41:47 +00:00
return -1;
}
}
2021-01-14 15:03:57 +00:00
return 0;
2021-01-09 08:30:59 +00:00
}
2022-01-07 08:21:28 +00:00
int tsdbScanAndTryFixDFileSet(STsdb *pRepo, SDFileSet *pSet) {
2021-01-17 05:00:04 +00:00
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
2021-01-25 10:15:34 +00:00
if (tsdbScanAndTryFixDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype)) < 0) {
2021-01-17 05:00:04 +00:00
return -1;
}
}
return 0;
}
int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype, uint32_t *_version) {
2021-01-25 07:12:54 +00:00
char *p = NULL;
*_version = 0;
2021-01-25 07:12:54 +00:00
*ftype = TSDB_FILE_MAX;
sscanf(fname, "v%df%d.%m[a-z]-ver%" PRIu32, vid, fid, &p, _version);
2021-01-25 07:12:54 +00:00
for (TSDB_FILE_T i = 0; i < TSDB_FILE_MAX; i++) {
if (strcmp(p, TSDB_FNAME_SUFFIX[i]) == 0) {
*ftype = i;
break;
}
}
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(p);
2021-01-25 07:12:54 +00:00
return 0;
}
2022-05-01 16:30:47 +00:00
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname) {
2021-01-09 08:30:59 +00:00
ASSERT(ftype != TSDB_FILE_MAX);
if (ftype < TSDB_FILE_MAX) {
if (ver == 0) {
2022-05-01 16:30:47 +00:00
snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/data/v%df%d.%s", vid, dname, vid, fid,
TSDB_FNAME_SUFFIX[ftype]);
2021-01-09 08:30:59 +00:00
} else {
2022-05-01 16:30:47 +00:00
snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/data/v%df%d.%s-ver%" PRIu32, vid, dname, vid, fid,
2021-01-15 06:26:59 +00:00
TSDB_FNAME_SUFFIX[ftype], ver);
2021-01-09 08:30:59 +00:00
}
} else {
if (ver == 0) {
2021-01-14 15:03:57 +00:00
snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s", vid, TSDB_FNAME_SUFFIX[ftype]);
2021-01-09 08:30:59 +00:00
} else {
2021-01-15 06:26:59 +00:00
snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s-ver%" PRIu32, vid, TSDB_FNAME_SUFFIX[ftype], ver);
2021-01-09 08:30:59 +00:00
}
}
2020-11-23 08:59:06 +00:00
}