From 361332505c15b8c6517b0cf8100f6a2dda90c62e Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Thu, 2 Jun 2022 11:38:04 +0800 Subject: [PATCH] feat(wal): support restore from snapshot --- include/libs/wal/wal.h | 1 + source/libs/wal/src/walWrite.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index e541c214de..95af8ac306 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -184,6 +184,7 @@ int32_t walRollback(SWal *, int64_t ver); // notify that previous logs can be pruned safely int32_t walBeginSnapshot(SWal *, int64_t ver); int32_t walEndSnapshot(SWal *); +void walRestoreFromSnapshot(SWal *, int64_t ver); // int32_t walDataCorrupted(SWal*); // read diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index d2a43c4107..4e2270c37b 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -18,6 +18,14 @@ #include "tchecksum.h" #include "walInt.h" +void walRestoreFromSnapshot(SWal *pWal, int64_t ver) { + pWal->vers.firstVer = -1; + pWal->vers.lastVer = ver; + pWal->vers.commitVer = ver - 1; + pWal->vers.snapshotVer = ver - 1; + pWal->vers.verInSnapshotting = -1; +} + int32_t walCommit(SWal *pWal, int64_t ver) { ASSERT(pWal->vers.commitVer >= pWal->vers.snapshotVer); ASSERT(pWal->vers.commitVer <= pWal->vers.lastVer);