db_impl_follower.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2024-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #pragma once
  6. #include <string>
  7. #include <vector>
  8. #include "db/db_impl/db_impl.h"
  9. #include "db/db_impl/db_impl_secondary.h"
  10. #include "logging/logging.h"
  11. #include "port/port.h"
  12. namespace ROCKSDB_NAMESPACE {
  13. class DBImplFollower : public DBImplSecondary {
  14. public:
  15. DBImplFollower(const DBOptions& db_options, std::unique_ptr<Env>&& env,
  16. const std::string& dbname, std::string src_path);
  17. ~DBImplFollower();
  18. Status Close() override;
  19. protected:
  20. bool OwnTablesAndLogs() const override {
  21. // TODO: Change this to true once we've properly implemented file
  22. // deletion for the read scaling case
  23. return true;
  24. }
  25. Status Recover(const std::vector<ColumnFamilyDescriptor>& column_families,
  26. bool /*readonly*/, bool /*error_if_wal_file_exists*/,
  27. bool /*error_if_data_exists_in_wals*/,
  28. bool /*is_retry*/ = false, uint64_t* = nullptr,
  29. RecoveryContext* /*recovery_ctx*/ = nullptr,
  30. bool* /*can_retry*/ = nullptr) override;
  31. private:
  32. friend class DB;
  33. Status TryCatchUpWithLeader();
  34. void PeriodicRefresh();
  35. std::unique_ptr<Env> env_guard_;
  36. std::unique_ptr<port::Thread> catch_up_thread_;
  37. std::atomic<bool> stop_requested_;
  38. std::string src_path_;
  39. port::Mutex mu_;
  40. port::CondVar cv_;
  41. std::unique_ptr<std::list<uint64_t>::iterator> pending_outputs_inserted_elem_;
  42. };
  43. } // namespace ROCKSDB_NAMESPACE