28#ifndef A11_NODES_NODE_MAP_H_
29#define A11_NODES_NODE_MAP_H_
39#include <absl/base/thread_annotations.h>
40#include <absl/container/flat_hash_map.h>
41#include <absl/status/status.h>
42#include <absl/status/statusor.h>
61 std::function<absl::StatusOr<std::shared_ptr<stores::ChunkStore>>(
62 std::string node_id)>;
71class NodeMap :
public std::enable_shared_from_this<NodeMap> {
79 static absl::StatusOr<std::shared_ptr<NodeMap>>
Create(
81 std::optional<data::StorageIdentity>
storage = {});
97 absl::StatusOr<std::shared_ptr<AsyncNode>>
Get(std::string node_id);
104 absl::StatusOr<std::shared_ptr<AsyncNode>>
GetIfExists(
105 std::string_view node_id)
const;
109 std::shared_ptr<NodeMap>
storage);
112 [[nodiscard]]
const std::optional<data::StorageIdentity>&
Storage()
const {
118 std::vector<std::string> accessible_ids = {});
120 [[nodiscard]] std::vector<std::string>
StorageIds()
const;
127 absl::StatusOr<std::shared_ptr<AsyncNode>>
Resolve(
135 const data::NodeRef& reference,
const std::shared_ptr<NodeMap>& source);
144 absl::StatusOr<std::shared_ptr<AsyncNode>>
Discard(
145 std::string_view node_id,
146 const std::shared_ptr<AsyncNode>& expected =
nullptr);
153 [[nodiscard]]
bool Contains(std::string_view node_id)
const;
159 [[nodiscard]]
size_t Size()
const;
169 [[nodiscard]] std::vector<std::string>
Ids()
const;
173 std::optional<data::StorageIdentity>
storage);
175 absl::Status Insert(
const std::shared_ptr<AsyncNode>&
node);
178 const std::optional<data::StorageIdentity> storage_;
181 std::vector<std::string> accessible_ids_ ABSL_GUARDED_BY(mu_);
182 bool allow_lazy_read_resolution_ ABSL_GUARDED_BY(mu_) =
false;
183 absl::flat_hash_map<std::string, std::shared_ptr<NodeMap>> storages_
184 ABSL_GUARDED_BY(mu_);
186 std::string, absl::flat_hash_map<std::string, std::shared_ptr<AsyncNode>>>
187 imported_ ABSL_GUARDED_BY(mu_);
188 absl::flat_hash_map<std::string, std::shared_ptr<AsyncNode>> nodes_
189 ABSL_GUARDED_BY(mu_);
190 absl::flat_hash_map<std::string, std::shared_ptr<AsyncNode>> retained_refs_
191 ABSL_GUARDED_BY(mu_);
A thread-safe registry of AsyncNodes keyed by id.
Definition node_map.h:71
absl::StatusOr< std::shared_ptr< AsyncNode > > ImportReference(const data::NodeRef &reference, const std::shared_ptr< NodeMap > &source)
Share a referenced node from another scope, preserving its identity.
Definition node_map.cc:299
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:109
static absl::StatusOr< std::shared_ptr< NodeMap > > Create(ChunkStoreFactory factory={}, std::optional< data::StorageIdentity > storage={})
Create a node map.
Definition node_map.cc:45
absl::Status SetStorageResolver(StorageResolver resolver, std::vector< std::string > accessible_ids={})
Adopt host connection policy; advertised ids must be directly accessible.
Definition node_map.cc:149
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:360
bool AllowsLazyReadResolution() const
Definition node_map.cc:127
void SetAllowLazyReadResolution(bool allowed)
Permit read resolution to open uncached nodes through this map's factory.
Definition node_map.cc:122
std::vector< std::string > StorageIds() const
Storage identities directly accessible through this host's resolver.
Definition node_map.cc:164
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:71
absl::Status RegisterStorage(std::string storage_id, std::shared_ptr< NodeMap > storage)
Configure a host-accessible namespace and its backend node map.
Definition node_map.cc:133
bool Contains(std::string_view node_id) const
Report whether a node with the given id exists.
Definition node_map.cc:374
std::vector< std::string > Ids() const
Return the id of every node the map holds, sorted.
Definition node_map.cc:384
size_t Size() const
Return the number of nodes currently in the map.
Definition node_map.cc:379
absl::StatusOr< std::shared_ptr< AsyncNode > > ResolveForRead(const data::NodeRef &reference)
Resolve an existing local target for a value read.
Definition node_map.cc:235
absl::StatusOr< std::shared_ptr< AsyncNode > > Resolve(const data::NodeRef &reference)
Resolve a whole-node reference; windows require a fragment-window reader.
Definition node_map.cc:178
const std::optional< data::StorageIdentity > & Storage() const
Identity of this map's backend, or absent for session-local storage.
Definition node_map.h:112
Abstract, pluggable backing store for the data of a node: an ordered, appendable log of fragments.
Definition chunk_store.h:67
Definition boost_primitives.h:21
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:62
std::function< absl::StatusOr< std::shared_ptr< NodeMap > >(data::StorageIdentity)> StorageResolver
Definition node_map.h:56
graph::RefId node
Graph ref for this result, or [graph::kNone] without a resolved ref.
Definition resolve.cc:809
int storage
Definition sqlite_chunk_store.cc:189
A reference to a (slice of a) logical node, in lieu of inline data.
Definition types.h:311
Logical namespace with optional host-interpreted backend access information.
Definition types.h:290
A11's core wire value types: chunks, node fragments and messages.