From ce4192375de7215b9bca5ec545de6a60e66b7026 Mon Sep 17 00:00:00 2001 From: Cheng Chang Date: Thu, 20 Aug 2020 15:10:38 -0700 Subject: [PATCH] Track WAL in MANIFEST: minor udpates (#7282) Summary: The updates resolve comments left from https://github.com/facebook/rocksdb/pull/7164. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7282 Test Plan: wal_edit_test Reviewed By: ltamasi Differential Revision: D23196824 Pulled By: cheng-chang fbshipit-source-id: 797f3fef27fc72114c2be777d9eadd3429da5301 --- db/wal_edit.cc | 6 +++--- db/wal_edit_test.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/wal_edit.cc b/db/wal_edit.cc index d68a98d31..8f15540e1 100644 --- a/db/wal_edit.cc +++ b/db/wal_edit.cc @@ -126,7 +126,7 @@ Status WalSet::AddWal(const WalAddition& wal) { ss << "WAL " << wal.GetLogNumber() << " is created more than once"; return Status::Corruption("WalSet", ss.str()); } - wals_[wal.GetLogNumber()] = wal.GetMetadata(); + wals_.insert(it, {wal.GetLogNumber(), wal.GetMetadata()}); } return Status::OK(); } @@ -143,9 +143,9 @@ Status WalSet::AddWals(const WalAdditions& wals) { } Status WalSet::DeleteWal(const WalDeletion& wal) { - auto it = wals_.lower_bound(wal.GetLogNumber()); + auto it = wals_.find(wal.GetLogNumber()); // The WAL must exist and has been closed. - if (it == wals_.end() || it->first != wal.GetLogNumber()) { + if (it == wals_.end()) { std::stringstream ss; ss << "WAL " << wal.GetLogNumber() << " must exist before deletion"; return Status::Corruption("WalSet", ss.str()); diff --git a/db/wal_edit_test.cc b/db/wal_edit_test.cc index 58b2e80dd..fb3bad070 100644 --- a/db/wal_edit_test.cc +++ b/db/wal_edit_test.cc @@ -109,10 +109,10 @@ TEST(WalSet, DeleteNonExistingWal) { } TEST(WalSet, DeleteNonClosedWal) { - constexpr WalNumber kNonExistingNumber = 100; + constexpr WalNumber kNonClosedWalNumber = 100; WalSet wals; - ASSERT_OK(wals.AddWal(WalAddition(kNonExistingNumber))); - Status s = wals.DeleteWal(WalDeletion(kNonExistingNumber)); + ASSERT_OK(wals.AddWal(WalAddition(kNonClosedWalNumber))); + Status s = wals.DeleteWal(WalDeletion(kNonClosedWalNumber)); ASSERT_TRUE(s.IsCorruption()); ASSERT_TRUE(s.ToString().find("WAL 100 must be closed before deletion") != std::string::npos);