Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/common/tglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ extern int64_t tsmaDataDeleteMark;
// wal
extern int64_t tsWalFsyncDataSizeLimit;
extern bool tsWalForceRepair;
extern bool tsWalDeleteOnCorruption;
// WAL recovery policy (only affects single replica)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header comment says walRecoveryPolicy "only affects single replica", but the new logic checks it for all replica != 3 cases (so it would also affect replica=2 if that configuration exists). Please align the comment (and possibly the config semantics) with actual behavior to avoid misconfiguration.

Suggested change
// WAL recovery policy (only affects single replica)
// WAL recovery policy (applies when replica count is not 3, including single-replica deployments)

Copilot uses AI. Check for mistakes.
// 0 = refuse to start (default), 1 = delete corrupted and start
extern int32_t tsWalRecoveryPolicy;

// internal
extern bool tsDiskIDCheckEnabled;
Expand Down
2 changes: 2 additions & 0 deletions include/libs/sync/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ const char* syncStr(ESyncState state);

int32_t syncNodeGetConfig(int64_t rid, SSyncCfg* cfg);

int32_t syncNotifyWalTruncated(int32_t vgId, int64_t truncatedVer);

// util
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size);

Expand Down
2 changes: 1 addition & 1 deletion include/libs/wal/wal.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int32_t walInit(stopDnodeFn stopDnode);
void walCleanUp();

// handle open and ctl
SWal *walOpen(const char *path, SWalCfg *pCfg);
SWal *walOpen(const char *path, SWalCfg *pCfg, int32_t replica);
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walOpen signature change is not fully propagated: multiple test call sites still use the old 2-arg form (e.g. source/libs/wal/test/walMetaTest.cpp and several source/libs/sync/test/*.cpp), which will break compilation. Consider either updating all callers in this PR or providing a backward-compatible wrapper API (e.g. keep walOpen(path,cfg) and introduce a new function / default replica handling).

Suggested change
SWal *walOpen(const char *path, SWalCfg *pCfg, int32_t replica);
SWal *walOpen(const char *path, SWalCfg *pCfg, int32_t replica);
static inline SWal *walOpenDefaultReplica(const char *path, SWalCfg *pCfg) { return walOpen(path, pCfg, 0); }
#define WAL_OPEN_SELECT(_1, _2, _3, NAME, ...) NAME
#define walOpen(...) WAL_OPEN_SELECT(__VA_ARGS__, walOpen, walOpenDefaultReplica)(__VA_ARGS__)

Copilot uses AI. Check for mistakes.
int32_t walAlter(SWal *, SWalCfg *pCfg);
int32_t walPersist(SWal *);
void walClose(SWal *);
Expand Down
8 changes: 4 additions & 4 deletions source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ bool tsStartUdfd = true;
// wal
int64_t tsWalFsyncDataSizeLimit = (100 * 1024 * 1024L);
bool tsWalForceRepair = 0;
bool tsWalDeleteOnCorruption = false;
int32_t tsWalRecoveryPolicy = 0; // Default: refuse to start for single replica

// ttl
bool tsTtlChangeOnWrite = false; // if true, ttl delete time changes on last write
Expand Down Expand Up @@ -981,7 +981,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "syncApplyQueueSize", tsSyncApplyQueueSize, 32, 2048, CFG_SCOPE_SERVER, CFG_DYN_SERVER,CFG_CATEGORY_GLOBAL));
TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "syncRoutineReportInterval", tsRoutineReportInterval, 5, 600, CFG_SCOPE_SERVER, CFG_DYN_SERVER,CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "syncLogHeartbeat", tsSyncLogHeartbeat, CFG_SCOPE_SERVER, CFG_DYN_SERVER,CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "walDeleteOnCorruption", tsWalDeleteOnCorruption, CFG_SCOPE_SERVER, CFG_DYN_NONE,CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "walRecoveryPolicy", tsWalRecoveryPolicy, 0, 1, CFG_SCOPE_SERVER, CFG_DYN_NONE, CFG_CATEGORY_LOCAL));

TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "syncTimeout", tsSyncTimeout, 0, 60 * 24 * 2 * 1000, CFG_SCOPE_SERVER, CFG_DYN_SERVER,CFG_CATEGORY_GLOBAL));

Expand Down Expand Up @@ -2143,8 +2143,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsRpcRecvLogThreshold = pItem->i32;
// GRANT_CFG_GET;

TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "walDeleteOnCorruption");
tsWalDeleteOnCorruption = pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "walRecoveryPolicy");
tsWalRecoveryPolicy = pItem->i32;

TAOS_RETURN(TSDB_CODE_SUCCESS);
}
Expand Down
2 changes: 1 addition & 1 deletion source/dnode/mnode/impl/src/mndMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ static int32_t mndInitWal(SMnode *pMnode) {
}
#endif

pMnode->pWal = walOpen(path, &cfg);
pMnode->pWal = walOpen(path, &cfg, pMnode->syncMgmt.numOfReplicas);
if (pMnode->pWal == NULL) {
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
if (terrno != 0) code = terrno;
Expand Down
2 changes: 1 addition & 1 deletion source/dnode/vnode/src/vnd/vnodeOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
TAOS_UNUSED(ret);

vInfo("vgId:%d, start to open vnode wal", TD_VID(pVnode));
pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg));
pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg), pVnode->config.syncCfg.replicaNum);
if (pVnode->pWal == NULL) {
vError("vgId:%d, failed to open vnode wal since %s. wal:%s", TD_VID(pVnode), tstrerror(terrno), tdir);
goto _err;
Expand Down
2 changes: 2 additions & 0 deletions source/libs/sync/inc/syncInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode);
bool syncNodeIsMnode(SSyncNode* pSyncNode);
int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);

int32_t syncNotifyWalTruncated(int32_t vgId, int64_t truncatedVer);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions source/libs/sync/src/syncMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -4090,3 +4090,8 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) {
return true;
}
#endif

int32_t syncNotifyWalTruncated(int32_t vgId, int64_t truncatedVer) {
sInfo("vgId:%d, notified sync module: WAL truncated to ver:%" PRId64, vgId, truncatedVer);
return TSDB_CODE_SUCCESS;
}
Comment on lines +4094 to +4097
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The implementation of syncNotifyWalTruncated currently only logs a message. To fulfill the PR's objective of 'Enabling Raft to detect and sync missing logs', this function should update the state of the corresponding sync node (e.g., resetting its applied index or marking it as needing a snapshot/sync).

Comment on lines +4093 to +4097
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncNotifyWalTruncated() is added to public headers, but there are no call sites in the repo. If the intent is to notify Raft after WAL truncation/recovery, wire this into the WAL recovery path (e.g., after walTruncateCorruptedFiles succeeds) and pass the actual truncated version; otherwise keep the symbol internal or remove it to avoid exposing an unused API surface.

Suggested change
int32_t syncNotifyWalTruncated(int32_t vgId, int64_t truncatedVer) {
sInfo("vgId:%d, notified sync module: WAL truncated to ver:%" PRId64, vgId, truncatedVer);
return TSDB_CODE_SUCCESS;
}

Copilot uses AI. Check for mistakes.
2 changes: 1 addition & 1 deletion source/libs/wal/inc/walInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int32_t walRemoveMeta(SWal* pWal);
int32_t walRollImpl(SWal* pWal);
int32_t walRollFileInfo(SWal* pWal);
int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, int64_t* lastVer);
int32_t walCheckAndRepairMeta(SWal* pWal);
int32_t walCheckAndRepairMeta(SWal* pWal, int32_t replica);
int64_t walChangeWrite(SWal* pWal, int64_t ver);

int32_t walCheckAndRepairIdx(SWal* pWal);
Expand Down
192 changes: 170 additions & 22 deletions source/libs/wal/src/walMeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,143 @@ static int32_t walRenameCorruptedDir(SWal* pWal) {
TAOS_RETURN(code);
}

static int32_t walLogEntriesComplete(SWal* pWal) {
static int32_t walTruncateCorruptedFiles(SWal* pWal, int32_t fileIdx, int32_t replica, int64_t lastValidVer) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
bool shouldRecover = false;

if (replica == 3) {
shouldRecover = true;
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
wInfo("vgId:%d, WAL corrupted at ver:%" PRId64 ", auto-recovery enabled for replica=3",
pWal->cfg.vgId, pFileInfo->firstVer);
} else {
shouldRecover = (tsWalRecoveryPolicy == 1);
if (shouldRecover) {
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
wWarn("vgId:%d, WAL corrupted at ver:%" PRId64 ", force recovery enabled by walRecoveryPolicy=1",
pWal->cfg.vgId, pFileInfo->firstVer);
} else {
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
wError("vgId:%d, WAL corrupted at ver:%" PRId64 ", refusing to start to prevent data loss",
pWal->cfg.vgId, pFileInfo->firstVer);
wError("vgId:%d, corrupted WAL files are preserved for manual inspection", pWal->cfg.vgId);
wError("vgId:%d, to force recovery with data loss, set 'walRecoveryPolicy 1' in taos.cfg and restart",
pWal->cfg.vgId);
Comment on lines +439 to +456
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walTruncateCorruptedFiles() doesn't validate fileIdx before calling taosArrayGet(pWal->fileInfoSet, fileIdx) and before computing the remove batch length (size - fileIdx). If fileIdx is negative or >= array size, this can lead to invalid memory access or a huge batch removal due to underflow. Add defensive checks at the start of this function and return an appropriate error when fileIdx is out of range.

Copilot uses AI. Check for mistakes.
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
}
}

if (!shouldRecover) {
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
}

wInfo("vgId:%d, truncating WAL at corrupted file index %d, lastValidVer:%" PRId64, pWal->cfg.vgId, fileIdx, lastValidVer);

// Truncate current corrupted file if there's a valid version
if (fileIdx < taosArrayGetSize(pWal->fileInfoSet) && lastValidVer >= 0) {
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);

// Only truncate if this file has valid entries before corruption
if (lastValidVer >= pFileInfo->firstVer) {
char logName[WAL_FILE_LEN];
char idxName[WAL_FILE_LEN];
walBuildLogName(pWal, pFileInfo->firstVer, logName);
walBuildIdxName(pWal, pFileInfo->firstVer, idxName);

// Read the idx file to find the offset of lastValidVer + 1
TdFilePtr pIdxFile = taosOpenFile(idxName, TD_FILE_READ);
if (pIdxFile != NULL) {
int64_t idxEntries = lastValidVer - pFileInfo->firstVer + 1;
int64_t idxFileSize = idxEntries * sizeof(SWalIdxEntry);

// Truncate idx file
(void)taosCloseFile(&pIdxFile);
pIdxFile = taosOpenFile(idxName, TD_FILE_READ | TD_FILE_WRITE);
if (pIdxFile != NULL) {
if (taosFtruncateFile(pIdxFile, idxFileSize) == 0) {
wInfo("vgId:%d, truncated idx file %s to size:%" PRId64, pWal->cfg.vgId, idxName, idxFileSize);
} else {
wWarn("vgId:%d, failed to truncate idx file %s", pWal->cfg.vgId, idxName);
}
(void)taosCloseFile(&pIdxFile);
}

// Read the last valid entry's offset from idx, then read log entry to get size
pIdxFile = taosOpenFile(idxName, TD_FILE_READ);
if (pIdxFile != NULL && idxEntries > 0) {
SWalIdxEntry idxEntry;
int64_t readPos = (idxEntries - 1) * sizeof(SWalIdxEntry);
if (taosLSeekFile(pIdxFile, readPos, SEEK_SET) >= 0) {
if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) == sizeof(SWalIdxEntry)) {
// Read log entry header to get the size
TdFilePtr pLogFile = taosOpenFile(logName, TD_FILE_READ | TD_FILE_WRITE);
if (pLogFile != NULL) {
SWalCkHead ckHead;
if (taosLSeekFile(pLogFile, idxEntry.offset, SEEK_SET) >= 0) {
if (taosReadFile(pLogFile, &ckHead, sizeof(SWalCkHead)) == sizeof(SWalCkHead)) {
int32_t cryptedBodyLen = ckHead.head.bodyLen;
if (pWal->cfg.encryptAlgorithm == DND_CA_SM4) {
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
}
int64_t logTruncateOffset = idxEntry.offset + sizeof(SWalCkHead) + cryptedBodyLen;

// Truncate log file
if (taosFtruncateFile(pLogFile, logTruncateOffset) == 0) {
wInfo("vgId:%d, truncated log file %s to offset:%" PRId64, pWal->cfg.vgId, logName, logTruncateOffset);
pFileInfo->lastVer = lastValidVer;
pFileInfo->fileSize = logTruncateOffset;
} else {
wWarn("vgId:%d, failed to truncate log file %s", pWal->cfg.vgId, logName);
}
}
}
(void)taosCloseFile(&pLogFile);
}
}
}
(void)taosCloseFile(&pIdxFile);
}
}

// Don't delete this file, move to next
fileIdx++;
}
}

// Delete all files from fileIdx onwards
for (int32_t i = fileIdx; i < taosArrayGetSize(pWal->fileInfoSet); i++) {
SWalFileInfo* pDelFileInfo = taosArrayGet(pWal->fileInfoSet, i);
char delLogName[WAL_FILE_LEN];
char delIdxName[WAL_FILE_LEN];

walBuildLogName(pWal, pDelFileInfo->firstVer, delLogName);
walBuildIdxName(pWal, pDelFileInfo->firstVer, delIdxName);

if (taosRemoveFile(delLogName) != 0) {
wWarn("vgId:%d, failed to remove corrupted log file %s", pWal->cfg.vgId, delLogName);
} else {
wInfo("vgId:%d, removed corrupted log file %s", pWal->cfg.vgId, delLogName);
}

if (taosRemoveFile(delIdxName) != 0) {
wWarn("vgId:%d, failed to remove corrupted idx file %s", pWal->cfg.vgId, delIdxName);
} else {
wInfo("vgId:%d, removed corrupted idx file %s", pWal->cfg.vgId, delIdxName);
}
}

// Remove deleted files from fileInfoSet
if (fileIdx < taosArrayGetSize(pWal->fileInfoSet)) {
taosArrayRemoveBatch(pWal->fileInfoSet, fileIdx, taosArrayGetSize(pWal->fileInfoSet) - fileIdx, NULL);
}

wInfo("vgId:%d, WAL truncated successfully", pWal->cfg.vgId);

TAOS_RETURN(TSDB_CODE_SUCCESS);
}

static int32_t walLogEntriesComplete(SWal* pWal, int32_t replica) {
int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
bool complete = true;
int32_t fileIdx = -1;
Expand All @@ -451,13 +587,10 @@ static int32_t walLogEntriesComplete(SWal* pWal) {

if (!complete) {
wError("vgId:%d, WAL log entries incomplete in range [%" PRId64 ", %" PRId64 "], index:%" PRId64
", snaphot index:%" PRId64,
pWal->cfg.vgId, pWal->vers.firstVer, pWal->vers.lastVer, index, pWal->vers.snapshotVer);
if (tsWalDeleteOnCorruption) {
TAOS_RETURN(walRenameCorruptedDir(pWal));
} else {
TAOS_RETURN(TSDB_CODE_WAL_LOG_INCOMPLETE);
}
", snaphot index:%" PRId64 ", fileIdx:%d",
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in log message: "snaphot" should be "snapshot".

Suggested change
", snaphot index:%" PRId64 ", fileIdx:%d",
", snapshot index:%" PRId64 ", fileIdx:%d",

Copilot uses AI. Check for mistakes.
pWal->cfg.vgId, pWal->vers.firstVer, pWal->vers.lastVer, index, pWal->vers.snapshotVer, fileIdx);
int64_t lastValidVer = (index > 0) ? (index - 1) : -1;
TAOS_RETURN(walTruncateCorruptedFiles(pWal, fileIdx, replica, lastValidVer));
} else {
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
Expand Down Expand Up @@ -517,7 +650,7 @@ void walRegfree(regex_t* ptr) {
regfree(ptr);
}

int32_t walCheckAndRepairMeta(SWal* pWal) {
int32_t walCheckAndRepairMeta(SWal* pWal, int32_t replica) {
// load log files, get first/snapshot/last version info
int32_t code = 0;
int32_t lino = 0;
Expand All @@ -526,6 +659,8 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regex_t logRegPattern, idxRegPattern;
TdDirPtr pDir = NULL;
SArray* actualLog = NULL;
bool walTruncated = false;
int64_t truncatedVer = -1;
Comment on lines +662 to +663
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walTruncated and truncatedVer are declared but never used, which is dead code and can trigger -Wunused-variable warnings in some build configurations. Either remove them or use them for the intended truncation notification/metadata tracking (e.g., record truncatedVer and propagate it to the sync module).

Suggested change
bool walTruncated = false;
int64_t truncatedVer = -1;

Copilot uses AI. Check for mistakes.

wInfo("vgId:%d, begin to repair meta, wal path:%s, first index:%" PRId64 ", last index:%" PRId64
", snapshot index:%" PRId64,
Expand Down Expand Up @@ -607,22 +742,35 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
if (lastVer < 0) {
if (code != TSDB_CODE_WAL_LOG_NOT_EXIST) {
wError("vgId:%d, failed to scan wal last index since %s", pWal->cfg.vgId, tstrerror(code));
if (tsWalDeleteOnCorruption) {
TAOS_RETURN(walRenameCorruptedDir(pWal));

// Calculate last valid version from previous file
int64_t lastValidVer = (fileIdx > 0) ? ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, fileIdx - 1))->lastVer : -1;

code = walTruncateCorruptedFiles(pWal, fileIdx, replica, lastValidVer);
if (code != TSDB_CODE_SUCCESS) {
goto _exit;
}
goto _exit;
}
// empty log file
lastVer = pFileInfo->firstVer - 1;

code = TSDB_CODE_SUCCESS;
// After truncation, set lastVer based on remaining files
lastVer = lastValidVer;
wInfo("vgId:%d, WAL truncated, new lastVer:%" PRId64, pWal->cfg.vgId, lastVer);
updateMeta = true;
code = TSDB_CODE_SUCCESS;
} else {
// empty log file
lastVer = pFileInfo->firstVer - 1;
code = TSDB_CODE_SUCCESS;
}
}
wInfo("vgId:%d, repaired file %s, last index:%" PRId64 ", fileSize:%" PRId64 ", fileSize in meta:%" PRId64,
pWal->cfg.vgId, fnameStr, lastVer, fileSize, pFileInfo->fileSize);

// update lastVer
pFileInfo->lastVer = lastVer;
totSize += pFileInfo->fileSize;
if (code == TSDB_CODE_SUCCESS && lastVer >= 0) {
wInfo("vgId:%d, repaired file %s, last index:%" PRId64 ", fileSize:%" PRId64 ", fileSize in meta:%" PRId64,
pWal->cfg.vgId, fnameStr, lastVer, fileSize, pFileInfo->fileSize);

// update lastVer
pFileInfo->lastVer = lastVer;
totSize += pFileInfo->fileSize;
}
}

// reset vers info and so on
Expand All @@ -647,7 +795,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
TAOS_CHECK_EXIT(walSaveMeta(pWal));
}

TAOS_CHECK_EXIT(walLogEntriesComplete(pWal));
TAOS_CHECK_EXIT(walLogEntriesComplete(pWal, replica));

Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walLogEntriesComplete() can now mutate pWal->fileInfoSet by truncating WAL files, but walCheckAndRepairMeta() doesn't recompute pWal->vers/totSize or persist meta after this call. If truncation happens here, pWal->vers.lastVer (and the on-disk meta) can remain stale/inconsistent with the new file set. Consider having walLogEntriesComplete() report whether truncation occurred (or return a distinct code), then re-run version alignment + walSaveMeta() (and adjust totSize) when truncation happens.

Suggested change
actualFileNum = taosArrayGetSize(pWal->fileInfoSet);
if (actualFileNum > 0) {
pWal->vers.firstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer;
pWal->vers.lastVer = ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer;
} else {
pWal->vers.firstVer = -1;
pWal->vers.lastVer = -1;
}
walAlignVersions(pWal);
TAOS_CHECK_EXIT(walSaveMeta(pWal));

Copilot uses AI. Check for mistakes.
wInfo("vgId:%d, success to repair meta, wal path:%s, first index:%" PRId64 ", last index:%" PRId64
", snapshot index:%" PRId64,
Expand Down
4 changes: 2 additions & 2 deletions source/libs/wal/src/walMgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int32_t walInitWriteFileForSkip(SWal *pWal) {
TAOS_RETURN(code);
}

SWal *walOpen(const char *path, SWalCfg *pCfg) {
SWal *walOpen(const char *path, SWalCfg *pCfg, int32_t replica) {
int32_t code = 0;
SWal *pWal = taosMemoryCalloc(1, sizeof(SWal));
if (pWal == NULL) {
Expand Down Expand Up @@ -206,7 +206,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
wWarn("vgId:%d, failed to load meta, code:0x%x", pWal->cfg.vgId, code);
}
if (pWal->cfg.level != TAOS_WAL_SKIP) {
code = walCheckAndRepairMeta(pWal);
code = walCheckAndRepairMeta(pWal, replica);
if (code < 0) {
wError("vgId:%d, cannot open wal since repair meta file failed since %s", pWal->cfg.vgId, tstrerror(code));
goto _err;
Expand Down
Loading