From 7f323a83a1dee99d1ddc22016e73f3d310cac642 Mon Sep 17 00:00:00 2001 From: Qi Xu Date: Thu, 21 Mar 2024 23:37:47 -0700 Subject: [PATCH] fix Wal in manifest Signed-off-by: Qi Xu --- db/wal_edit.cc | 9 +++++++++ db/wal_edit.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/db/wal_edit.cc b/db/wal_edit.cc index 1e1e820b71c..4435636dd13 100644 --- a/db/wal_edit.cc +++ b/db/wal_edit.cc @@ -17,6 +17,8 @@ void WalAddition::EncodeTo(std::string* dst) const { if (metadata_.HasSyncedSize()) { PutVarint32(dst, static_cast(WalAdditionTag::kSyncedSize)); PutVarint64(dst, metadata_.GetSyncedSizeInBytes()); + PutVarint32(dst, static_cast(WalAdditionTag::kLastSyncSeq)); + PutVarint64(dst, metadata_.GetLastSequence()); } PutVarint32(dst, static_cast(WalAdditionTag::kTerminate)); @@ -44,6 +46,13 @@ Status WalAddition::DecodeFrom(Slice* src) { metadata_.SetSyncedSizeInBytes(size); break; } + case WalAdditionTag::kLastSyncSeq: { + uint64_t lsn = 0; + if (!GetVarint64(src, &lsn)) { + return Status::Corruption(class_name, "Error decoding WAL file size"); + } + metadata_.SetLastSequence(lsn); + } // TODO: process future tags such as checksum. case WalAdditionTag::kTerminate: return Status::OK(); diff --git a/db/wal_edit.h b/db/wal_edit.h index e4807b9b633..c3c2566a942 100644 --- a/db/wal_edit.h +++ b/db/wal_edit.h @@ -45,6 +45,8 @@ class WalMetadata { uint64_t GetLastSequence() const { return last_sequence_number_; } + void SetLastSequence(uint64_t lsn) { last_sequence_number_ = lsn; } + private: friend bool operator==(const WalMetadata& lhs, const WalMetadata& rhs); friend bool operator!=(const WalMetadata& lhs, const WalMetadata& rhs); @@ -72,6 +74,8 @@ enum class WalAdditionTag : uint32_t { kTerminate = 1, // Synced Size in bytes. kSyncedSize = 2, + + kLastSyncSeq = 3, // Add tags in the future, such as checksum? };