#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace xrpl::NodeStore { class DatabaseRotatingImp : public DatabaseRotating { public: DatabaseRotatingImp() = delete; DatabaseRotatingImp(DatabaseRotatingImp const&) = delete; DatabaseRotatingImp& operator=(DatabaseRotatingImp const&) = delete; DatabaseRotatingImp( Scheduler& scheduler, int readThreads, std::shared_ptr writableBackend, std::shared_ptr archiveBackend, Section const& config, beast::Journal j); ~DatabaseRotatingImp() override { stop(); } void rotate( std::unique_ptr&& newBackend, std::function const& f) override; std::string getName() const override; std::int32_t getWriteLoad() const override; void importDatabase(Database& source) override; bool isSameDB(std::uint32_t, std::uint32_t) override { // rotating store acts as one logical database return true; } void store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t) override; void sync() override; void sweep() override; void setRotationInFlight(bool inFlight) override; private: std::shared_ptr writableBackend_; std::shared_ptr archiveBackend_; mutable std::mutex mutex_; // True between SHAMapStore starting the cache-freshen phase and the // completion of rotate(). While true, archive hits on ordinary // (duplicate == false) fetches are copied forward into the writable // backend; copyForwardCount_ tallies them per rotation for the // summary line logged at swap. std::atomic rotationInFlight_{false}; std::atomic copyForwardCount_{0}; std::shared_ptr fetchNodeObject(uint256 const& hash, std::uint32_t, FetchReport& fetchReport, bool duplicate) override; void forEach(std::function)> f) override; }; } // namespace xrpl::NodeStore