From 3969958f2c66fe76d0110386b7c0691dc8a12b48 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Thu, 6 Mar 2025 13:58:57 +0000 Subject: [PATCH 1/4] Protect access to strategies collection --- include/ccf/indexing/indexer_interface.h | 5 +++++ 1 file changed, 5 insertions(+) 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) From a57bfef95926e24138ce1061138f8bdacf0eb5f4 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Thu, 6 Mar 2025 14:00:29 +0000 Subject: [PATCH 2/4] Lock in derived class --- src/indexing/indexer.h | 3 +++ 1 file changed, 3 insertions(+) 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(); From 9c27e034fb9e47a6a627b3fb31b562be1a6465cc Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Thu, 6 Mar 2025 14:01:10 +0000 Subject: [PATCH 3/4] Lock max_requested_seqno in LazyStrategy --- include/ccf/indexing/strategy.h | 4 ++++ 1 file changed, 4 insertions(+) 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; From 3789b440a4e671690bbf6a8f8e712817de3ac7a8 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 10 Mar 2025 10:03:47 +0000 Subject: [PATCH 4/4] Hmm --- include/ccf/indexing/indexer_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ccf/indexing/indexer_interface.h b/include/ccf/indexing/indexer_interface.h index 08474072ba21..58cb70f75afa 100644 --- a/include/ccf/indexing/indexer_interface.h +++ b/include/ccf/indexing/indexer_interface.h @@ -53,7 +53,7 @@ namespace ccf::indexing strategies.erase(strategy); } - nlohmann::json describe() const + nlohmann::json describe() { std::lock_guard guard(lock); auto j = nlohmann::json::array();