diff --git a/db/db_impl_secondary.cc b/db/db_impl_secondary.cc index 5dfa2d0c9..586158ef7 100644 --- a/db/db_impl_secondary.cc +++ b/db/db_impl_secondary.cc @@ -120,8 +120,6 @@ Status DBImplSecondary::FindNewLogNumbers(std::vector* logs) { return s; } -// try to find log reader using log_number from log_readers_ map, initialize -// if it doesn't exist Status DBImplSecondary::MaybeInitLogReader( uint64_t log_number, log::FragmentBufferedReader** log_reader) { auto iter = log_readers_.find(log_number); diff --git a/db/db_impl_secondary.h b/db/db_impl_secondary.h index 912708b1e..a57835432 100644 --- a/db/db_impl_secondary.h +++ b/db/db_impl_secondary.h @@ -13,6 +13,7 @@ namespace rocksdb { +// A wrapper class to hold log reader, log reporter, log status. class LogReaderContainer { public: LogReaderContainer() @@ -62,11 +63,19 @@ class LogReaderContainer { }; }; +// The secondary instance shares access to the storage as the primary. +// The secondary is able to read and replay changes described in both the +// MANIFEST and the WAL files without coordination with the primary. +// The secondary instance can be opened using `DB::OpenAsSecondary`. After +// that, it can call `DBImplSecondary::TryCatchUpWithPrimary` to make best +// effort attempts to catch up with the primary. class DBImplSecondary : public DBImpl { public: DBImplSecondary(const DBOptions& options, const std::string& dbname); ~DBImplSecondary() override; + // Recover by replaying MANIFEST and WAL. Also initialize manifest_reader_ + // and log_readers_ to facilitate future operations. Status Recover(const std::vector& column_families, bool read_only, bool error_if_log_file_exist, bool error_if_data_exists_in_logs) override; @@ -182,10 +191,15 @@ class DBImplSecondary : public DBImpl { // method can take long time due to all the I/O and CPU costs. Status TryCatchUpWithPrimary() override; + + // Try to find log reader using log_number from log_readers_ map, initialize + // if it doesn't exist Status MaybeInitLogReader(uint64_t log_number, log::FragmentBufferedReader** log_reader); protected: + // ColumnFamilyCollector is a write batch handler which does nothing + // except recording unique column family IDs class ColumnFamilyCollector : public WriteBatch::Handler { std::unordered_set column_family_ids_; @@ -262,6 +276,8 @@ class DBImplSecondary : public DBImpl { std::unordered_set* cfds_changed, JobContext* job_context); Status FindNewLogNumbers(std::vector* logs); + // After manifest recovery, replay WALs and refresh log_readers_ if necessary + // REQUIRES: log_numbers are sorted in ascending order Status RecoverLogFiles(const std::vector& log_numbers, SequenceNumber* next_sequence, std::unordered_set* cfds_changed,