wal/mgmg: use new return macros for wal mgmt
This commit is contained in:
parent
180411434a
commit
6ce5320750
|
@ -205,7 +205,6 @@ int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tEncoderInit(&encoder, buf, vlen);
|
tEncoderInit(&encoder, buf, vlen);
|
||||||
|
|
||||||
code = tEncodeSTqHandle(&encoder, pHandle);
|
code = tEncodeSTqHandle(&encoder, pHandle);
|
||||||
|
@ -266,7 +265,8 @@ static int buildHandle(STQ* pTq, STqHandle* handle){
|
||||||
if (handle->pRef == NULL) {
|
if (handle->pRef == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
walSetRefVer(handle->pRef, handle->snapshotVer);
|
|
||||||
|
TAOS_CHECK_RETURN(walSetRefVer(handle->pRef, handle->snapshotVer));
|
||||||
|
|
||||||
SReadHandle reader = {
|
SReadHandle reader = {
|
||||||
.vnode = pVnode,
|
.vnode = pVnode,
|
||||||
|
@ -278,8 +278,8 @@ static int buildHandle(STQ* pTq, STqHandle* handle){
|
||||||
initStorageAPI(&reader.api);
|
initStorageAPI(&reader.api);
|
||||||
|
|
||||||
if (handle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
if (handle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||||
handle->execHandle.task =
|
handle->execHandle.task = qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId,
|
||||||
qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId, &handle->execHandle.numOfCols, handle->consumerId);
|
&handle->execHandle.numOfCols, handle->consumerId);
|
||||||
if (handle->execHandle.task == NULL) {
|
if (handle->execHandle.task == NULL) {
|
||||||
tqError("cannot create exec task for %s", handle->subKey);
|
tqError("cannot create exec task for %s", handle->subKey);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -316,13 +316,15 @@ static int buildHandle(STQ* pTq, STqHandle* handle){
|
||||||
handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId);
|
handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId);
|
||||||
|
|
||||||
SArray* tbUidList = NULL;
|
SArray* tbUidList = NULL;
|
||||||
int ret = qGetTableList(handle->execHandle.execTb.suid, pVnode, handle->execHandle.execTb.node, &tbUidList, handle->execHandle.task);
|
int ret = qGetTableList(handle->execHandle.execTb.suid, pVnode, handle->execHandle.execTb.node, &tbUidList,
|
||||||
|
handle->execHandle.task);
|
||||||
if (ret != TDB_CODE_SUCCESS) {
|
if (ret != TDB_CODE_SUCCESS) {
|
||||||
tqError("qGetTableList error:%d handle %s consumer:0x%" PRIx64, ret, handle->subKey, handle->consumerId);
|
tqError("qGetTableList error:%d handle %s consumer:0x%" PRIx64, ret, handle->subKey, handle->consumerId);
|
||||||
taosArrayDestroy(tbUidList);
|
taosArrayDestroy(tbUidList);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tqInfo("vgId:%d, tq try to get ctb for stb subscribe, suid:%" PRId64, pVnode->config.vgId, handle->execHandle.execTb.suid);
|
tqInfo("vgId:%d, tq try to get ctb for stb subscribe, suid:%" PRId64, pVnode->config.vgId,
|
||||||
|
handle->execHandle.execTb.suid);
|
||||||
handle->execHandle.pTqReader = tqReaderOpen(pVnode);
|
handle->execHandle.pTqReader = tqReaderOpen(pVnode);
|
||||||
tqReaderSetTbUidList(handle->execHandle.pTqReader, tbUidList, NULL);
|
tqReaderSetTbUidList(handle->execHandle.pTqReader, tbUidList, NULL);
|
||||||
taosArrayDestroy(tbUidList);
|
taosArrayDestroy(tbUidList);
|
||||||
|
@ -370,7 +372,8 @@ int32_t tqCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle){
|
||||||
if (buildHandle(pTq, handle) < 0) {
|
if (buildHandle(pTq, handle) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tqInfo("tqCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey, handle->consumerId, vgId, handle->snapshotVer);
|
tqInfo("tqCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey, handle->consumerId,
|
||||||
|
vgId, handle->snapshotVer);
|
||||||
return taosHashPut(pTq->pHandle, handle->subKey, strlen(handle->subKey), handle, sizeof(STqHandle));
|
return taosHashPut(pTq->pHandle, handle->subKey, strlen(handle->subKey), handle, sizeof(STqHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +445,6 @@ int32_t tqMetaTransform(STQ* pTq) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (tdbOpen(pTq->path, 16 * 1024, 1, &pMetaDB, 0, 0, NULL) < 0) {
|
if (tdbOpen(pTq->path, 16 * 1024, 1, &pMetaDB, 0, 0, NULL) < 0) {
|
||||||
code = -1;
|
code = -1;
|
||||||
goto END;
|
goto END;
|
||||||
|
|
|
@ -873,6 +873,7 @@ static void walUpdateSyncedOffset(SWal* pWal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int walSaveMeta(SWal* pWal) {
|
int walSaveMeta(SWal* pWal) {
|
||||||
|
int code = 0;
|
||||||
int metaVer = walFindCurMetaVer(pWal);
|
int metaVer = walFindCurMetaVer(pWal);
|
||||||
char fnameStr[WAL_FILE_LEN];
|
char fnameStr[WAL_FILE_LEN];
|
||||||
char tmpFnameStr[WAL_FILE_LEN];
|
char tmpFnameStr[WAL_FILE_LEN];
|
||||||
|
@ -881,14 +882,14 @@ int walSaveMeta(SWal* pWal) {
|
||||||
// fsync the idx and log file at first to ensure validity of meta
|
// fsync the idx and log file at first to ensure validity of meta
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pWal->pIdxFile) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pWal->pIdxFile) < 0) {
|
||||||
wError("vgId:%d, failed to sync idx file due to %s", pWal->cfg.vgId, strerror(errno));
|
wError("vgId:%d, failed to sync idx file due to %s", pWal->cfg.vgId, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return -1;
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pWal->pLogFile) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pWal->pLogFile) < 0) {
|
||||||
wError("vgId:%d, failed to sync log file due to %s", pWal->cfg.vgId, strerror(errno));
|
wError("vgId:%d, failed to sync log file due to %s", pWal->cfg.vgId, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return -1;
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
// update synced offset
|
// update synced offset
|
||||||
|
@ -897,46 +898,47 @@ int walSaveMeta(SWal* pWal) {
|
||||||
// flush to a tmpfile
|
// flush to a tmpfile
|
||||||
n = walBuildTmpMetaName(pWal, tmpFnameStr);
|
n = walBuildTmpMetaName(pWal, tmpFnameStr);
|
||||||
if (n >= sizeof(tmpFnameStr)) {
|
if (n >= sizeof(tmpFnameStr)) {
|
||||||
return -1;
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr pMetaFile =
|
TdFilePtr pMetaFile =
|
||||||
taosOpenFile(tmpFnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
taosOpenFile(tmpFnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pMetaFile == NULL) {
|
if (pMetaFile == NULL) {
|
||||||
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return -1;
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
char* serialized = walMetaSerialize(pWal);
|
char* serialized = walMetaSerialize(pWal);
|
||||||
int len = strlen(serialized);
|
int len = strlen(serialized);
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) {
|
||||||
wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) {
|
||||||
wError("vgId:%d, failed to sync file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to sync file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCloseFile(&pMetaFile) < 0) {
|
if (taosCloseFile(&pMetaFile) < 0) {
|
||||||
wError("vgId:%d, failed to close file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to close file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rename it
|
// rename it
|
||||||
n = walBuildMetaName(pWal, metaVer + 1, fnameStr);
|
n = walBuildMetaName(pWal, metaVer + 1, fnameStr);
|
||||||
if (n >= sizeof(fnameStr)) {
|
if (n >= sizeof(fnameStr)) {
|
||||||
|
code = TSDB_CODE_FAILED;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosRenameFile(tmpFnameStr, fnameStr) < 0) {
|
if (taosRenameFile(tmpFnameStr, fnameStr) < 0) {
|
||||||
wError("failed to rename file due to %s. dest:%s", strerror(errno), fnameStr);
|
wError("failed to rename file due to %s. dest:%s", strerror(errno), fnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,13 +947,14 @@ int walSaveMeta(SWal* pWal) {
|
||||||
walBuildMetaName(pWal, metaVer, fnameStr);
|
walBuildMetaName(pWal, metaVer, fnameStr);
|
||||||
taosRemoveFile(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
return 0;
|
return code;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
taosCloseFile(&pMetaFile);
|
taosCloseFile(&pMetaFile);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int walLoadMeta(SWal* pWal) {
|
int walLoadMeta(SWal* pWal) {
|
||||||
|
|
|
@ -46,10 +46,11 @@ int32_t walInit() {
|
||||||
tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
|
tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
|
||||||
|
|
||||||
int32_t code = walCreateThread();
|
int32_t code = walCreateThread();
|
||||||
if (code != 0) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
wError("failed to init wal module since %s", tstrerror(code));
|
wError("failed to init wal module since %s", tstrerror(code));
|
||||||
atomic_store_8(&tsWal.inited, 0);
|
atomic_store_8(&tsWal.inited, 0);
|
||||||
return code;
|
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
wInfo("wal module is initialized, rsetId:%d", tsWal.refSetId);
|
wInfo("wal module is initialized, rsetId:%d", tsWal.refSetId);
|
||||||
|
@ -171,19 +172,20 @@ _err:
|
||||||
taosArrayDestroy(pWal->fileInfoSet);
|
taosArrayDestroy(pWal->fileInfoSet);
|
||||||
taosHashCleanup(pWal->pRefHash);
|
taosHashCleanup(pWal->pRefHash);
|
||||||
taosThreadMutexDestroy(&pWal->mutex);
|
taosThreadMutexDestroy(&pWal->mutex);
|
||||||
taosMemoryFree(pWal);
|
taosMemoryFreeClear(pWal);
|
||||||
pWal = NULL;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
||||||
if (pWal == NULL) return TSDB_CODE_APP_ERROR;
|
if (pWal == NULL) TAOS_RETURN(TSDB_CODE_APP_ERROR);
|
||||||
|
|
||||||
if (pWal->cfg.level == pCfg->level && pWal->cfg.fsyncPeriod == pCfg->fsyncPeriod &&
|
if (pWal->cfg.level == pCfg->level && pWal->cfg.fsyncPeriod == pCfg->fsyncPeriod &&
|
||||||
pWal->cfg.retentionPeriod == pCfg->retentionPeriod && pWal->cfg.retentionSize == pCfg->retentionSize) {
|
pWal->cfg.retentionPeriod == pCfg->retentionPeriod && pWal->cfg.retentionSize == pCfg->retentionSize) {
|
||||||
wDebug("vgId:%d, walLevel:%d fsync:%d walRetentionPeriod:%d walRetentionSize:%" PRId64 " not change",
|
wDebug("vgId:%d, walLevel:%d fsync:%d walRetentionPeriod:%d walRetentionSize:%" PRId64 " not change",
|
||||||
pWal->cfg.vgId, pWal->cfg.level, pWal->cfg.fsyncPeriod, pWal->cfg.retentionPeriod, pWal->cfg.retentionSize);
|
pWal->cfg.vgId, pWal->cfg.level, pWal->cfg.fsyncPeriod, pWal->cfg.retentionPeriod, pWal->cfg.retentionSize);
|
||||||
return 0;
|
|
||||||
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
wInfo("vgId:%d, change old walLevel:%d fsync:%d walRetentionPeriod:%d walRetentionSize:%" PRId64
|
wInfo("vgId:%d, change old walLevel:%d fsync:%d walRetentionPeriod:%d walRetentionSize:%" PRId64
|
||||||
|
@ -199,14 +201,17 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
||||||
pWal->fsyncSeq = pCfg->fsyncPeriod / 1000;
|
pWal->fsyncSeq = pCfg->fsyncPeriod / 1000;
|
||||||
if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1;
|
if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1;
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t walPersist(SWal *pWal) {
|
int32_t walPersist(SWal *pWal) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
taosThreadMutexLock(&pWal->mutex);
|
taosThreadMutexLock(&pWal->mutex);
|
||||||
int32_t ret = walSaveMeta(pWal);
|
code = walSaveMeta(pWal);
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return ret;
|
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void walClose(SWal *pWal) {
|
void walClose(SWal *pWal) {
|
||||||
|
@ -301,14 +306,14 @@ static int32_t walCreateThread() {
|
||||||
|
|
||||||
if (taosThreadCreate(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
|
if (taosThreadCreate(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
|
||||||
wError("failed to create wal thread since %s", strerror(errno));
|
wError("failed to create wal thread since %s", strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return -1;
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread));
|
wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void walStopThread() {
|
static void walStopThread() {
|
||||||
|
|
Loading…
Reference in New Issue