Behavior

class aerospike_sdk.policy.behavior.Behavior[source]

Bases: object

Immutable, scope-aware configuration for Aerospike operation policies.

A Behavior holds a set of scope-keyed Settings patches 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.

DEFAULT: ClassVar[Behavior] = <Behavior 'DEFAULT' patches=10 children=2>
READ_FAST: ClassVar[Behavior] = <Behavior 'READ_FAST' parent='DEFAULT' patches=1 children=1>
STRICTLY_CONSISTENT: ClassVar[Behavior] = <Behavior 'STRICTLY_CONSISTENT' parent='DEFAULT' patches=1>
FAST_RACK_AWARE: ClassVar[Behavior] = <Behavior 'FAST_RACK_AWARE' parent='READ_FAST' patches=2>
__init__(name, patches, parent=None)[source]
property name: str

Identifier for this behavior (for example 'DEFAULT').

property parent: Behavior | None

Behavior from which this one inherits, or None for root.

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:

Settings

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 ALL scope plus the system_txn_verify scope, layered through the parent chain.

This is a cached O(1) dict lookup, like get_settings().

Return type:

Settings

Returns:

The fully-resolved Settings for 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 ALL scope plus the system_txn_roll scope, layered through the parent chain.

This is a cached O(1) dict lookup, like get_settings().

Return type:

Settings

Returns:

The fully-resolved Settings for 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:

None

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 Settings apply to. all covers every operation; narrower scopes such as reads or writes_sc override 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.

  • all (Optional[Settings]) – Settings for every operation.

  • reads (Optional[Settings]) – Settings for all reads; reads_point, reads_batch, reads_query, reads_ap, and reads_sc narrow 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, and writes_sc narrow 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:

Behavior

Returns:

A new Behavior whose parent is this behavior.

See also

get_settings(): Resolve the effective settings for an operation.

find_behavior(name)[source]

Search this behavior and its descendants for one with name.

Return type:

Optional[Behavior]

Returns:

The matching Behavior, or None if not found.

explain()[source]

Return a human-readable summary of overrides and resolved settings.

Example:

print(behavior.explain())
Return type:

str

Returns:

Multi-line string with overrides and the full resolved settings matrix.

Behavior Settings

Settings and scope types for the Behavior model.

class aerospike_sdk.policy.behavior_settings.OpKind[source]

Bases: Enum

The 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: Enum

The shape (cardinality) of the operation.

POINT = 'point'
BATCH = 'batch'
QUERY = 'query'
class aerospike_sdk.policy.behavior_settings.Mode[source]

Bases: Enum

Namespace consistency mode.

AP = 'ap'
SC = 'sc'
class aerospike_sdk.policy.behavior_settings.Scope[source]

Bases: Enum

Named 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: object

Immutable set of operation settings.

All fields are Optional; None means “not configured / inherit from a less-specific scope or the parent Behavior”.

total_timeout: timedelta | None = None
socket_timeout: timedelta | None = None
timeout_delay: timedelta | None = None
max_retries: int | None = None
retry_delay: timedelta | None = None
send_key: bool | None = None
durable_delete: bool | None = None
commit_level: CommitLevel | None = None
replica: Replica | None = None
read_mode_ap: ReadModeAP | None = None
read_mode_sc: ReadModeSC | None = None
use_compression: bool | None = None
compression_threshold: int | None = None
max_concurrent_nodes: int | None = None
record_queue_size: int | None = None
allow_scans_with_where: bool | None = None
allow_inline: bool | None = None
allow_inline_ssd: bool | None = None
read_touch_ttl_percent: int | None = None
error_detail_verbosity: int | None = None
classmethod merge(base, override)[source]

Merge two Settings; override’s non-None fields win.

Return type:

Settings

__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)
aerospike_sdk.policy.behavior_settings.resolution_order(kind, shape, mode=Mode.AP)[source]

Return applicable scopes from least-specific to most-specific.

Used by Behavior.get_settings() to layer patches so that more-specific scopes override less-specific ones.

Return type:

tuple[Scope, ...]