forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic RocksDB follower implementation (facebook#12540)
Summary: A basic implementation of RocksDB follower mode, which opens a remote database (referred to as leader) on a distributed file system by tailing its MANIFEST. It leverages the secondary instance mode, but is different in some key ways - 1. It has its own directory with links to the leader's database 2. Periodically refreshes itself 3. (Future) Snapshot support 4. (Future) Garbage collection of obsolete links 5. (Long term) Memtable replication There are two main classes implementing this functionality - `DBImplFollower` and `OnDemandFileSystem`. The former is derived from `DBImplSecondary`. Similar to `DBImplSecondary`, it implements recovery and catch up through MANIFEST tailing using the `ReactiveVersionSet`, but does not consider logs. In a future PR, we will implement memtable replication, which will eliminate the need to catch up using logs. In addition, the recovery and catch-up tries to avoid directory listing as repeated metadata operations are expensive. The second main piece is the `OnDemandFileSystem`, which plugs in as an `Env` for the follower instance and creates the illusion of the follower directory as a clone of the leader directory. It creates links to SSTs on first reference. When the follower tails the MANIFEST and attempts to create a new `Version`, it calls `VerifyFileMetadata` to verify the size of the file, and optionally the unique ID of the file. During this process, links are created which prevent the underlying files from getting deallocated even if the leader deletes the files. TODOs: Deletion of obsolete links, snapshots, robust checking against misconfigurations, better observability etc. Pull Request resolved: facebook#12540 Reviewed By: jowlyzhang Differential Revision: D56315718 Pulled By: anand1976 fbshipit-source-id: d19e1aca43a6af4000cb8622a718031b69ebd97b
- Loading branch information
1 parent
f0864d3
commit d8fb849
Showing
17 changed files
with
1,009 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
|
||
#include "db/db_test_util.h" | ||
#include "port/stack_trace.h" | ||
#include "test_util/sync_point.h" | ||
|
||
namespace ROCKSDB_NAMESPACE { | ||
|
||
#ifdef OS_LINUX | ||
|
||
class DBFollowerTest : public DBTestBase { | ||
public: | ||
// Create directories for leader and follower | ||
// Create the leader DB object | ||
DBFollowerTest() : DBTestBase("/db_follower_test", /*env_do_fsync*/ false) { | ||
follower_name_ = dbname_ + "/follower"; | ||
Close(); | ||
Destroy(CurrentOptions()); | ||
EXPECT_EQ(env_->CreateDirIfMissing(dbname_), Status::OK()); | ||
dbname_ = dbname_ + "/leader"; | ||
Reopen(CurrentOptions()); | ||
} | ||
|
||
~DBFollowerTest() { | ||
follower_.reset(); | ||
EXPECT_EQ(DestroyDB(follower_name_, CurrentOptions()), Status::OK()); | ||
} | ||
|
||
protected: | ||
Status OpenAsFollower() { | ||
return DB::OpenAsFollower(CurrentOptions(), follower_name_, dbname_, | ||
&follower_); | ||
} | ||
DB* follower() { return follower_.get(); } | ||
|
||
private: | ||
std::string follower_name_; | ||
std::unique_ptr<DB> follower_; | ||
}; | ||
|
||
TEST_F(DBFollowerTest, Basic) { | ||
ASSERT_OK(Put("k1", "v1")); | ||
ASSERT_OK(Flush()); | ||
ASSERT_OK(Put("k2", "v2")); | ||
ASSERT_OK(Flush()); | ||
|
||
ASSERT_OK(OpenAsFollower()); | ||
std::string val; | ||
ASSERT_OK(follower()->Get(ReadOptions(), "k1", &val)); | ||
ASSERT_EQ(val, "v1"); | ||
} | ||
|
||
#endif | ||
} // namespace ROCKSDB_NAMESPACE | ||
|
||
int main(int argc, char** argv) { | ||
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler(); | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.