enh: unify handling of vnode primary dir for vnd and tsdb
This commit is contained in:
parent
4c3bf41178
commit
05e8af4837
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "tsdb.h"
|
||||
#include "vnd.h"
|
||||
|
||||
#define ROCKS_BATCH_SIZE (4096)
|
||||
|
||||
|
@ -58,16 +59,10 @@ typedef struct {
|
|||
|
||||
static void tsdbGetRocksPath(STsdb *pTsdb, char *path) {
|
||||
SVnode *pVnode = pTsdb->pVnode;
|
||||
if (pVnode->pTfs) {
|
||||
if (path) {
|
||||
snprintf(path, TSDB_FILENAME_LEN, "%s%s%s%scache.rdb", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
|
||||
pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
} else {
|
||||
if (path) {
|
||||
snprintf(path, TSDB_FILENAME_LEN, "%s%scache.rdb", pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
}
|
||||
vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, path, TSDB_FILENAME_LEN);
|
||||
|
||||
int32_t offset = strlen(path);
|
||||
snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP);
|
||||
}
|
||||
|
||||
static const char *myCmpName(void *state) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "vnd.h"
|
||||
|
||||
// =================================================================================================
|
||||
static int32_t tsdbFSToBinary(uint8_t *p, STsdbFS *pFS) {
|
||||
|
@ -271,22 +272,20 @@ int32_t tDFileSetCmprFn(const void *p1, const void *p2) {
|
|||
|
||||
static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) {
|
||||
SVnode *pVnode = pTsdb->pVnode;
|
||||
if (pVnode->pTfs) {
|
||||
if (current) {
|
||||
snprintf(current, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
|
||||
pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
if (current_t) {
|
||||
snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
|
||||
pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
} else {
|
||||
if (current) {
|
||||
snprintf(current, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
if (current_t) {
|
||||
snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%sCURRENT.t", pTsdb->path, TD_DIRSEP);
|
||||
}
|
||||
int32_t offset = 0;
|
||||
|
||||
// CURRENT
|
||||
if (current) {
|
||||
vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current, TSDB_FILENAME_LEN);
|
||||
offset = strlen(current);
|
||||
snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP);
|
||||
}
|
||||
|
||||
// CURRENT.t
|
||||
if (current_t) {
|
||||
vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN);
|
||||
offset = strlen(current_t);
|
||||
snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1142,4 +1141,4 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
|||
}
|
||||
|
||||
taosArrayDestroy(pFS->aDFileSet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "vnd.h"
|
||||
|
||||
int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile) {
|
||||
int32_t n = 0;
|
||||
|
@ -282,8 +283,12 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
|||
|
||||
// SDelFile ===============================================
|
||||
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) {
|
||||
snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%dver%" PRId64 "%s", tfsGetPrimaryPath(pTsdb->pVnode->pTfs),
|
||||
TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pFile->commitID, ".del");
|
||||
int32_t offset = 0;
|
||||
|
||||
vnodeGetAbsDir(pTsdb->path, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN);
|
||||
offset = strlen(fname);
|
||||
snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP,
|
||||
TD_VID(pTsdb->pVnode), pFile->commitID);
|
||||
}
|
||||
|
||||
int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile) {
|
||||
|
|
|
@ -290,11 +290,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
|||
pInfo->txn = metaGetTxn(pVnode->pMeta);
|
||||
|
||||
// save info
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
vDebug("vgId:%d, save config while prepare commit", TD_VID(pVnode));
|
||||
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
||||
|
@ -427,11 +423,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed);
|
||||
|
||||
|
@ -493,16 +485,22 @@ _exit:
|
|||
|
||||
bool vnodeShouldRollback(SVnode *pVnode) {
|
||||
char tFName[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP,
|
||||
VND_INFO_FNAME_TMP);
|
||||
int32_t offset = 0;
|
||||
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN);
|
||||
offset = strlen(tFName);
|
||||
snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP);
|
||||
|
||||
return taosCheckExistFile(tFName);
|
||||
}
|
||||
|
||||
void vnodeRollback(SVnode *pVnode) {
|
||||
char tFName[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP,
|
||||
VND_INFO_FNAME_TMP);
|
||||
int32_t offset = 0;
|
||||
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN);
|
||||
offset = strlen(tFName);
|
||||
snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP);
|
||||
|
||||
(void)taosRemoveFile(tFName);
|
||||
}
|
||||
|
|
|
@ -291,11 +291,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
|
|||
char tdir[TSDB_FILENAME_LEN * 2] = {0};
|
||||
int32_t ret = 0;
|
||||
|
||||
if (pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", path);
|
||||
}
|
||||
vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
info.config = vnodeCfgDefault;
|
||||
|
||||
|
|
|
@ -35,11 +35,7 @@ static int32_t vnodePrepareRentention(SVnode *pVnode, SRetentionInfo *pInfo) {
|
|||
pInfo->commitID = ++pVnode->state.commitID;
|
||||
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
if (vnodeLoadInfo(dir, &pInfo->info) < 0) {
|
||||
code = terrno;
|
||||
|
@ -64,11 +60,7 @@ static int32_t vnodeRetentionTask(void *param) {
|
|||
SVnode *pVnode = pInfo->pVnode;
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
// save info
|
||||
pInfo->info.state.commitID = pInfo->commitID;
|
||||
|
@ -127,4 +119,4 @@ _exit:
|
|||
vInfo("vgId:%d %s done", TD_VID(pInfo->pVnode), __func__);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,12 +91,11 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
|||
// FIXME: if commit multiple times and the config changed?
|
||||
if (!pReader->cfgDone) {
|
||||
char fName[TSDB_FILENAME_LEN];
|
||||
if (pReader->pVnode->pTfs) {
|
||||
snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pReader->pVnode->pTfs), TD_DIRSEP,
|
||||
pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME);
|
||||
} else {
|
||||
snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s", pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME);
|
||||
}
|
||||
int32_t offset = 0;
|
||||
|
||||
vnodeGetAbsDir(pReader->pVnode->path, pReader->pVnode->pTfs, fName, TSDB_FILENAME_LEN);
|
||||
offset = strlen(fName);
|
||||
snprintf(fName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ);
|
||||
if (NULL == pFile) {
|
||||
|
@ -344,11 +343,7 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
|
|||
.applyTerm = pWriter->info.state.commitTerm};
|
||||
pVnode->statis = pWriter->info.statis;
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
if (pWriter->pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
vnodeCommitInfo(dir);
|
||||
} else {
|
||||
|
@ -400,12 +395,7 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_
|
|||
|
||||
// modify info as needed
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
if (pWriter->pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pWriter->pVnode->pTfs), TD_DIRSEP,
|
||||
pWriter->pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
|
||||
}
|
||||
vnodeGetAbsDir(pWriter->pVnode->path, pWriter->pVnode->pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
SVnodeStats vndStats = pWriter->info.config.vndStats;
|
||||
SVnode *pVnode = pWriter->pVnode;
|
||||
|
|
Loading…
Reference in New Issue