Bedrock.Internal.TransactionBuilder.Tx (bedrock v0.5.2)
View SourceOpaque transaction type for building and committing database operations.
This module provides an immutable transaction structure that accumulates reads, writes, and range operations. Transactions can be committed to produce the final mutation list and conflict ranges for resolution.
Summary
Functions
Add a single key read conflict to the transaction.
Add a read conflict range to the transaction.
Add a single key write conflict to the transaction.
Add a write conflict range to the transaction.
Merge storage range read results into the transaction state for conflict tracking.
Enhanced version of merge_storage_range_with_writes that handles pending writes correctly based on shard boundaries and has_more flag.
Merge a storage read result into the transaction state for conflict tracking.
Get the repeatable read value for a key within the transaction.
Types
@type key() :: binary()
@type t() :: %Bedrock.Internal.TransactionBuilder.Tx{ mutations: [mutation()], range_reads: [range()], range_writes: [range()], reads: %{required(key()) => value() | :clear}, writes: :gb_trees.tree( key(), value() | :clear | {:add, binary()} | {:min, binary()} | {:max, binary()} | {:bit_and, binary()} | {:bit_or, binary()} | {:bit_xor, binary()} | {:byte_min, binary()} | {:byte_max, binary()} | {:append_if_fits, binary()} | {:compare_and_clear, binary()} ) }
@type value() :: binary()
Functions
Add a single key read conflict to the transaction.
This is a convenience function that adds a read conflict for a single key by converting it to a single-key range (key to Key.key_after(key)).
Parameters
t- The transactionkey- The key to add as a read conflict
Examples
iex> tx = Tx.new()
iex> tx = Tx.add_read_conflict_key(tx, "my_key")
iex> tx.range_reads
[{"my_key", "my_key\0"}]
Add a read conflict range to the transaction.
This function adds the specified range to the transaction's read conflict tracking. Overlapping and adjacent ranges are automatically merged for efficiency.
Parameters
t- The transactionstart_key- The inclusive start key of the rangeend_key- The exclusive end key of the range
Examples
iex> tx = Tx.new()
iex> tx = Tx.add_read_conflict_range(tx, "a", "z")
iex> tx.range_reads
[{"a", "z"}]
iex> tx = Tx.new()
iex> tx = Tx.add_read_conflict_range(tx, "a", "m")
iex> tx = Tx.add_read_conflict_range(tx, "k", "z")
iex> tx.range_reads
[{"a", "z"}]
Add a single key write conflict to the transaction.
This is a convenience function that adds a write conflict for a single key by converting it to a single-key range (key to Key.key_after(key)).
Parameters
t- The transactionkey- The key to add as a write conflict
Examples
iex> tx = Tx.new()
iex> tx = Tx.add_write_conflict_key(tx, "my_key")
iex> tx.range_writes
[{"my_key", "my_key\0"}]
Add a write conflict range to the transaction.
This function adds the specified range to the transaction's write conflict tracking. Overlapping and adjacent ranges are automatically merged for efficiency.
Parameters
t- The transactionstart_key- The inclusive start key of the rangeend_key- The exclusive end key of the range
Examples
iex> tx = Tx.new()
iex> tx = Tx.add_write_conflict_range(tx, "a", "z")
iex> tx.range_writes
[{"a", "z"}]
iex> tx = Tx.new()
iex> tx = Tx.add_write_conflict_range(tx, "a", "m")
iex> tx = Tx.add_write_conflict_range(tx, "k", "z")
iex> tx.range_writes
[{"a", "z"}]
@spec commit(t(), Bedrock.version() | nil) :: Bedrock.DataPlane.Transaction.encoded()
Merge storage range read results into the transaction state for conflict tracking.
This function is used after KeySelector range resolution to merge resolved keys and values into the transaction's read state, and add the range to range_reads.
@spec merge_storage_range_with_writes( t(), [{key(), value()}], has_more :: boolean(), query_range :: {key(), key()}, shard_range :: Bedrock.key_range() ) :: {t(), [{key(), value()}]}
Enhanced version of merge_storage_range_with_writes that handles pending writes correctly based on shard boundaries and has_more flag.
When has_more = false, this indicates the storage server has given us all data in its authoritative range, so we should include pending writes beyond the storage results up to the boundary of the query range and shard range.
Merge a storage read result into the transaction state for conflict tracking.
This function is used after KeySelector resolution to merge the resolved key and value into the transaction's read state, ensuring proper conflict detection.
@spec new() :: t()
Get the repeatable read value for a key within the transaction.
Checks both writes and reads, returning the value if the key has been accessed in this transaction, or nil if the key is unknown to the transaction. This ensures repeatable read semantics - the same key returns the same value throughout the transaction.