Merge branch 'main' of https://github.com/taosdata/TDengine into fix/TD-22070
This commit is contained in:
commit
76e3720530
|
@ -306,7 +306,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
if (pSyncNode->replicaNum > 1) {
|
||||
// multi replicas
|
||||
|
||||
lastApplyIndex -= SYNC_VNODE_LOG_RETENTION;
|
||||
lastApplyIndex = TMAX(lastApplyIndex - SYNC_VNODE_LOG_RETENTION, beginIndex - 1);
|
||||
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
pSyncNode->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||
|
|
|
@ -325,6 +325,35 @@ bool walLogEntriesComplete(const SWal* pWal) {
|
|||
return complete;
|
||||
}
|
||||
|
||||
int walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
|
||||
ASSERT(pFileInfo != NULL);
|
||||
char fnameStr[WAL_FILE_LEN];
|
||||
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
|
||||
|
||||
int64_t fileSize = 0;
|
||||
taosStatFile(fnameStr, &fileSize, NULL);
|
||||
int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1);
|
||||
int64_t lastEndOffset = records * sizeof(SWalIdxEntry);
|
||||
|
||||
if (fileSize <= lastEndOffset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize,
|
||||
lastEndOffset);
|
||||
|
||||
taosFtruncateFile(pFile, lastEndOffset);
|
||||
taosCloseFile(&pFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int walCheckAndRepairMeta(SWal* pWal) {
|
||||
// load log files, get first/snapshot/last version info
|
||||
const char* logPattern = "^[0-9]+.log$";
|
||||
|
@ -402,6 +431,8 @@ int walCheckAndRepairMeta(SWal* pWal) {
|
|||
}
|
||||
updateMeta = true;
|
||||
|
||||
(void)walTrimIdxFile(pWal, fileIdx);
|
||||
|
||||
int64_t lastVer = walScanLogGetLastVer(pWal, fileIdx);
|
||||
if (lastVer < 0) {
|
||||
if (terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
|
@ -567,6 +598,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
int64_t count = 0;
|
||||
while (idxEntry.ver < pFileInfo->lastVer) {
|
||||
ASSERT(idxEntry.ver == ckHead.head.version);
|
||||
|
||||
|
@ -578,11 +610,11 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
|||
idxEntry.offset, fLogNameStr);
|
||||
goto _err;
|
||||
}
|
||||
wWarn("vgId:%d, wal idx append new entry %" PRId64 " %" PRId64, pWal->cfg.vgId, idxEntry.ver, idxEntry.offset);
|
||||
if (taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) {
|
||||
wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr);
|
||||
goto _err;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
if (taosFsyncFile(pIdxFile) < 0) {
|
||||
|
@ -590,6 +622,11 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
wInfo("vgId:%d, rebuilt %" PRId64 " wal idx entries until lastVer: %" PRId64, pWal->cfg.vgId, count,
|
||||
pFileInfo->lastVer);
|
||||
}
|
||||
|
||||
(void)taosCloseFile(&pLogFile);
|
||||
(void)taosCloseFile(&pIdxFile);
|
||||
return 0;
|
||||
|
|
|
@ -79,6 +79,7 @@ sql insert into db.ctb6 values(now, 6, "6")
|
|||
sql insert into db.ctb7 values(now, 7, "7")
|
||||
sql insert into db.ctb8 values(now, 8, "8")
|
||||
sql insert into db.ctb9 values(now, 9, "9")
|
||||
sql flush database db;
|
||||
|
||||
print =============== step3: create dnodes
|
||||
sql create dnode $hostname port 7300
|
||||
|
|
Loading…
Reference in New Issue