CCF
Loading...
Searching...
No Matches
seqnos_by_key_in_memory.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6#include "ccf/pal/locking.h"
8
10{
11 // A simple Strategy which stores one large map in-memory
13 {
14 protected:
15 // Key is the raw value of a KV key.
16 // Value is every SeqNo which talks about that key.
17 std::unordered_map<ccf::ByteVector, SeqNoCollection> seqnos_by_key;
18
19 // Mutex guarding access to seqnos_by_key
21
22 void visit_entry(
23 const ccf::TxID& tx_id,
24 const ccf::ByteVector& k,
25 const ccf::ByteVector& v) override;
26
27 std::optional<SeqNoCollection> get_write_txs_impl(
28 const ccf::ByteVector& serialised_key,
29 ccf::SeqNo from,
30 ccf::SeqNo to,
31 std::optional<size_t> max_seqnos = std::nullopt);
32
33 public:
34 SeqnosByKey_InMemory_Untyped(const std::string& map_name_) :
35 VisitEachEntryInMap(map_name_, "SeqnosByKey")
36 {}
37 };
38
39 template <typename M>
41 {
42 public:
46
47 std::optional<SeqNoCollection> get_write_txs_in_range(
48 const typename M::Key& key,
49 ccf::SeqNo from,
50 ccf::SeqNo to,
51 std::optional<size_t> max_seqnos = std::nullopt)
52 {
53 if (to < from)
54 {
55 throw std::logic_error(
56 fmt::format("Range goes backwards: {} -> {}", from, to));
57 }
58
59 if (to > current_txid.seqno)
60 {
61 // If the requested range hasn't been populated yet, indicate
62 // that with nullopt
63 return std::nullopt;
64 }
65
66 return get_write_txs_impl(
67 M::KeySerialiser::to_serialised(key), from, to, max_seqnos);
68 }
69
70 std::optional<SeqNoCollection> get_all_write_txs(const typename M::Key& key)
71 {
72 std::lock_guard<ccf::pal::Mutex> guard(current_txid_lock);
74 }
75 };
76}
std::string get_name() const
Definition strategy.h:31
Definition seqnos_by_key_in_memory.h:13
ccf::pal::Mutex lock
Definition seqnos_by_key_in_memory.h:20
std::optional< SeqNoCollection > get_write_txs_impl(const ccf::ByteVector &serialised_key, ccf::SeqNo from, ccf::SeqNo to, std::optional< size_t > max_seqnos=std::nullopt)
Definition seqnos_by_key_in_memory.cpp:19
std::unordered_map< ccf::ByteVector, SeqNoCollection > seqnos_by_key
Definition seqnos_by_key_in_memory.h:17
SeqnosByKey_InMemory_Untyped(const std::string &map_name_)
Definition seqnos_by_key_in_memory.h:34
void visit_entry(const ccf::TxID &tx_id, const ccf::ByteVector &k, const ccf::ByteVector &v) override
Definition seqnos_by_key_in_memory.cpp:10
Definition seqnos_by_key_in_memory.h:41
std::optional< SeqNoCollection > get_write_txs_in_range(const typename M::Key &key, ccf::SeqNo from, ccf::SeqNo to, std::optional< size_t > max_seqnos=std::nullopt)
Definition seqnos_by_key_in_memory.h:47
SeqnosByKey_InMemory(const M &map)
Definition seqnos_by_key_in_memory.h:43
std::optional< SeqNoCollection > get_all_write_txs(const typename M::Key &key)
Definition seqnos_by_key_in_memory.h:70
Definition visit_each_entry_in_map.h:15
ccf::TxID current_txid
Definition visit_each_entry_in_map.h:22
ccf::pal::Mutex current_txid_lock
Definition visit_each_entry_in_map.h:20
Definition seqnos_by_key_bucketed.h:10
std::mutex Mutex
Definition locking.h:12
llvm_vecsmall::SmallVector< uint8_t, 8 > ByteVector
Definition byte_vector.h:14
uint64_t SeqNo
Definition tx_id.h:36
Definition map_serializers.h:11
Definition tx_id.h:44
SeqNo seqno
Definition tx_id.h:46