diff --git a/include/ccf/indexing/indexer_interface.h b/include/ccf/indexing/indexer_interface.h index add86f3963d3..08474072ba21 100644 --- a/include/ccf/indexing/indexer_interface.h +++ b/include/ccf/indexing/indexer_interface.h @@ -4,6 +4,7 @@ #include "ccf/indexing/strategy.h" #include "ccf/node_subsystem_interface.h" +#include "ccf/pal/locking.h" #include #include @@ -19,6 +20,7 @@ namespace ccf::indexing class IndexingStrategies : public ccf::AbstractNodeSubSystem { protected: + ccf::pal::Mutex lock; std::set strategies; public: @@ -36,11 +38,13 @@ namespace ccf::indexing throw std::logic_error("Tried to install null strategy"); } + std::lock_guard guard(lock); return strategies.insert(strategy).second; } void uninstall_strategy(const StrategyPtr& strategy) { + std::lock_guard guard(lock); if (strategy == nullptr || strategies.find(strategy) == strategies.end()) { throw std::logic_error("Strategy doesn't exist"); @@ -51,6 +55,7 @@ namespace ccf::indexing nlohmann::json describe() const { + std::lock_guard guard(lock); auto j = nlohmann::json::array(); for (const auto& strategy : strategies) diff --git a/include/ccf/indexing/strategy.h b/include/ccf/indexing/strategy.h index 1d29483adb64..5f8c95f9b5a8 100644 --- a/include/ccf/indexing/strategy.h +++ b/include/ccf/indexing/strategy.h @@ -3,6 +3,7 @@ #pragma once #include "ccf/kv/read_only_store.h" +#include "ccf/pal/locking.h" #include "ccf/tx_id.h" #include @@ -68,6 +69,7 @@ namespace ccf::indexing class LazyStrategy : public Base { protected: + ccf::pal::Mutex lock; ccf::SeqNo max_requested_seqno = 0; public: @@ -78,6 +80,7 @@ namespace ccf::indexing const auto base = Base::next_requested(); if (base.has_value()) { + std::lock_guard guard(lock); if (*base <= max_requested_seqno) { return base; @@ -89,6 +92,7 @@ namespace ccf::indexing void extend_index_to(ccf::TxID to_txid) { + std::lock_guard guard(lock); if (to_txid.seqno > max_requested_seqno) { max_requested_seqno = to_txid.seqno; diff --git a/src/indexing/indexer.h b/src/indexing/indexer.h index a98e583495b5..bf1b6dff2064 100644 --- a/src/indexing/indexer.h +++ b/src/indexing/indexer.h @@ -68,6 +68,9 @@ namespace ccf::indexing update_commit(newly_committed); std::optional min_requested = std::nullopt; + + std::lock_guard guard(lock); + for (auto& strategy : strategies) { strategy->tick();