From 19ad1b832b5c0027684de28a8fb3c8131133a089 Mon Sep 17 00:00:00 2001 From: "wangyi.ywq" Date: Tue, 5 Jul 2022 13:39:55 +0800 Subject: [PATCH] WIP --- Makefile | 3 +- db/db_filesnapshot.cc | 11 +++-- utilities/checkpoint/checkpoint_test.cc | 57 +++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1cb34e8fc8..1a62eb44fe 100644 --- a/Makefile +++ b/Makefile @@ -1883,7 +1883,8 @@ rocksdbjavastaticreleasedocker: rocksdbjavastatic rocksdbjavastaticdockerx86_64 fterark:rocksdbjavastatic cd java;jar -cf target/$(ROCKSDB_JAR_ALL) HISTORY*.md - cd java/target;jar -uf $(ROCKSDB_JAR_ALL) libterarkdbjni-*.so libterarkdbjni-* + cd java/target;jar -uf $(ROCKSDB_JAR_ALL) libterarkdbjni-* + #cd java/target;jar -uf $(ROCKSDB_JAR_ALL) libterarkdbjni-*.so libterarkdbjni-* cd java/target/classes;jar -uf ../$(ROCKSDB_JAR_ALL) org/rocksdb/*.class org/rocksdb/util/*.class # update apache license diff --git a/db/db_filesnapshot.cc b/db/db_filesnapshot.cc index 1eaa3c951d..48bb82c8ce 100644 --- a/db/db_filesnapshot.cc +++ b/db/db_filesnapshot.cc @@ -145,9 +145,14 @@ Status DBImpl::FakeFlush(std::vector& ret) { VersionEdit* edit = &iter->second; autovector mems; cfd->imm()->PickMemtablesToFlush(nullptr,&mems); - for(auto& m: mems){ - status = WriteLevel0TableForRecovery(job_id, cfd, m , edit); - if(!status.ok()) break; + if (!mems.empty()) { + cfd->imm()->RollbackMemtableFlush(mems, 0, status); + } + if (status.ok()) { + for (auto& m : mems) { + status = WriteLevel0TableForRecovery(job_id, cfd, m, edit); + if (!status.ok()) break; + } } if(status.ok()){ status = WriteLevel0TableForRecovery(job_id, cfd, cfd->mem(), edit); diff --git a/utilities/checkpoint/checkpoint_test.cc b/utilities/checkpoint/checkpoint_test.cc index b9441f454b..06d3796889 100644 --- a/utilities/checkpoint/checkpoint_test.cc +++ b/utilities/checkpoint/checkpoint_test.cc @@ -232,6 +232,63 @@ class CheckpointTest : public testing::Test { } }; +TEST_F(CheckpointTest, RepeatGetSnapshotLink) { + for (uint64_t log_size_for_flush : {0, 1000000}) { + Options options; + DB* snapshotDB; + ReadOptions roptions; + std::string result; + Checkpoint* checkpoint; + + options = CurrentOptions(); + delete db_; + db_ = nullptr; + ASSERT_OK(DestroyDB(dbname_, options)); + + // Create a database + Status s; + options.create_if_missing = true; + ASSERT_OK(DB::Open(options, dbname_, &db_)); + std::string key = std::string("foo"); + ASSERT_OK(Put(key, "v1")); + // Take a snapshot + for (int i = 0; i < 10; i++) { + ASSERT_OK(Checkpoint::Create(db_, &checkpoint)); + std::string snap_shot = snapshot_name_; + snap_shot.push_back(('a' + i)); + ASSERT_OK(checkpoint->CreateCheckpoint(snap_shot, log_size_for_flush)); + ASSERT_OK(Put(key, "v1")); + ASSERT_EQ("v1", Get(key)); + ASSERT_OK(Flush()); + ASSERT_EQ("v1", Get(key)); + // Open snapshot and verify contents while DB is running + options.create_if_missing = false; + ASSERT_OK(DB::Open(options, snap_shot, &snapshotDB)); + ASSERT_OK(snapshotDB->Get(roptions, key, &result)); + ASSERT_EQ("v1", result); + delete snapshotDB; + snapshotDB = nullptr; + } + delete db_; + db_ = nullptr; + + // Destroy original DB + ASSERT_OK(DestroyDB(dbname_, options)); + + // Open snapshot and verify contents + options.create_if_missing = false; + dbname_ = snapshot_name_; + ASSERT_OK(DB::Open(options, dbname_, &db_)); + ASSERT_EQ("v1", Get(key)); + delete db_; + db_ = nullptr; + ASSERT_OK(DestroyDB(dbname_, options)); + delete checkpoint; + + // Restore DB name + dbname_ = test::PerThreadDBPath(env_, "db_test"); + } +} TEST_F(CheckpointTest, GetSnapshotLink) { for (uint64_t log_size_for_flush : {0, 1000000}) { Options options;