Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/ccf/indexing/indexer_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ccf/indexing/strategy.h"
#include "ccf/node_subsystem_interface.h"
#include "ccf/pal/locking.h"

#include <map>
#include <memory>
Expand All @@ -19,6 +20,7 @@ namespace ccf::indexing
class IndexingStrategies : public ccf::AbstractNodeSubSystem
{
protected:
ccf::pal::Mutex lock;
std::set<StrategyPtr> strategies;

public:
Expand All @@ -36,11 +38,13 @@ namespace ccf::indexing
throw std::logic_error("Tried to install null strategy");
}

std::lock_guard<ccf::pal::Mutex> guard(lock);
return strategies.insert(strategy).second;
}

void uninstall_strategy(const StrategyPtr& strategy)
{
std::lock_guard<ccf::pal::Mutex> guard(lock);
if (strategy == nullptr || strategies.find(strategy) == strategies.end())
{
throw std::logic_error("Strategy doesn't exist");
Expand All @@ -49,8 +53,9 @@ namespace ccf::indexing
strategies.erase(strategy);
}

nlohmann::json describe() const
nlohmann::json describe()
{
std::lock_guard<ccf::pal::Mutex> guard(lock);
auto j = nlohmann::json::array();

for (const auto& strategy : strategies)
Expand Down
4 changes: 4 additions & 0 deletions include/ccf/indexing/strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "ccf/kv/read_only_store.h"
#include "ccf/pal/locking.h"
#include "ccf/tx_id.h"

#include <optional>
Expand Down Expand Up @@ -68,6 +69,7 @@ namespace ccf::indexing
class LazyStrategy : public Base
{
protected:
ccf::pal::Mutex lock;
ccf::SeqNo max_requested_seqno = 0;

public:
Expand All @@ -78,6 +80,7 @@ namespace ccf::indexing
const auto base = Base::next_requested();
if (base.has_value())
{
std::lock_guard<ccf::pal::Mutex> guard(lock);
if (*base <= max_requested_seqno)
{
return base;
Expand All @@ -89,6 +92,7 @@ namespace ccf::indexing

void extend_index_to(ccf::TxID to_txid)
{
std::lock_guard<ccf::pal::Mutex> guard(lock);
if (to_txid.seqno > max_requested_seqno)
{
max_requested_seqno = to_txid.seqno;
Expand Down
3 changes: 3 additions & 0 deletions src/indexing/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ namespace ccf::indexing
update_commit(newly_committed);

std::optional<ccf::SeqNo> min_requested = std::nullopt;

std::lock_guard<ccf::pal::Mutex> guard(lock);

for (auto& strategy : strategies)
{
strategy->tick();
Expand Down