Behavior¶
- class aerospike_sdk.policy.behavior.Behavior[source]¶
Bases:
objectImmutable, scope-aware configuration for Aerospike operation policies.
A Behavior holds a set of scope-keyed
Settingspatches that are resolved at operation time based on the operation’s kind, shape, and namespace mode. More-specific scopes override less-specific ones, and a child Behavior inherits from its parent.Resolved settings are eagerly cached at construction time so that
get_settings()is a simple dict lookup.Example:
# Use a pre-defined behavior session = cluster.create_session(Behavior.DEFAULT) # Derive a custom behavior with scope-specific overrides fast = Behavior.DEFAULT.derive_with_changes( "fast_reads", reads=Settings(total_timeout=timedelta(milliseconds=200)), reads_batch=Settings(max_concurrent_nodes=8), ) session = cluster.create_session(fast)
- DEFAULT¶
Balanced defaults (1 s total / 30 s socket timeout, 2 retries; queries and background ops carry their own timeouts).
- READ_FAST¶
Low-latency reads (200 ms total, 50 ms socket, 3 retries).
- STRICTLY_CONSISTENT¶
SC-namespace reads with linearizable consistency.
- FAST_RACK_AWARE¶
Low-latency rack-preferred reads.
- STRICTLY_CONSISTENT: ClassVar[Behavior] = <Behavior 'STRICTLY_CONSISTENT' parent='DEFAULT' patches=1>¶
- property children: List[Behavior]¶
Behaviors derived from this one via
derive_with_changes().
- get_settings(kind, shape, mode=Mode.AP)[source]¶
Return the fully-resolved Settings for the given operation context.
This is a cached O(1) dict lookup; the matrix is pre-computed at construction time.
- Return type:
- get_txn_verify_settings()[source]¶
Return the resolved settings for the transaction verify phase.
The verify phase re-reads every record a transaction touched to confirm its version before commit. Its shape and mode are fixed by the protocol (a batch of reads against a strong-consistency namespace), so the cell resolves from the
ALLscope plus thesystem_txn_verifyscope, layered through the parent chain.This is a cached O(1) dict lookup, like
get_settings().- Return type:
- Returns:
The fully-resolved
Settingsfor the verify phase.
Example:
patient_commits = Behavior.DEFAULT.derive_with_changes( "patient_commits", system_txn_verify=Settings(total_timeout=timedelta(seconds=30)), ) verify = patient_commits.get_txn_verify_settings()
See also
get_txn_roll_settings(): The roll (commit/abort) phase.
- get_txn_roll_settings()[source]¶
Return the resolved settings for the transaction roll phase.
The roll phase moves every record a transaction touched forward on commit or back on abort. Like verify, its shape and mode are fixed by the protocol (a batch of writes against a strong-consistency namespace), so the cell resolves from the
ALLscope plus thesystem_txn_rollscope, layered through the parent chain.This is a cached O(1) dict lookup, like
get_settings().- Return type:
- Returns:
The fully-resolved
Settingsfor the roll phase.
See also
get_txn_verify_settings(): The pre-commit verify phase.
- clear_cache()[source]¶
Recompute the resolved settings matrix and cascade to children.
Live sessions bound to this behavior have their cached policies rebuilt and swapped in, so settings changes reach them without any per-operation check.
- Return type:
- derive_with_changes(name, *, all=None, reads=None, reads_point=None, reads_batch=None, reads_query=None, reads_ap=None, reads_sc=None, writes=None, writes_retryable=None, writes_non_retryable=None, writes_point=None, writes_batch=None, writes_query=None, writes_ap=None, writes_sc=None, system_txn_verify=None, system_txn_roll=None)[source]¶
Create a child Behavior with the specified overrides.
Each keyword names the operations its
Settingsapply to.allcovers every operation; narrower scopes such asreadsorwrites_scoverride it for their operations. Fields left unset inherit from this behavior.Example:
from datetime import timedelta from aerospike_sdk.policy import Settings fast_reads = Behavior.DEFAULT.derive_with_changes( "fast_reads", all=Settings(max_retries=1), reads=Settings(total_timeout=timedelta(milliseconds=200)), )
- Parameters:
name (
str) – Name of the new behavior.reads (
Optional[Settings]) – Settings for all reads;reads_point,reads_batch,reads_query,reads_ap, andreads_scnarrow that by shape or consistency mode.writes (
Optional[Settings]) – Settings for all writes;writes_retryable,writes_non_retryable,writes_point,writes_batch,writes_query,writes_ap, andwrites_scnarrow that by retryability, shape, or consistency mode.system_txn_verify (
Optional[Settings]) – Settings for transaction verify commands.system_txn_roll (
Optional[Settings]) – Settings for transaction roll-forward and roll-back commands.
- Return type:
- Returns:
A new
Behaviorwhose parent is this behavior.
See also
get_settings(): Resolve the effective settings for an operation.
Behavior Settings¶
Settings and scope types for the Behavior model.
- class aerospike_sdk.policy.behavior_settings.OpKind[source]¶
Bases:
EnumThe kind of database operation.
- READ = 'read'¶
- WRITE_RETRYABLE = 'write_retryable'¶
- WRITE_NON_RETRYABLE = 'write_non_retryable'¶
- class aerospike_sdk.policy.behavior_settings.OpShape[source]¶
Bases:
EnumThe shape (cardinality) of the operation.
- POINT = 'point'¶
- BATCH = 'batch'¶
- QUERY = 'query'¶
- class aerospike_sdk.policy.behavior_settings.Mode[source]¶
Bases:
EnumNamespace consistency mode.
- AP = 'ap'¶
- SC = 'sc'¶
- class aerospike_sdk.policy.behavior_settings.Scope[source]¶
Bases:
EnumNamed scopes for configuring operation settings within a Behavior.
Scope values correspond to keyword arguments accepted by
Behavior.derive_with_changes().- ALL = 'all'¶
- READS = 'reads'¶
- READS_POINT = 'reads_point'¶
- READS_BATCH = 'reads_batch'¶
- READS_QUERY = 'reads_query'¶
- READS_AP = 'reads_ap'¶
- READS_SC = 'reads_sc'¶
- WRITES = 'writes'¶
- WRITES_RETRYABLE = 'writes_retryable'¶
- WRITES_NON_RETRYABLE = 'writes_non_retryable'¶
- WRITES_POINT = 'writes_point'¶
- WRITES_BATCH = 'writes_batch'¶
- WRITES_QUERY = 'writes_query'¶
- WRITES_AP = 'writes_ap'¶
- WRITES_SC = 'writes_sc'¶
- SYSTEM_TXN_VERIFY = 'system_txn_verify'¶
- SYSTEM_TXN_ROLL = 'system_txn_roll'¶
- class aerospike_sdk.policy.behavior_settings.Settings[source]¶
Bases:
objectImmutable set of operation settings.
All fields are Optional;
Nonemeans “not configured / inherit from a less-specific scope or the parent Behavior”.- classmethod merge(base, override)[source]¶
Merge two Settings; override’s non-None fields win.
- Return type:
- __init__(*, total_timeout=None, socket_timeout=None, timeout_delay=None, max_retries=None, retry_delay=None, send_key=None, durable_delete=None, commit_level=None, replica=None, read_mode_ap=None, read_mode_sc=None, use_compression=None, compression_threshold=None, max_concurrent_nodes=None, record_queue_size=None, allow_scans_with_where=None, allow_inline=None, allow_inline_ssd=None, read_touch_ttl_percent=None, error_detail_verbosity=None)¶