Bedrock.Internal.TransactionBuilder.StorageRacing (bedrock v0.5.3)
View SourceStorage server racing and caching utilities.
This module provides infrastructure for racing multiple storage servers to find the fastest one and caching the results for future use.
The racing pattern allows any operation to be performed across multiple storage servers in parallel, returning the first successful result along with the winning server for future caching.
Summary
Functions
Race storage servers for a key, using caching transparently.
Functions
@spec race_storage_servers( state :: Bedrock.Internal.TransactionBuilder.State.t(), key :: binary(), operation_fn :: (pid(), Bedrock.version(), Bedrock.timeout_in_ms() -> {:ok, any()} | {:error, :not_found | :version_too_new} | {:failure, :timeout | :unavailable | :version_too_old, pid()}) ) :: {Bedrock.Internal.TransactionBuilder.State.t(), {:ok, {any(), Bedrock.key_range()}} | {:failure, %{required(atom()) => [pid()]}}}
Race storage servers for a key, using caching transparently.
Uses the key to determine the storage servers and check for cached fastest server. If no cached server exists, races all servers and caches the winner.
Parameters
key: The key to look up storage servers and cache bystate: Transaction builder state with layout and cacheoperation_fn: Function to run(pid(), Bedrock.version(), Bedrock.timeout_in_ms() -> {:ok, any()} | {:error, any()} | {:failure, atom(), pid()})
Returns
{:ok, {result, key_range}, updated_state}- Result with shard key range and potentially updated cache{:error, reason, state}- All servers failed or unavailable