Skip to content

Commit

Permalink
fix Wal in manifest
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Xu <[email protected]>
  • Loading branch information
Qi Xu committed Mar 22, 2024
1 parent c98e2f6 commit 7f323a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions db/wal_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void WalAddition::EncodeTo(std::string* dst) const {
if (metadata_.HasSyncedSize()) {
PutVarint32(dst, static_cast<uint32_t>(WalAdditionTag::kSyncedSize));
PutVarint64(dst, metadata_.GetSyncedSizeInBytes());
PutVarint32(dst, static_cast<uint32_t>(WalAdditionTag::kLastSyncSeq));
PutVarint64(dst, metadata_.GetLastSequence());
}

PutVarint32(dst, static_cast<uint32_t>(WalAdditionTag::kTerminate));
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions db/wal_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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?
};

Expand Down

0 comments on commit 7f323a8

Please sign in to comment.