14#ifndef A11_NODES_NODE_MAP_H_
15#define A11_NODES_NODE_MAP_H_
23#include <absl/base/thread_annotations.h>
24#include <absl/container/flat_hash_map.h>
25#include <absl/status/status.h>
26#include <absl/status/statusor.h>
28#include "thread/boost_primitives.h"
41 std::function<absl::StatusOr<std::shared_ptr<stores::ChunkStore>>(
42 std::string node_id)>;
51class NodeMap :
public std::enable_shared_from_this<NodeMap> {
59 static absl::StatusOr<std::shared_ptr<NodeMap>>
Create(
68 absl::StatusOr<std::shared_ptr<AsyncNode>>
Get(std::string node_id);
75 absl::StatusOr<std::shared_ptr<AsyncNode>>
GetIfExists(
76 std::string_view node_id)
const;
85 absl::StatusOr<std::shared_ptr<AsyncNode>>
Discard(
86 std::string_view node_id,
87 const std::shared_ptr<AsyncNode>&
expected =
nullptr);
106 mutable thread::Mutex mu_;
107 absl::flat_hash_map<std::string, std::shared_ptr<AsyncNode>>
nodes_
108 ABSL_GUARDED_BY(mu_);
A thread-safe registry of AsyncNodes keyed by id.
Definition node_map.h:51
absl::StatusOr< std::shared_ptr< AsyncNode > > GetIfExists(std::string_view node_id) const
Return the node for an id without creating it.
Definition node_map.cc:82
absl::StatusOr< std::shared_ptr< AsyncNode > > Discard(std::string_view node_id, const std::shared_ptr< AsyncNode > &expected=nullptr)
Remove the node for an id.
Definition node_map.cc:94
static absl::StatusOr< std::shared_ptr< NodeMap > > Create(ChunkStoreFactory factory={})
Create a node map.
Definition node_map.cc:22
absl::StatusOr< std::shared_ptr< AsyncNode > > Get(std::string node_id)
Return the node for an id, creating it if it does not exist.
Definition node_map.cc:43
bool Contains(std::string_view node_id) const
Report whether a node with the given id exists.
Definition node_map.cc:110
size_t Size() const
Return the number of nodes currently in the map.
Definition node_map.cc:115
Abstract, pluggable backing store for the data of a node: an ordered, appendable log of fragments.
Definition chunk_store.h:53
std::function< absl::StatusOr< std::shared_ptr< stores::ChunkStore > >(std::string node_id)> ChunkStoreFactory
Callable invoked to construct the backing chunk store for a new node from its id.
Definition node_map.h:42
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30