IndexesMonitor

class aerospike_sdk.index_monitor.IndexesMonitor[source]

Bases: object

Daemon-thread background monitor that caches secondary index metadata.

Matches the JSDK IndexesMonitor design: a single daemon thread polls the cluster’s info APIs at a fixed interval and refreshes an in-memory cache. Readers (sync or async builders) consult the cache through get_index_context(), which is non-blocking.

The monitor starts lazily: start() is invoked by the query builders on the first AEL where() query that needs cached metadata, not by Client.connect. Callers that never use AEL filters pay zero daemon-thread cost. stop() is called from the matching close paths and is a no-op when the monitor never started.

Example:

monitor = IndexesMonitor()
monitor.start(pac_client)   # idempotent; safe to call repeatedly
monitor.wait_until_ready()
ctx = monitor.get_index_context("test")
monitor.stop()
Parameters:

refresh_interval (float) – Seconds between cache refreshes (default 5.0).

__init__(refresh_interval=_DEFAULT_REFRESH_INTERVAL)[source]
start(pac_client)[source]

Begin background refresh (idempotent; lazy-start friendly).

Safe to call from multiple builders on every AEL query — if the daemon thread is already running, this is a no-op. The first metadata fetch runs asynchronously on the daemon thread; callers that need index metadata immediately (for example AEL where() filter generation on a dataset query) should call wait_until_ready() before relying on get_index_context().

Return type:

None

wait_until_ready(timeout=None)[source]

Block until the first index refresh attempt has finished.

After this returns, get_index_context() reflects the latest fetch (possibly empty if the cluster reports no secondary indexes).

Parameters:

timeout (Optional[float]) – Seconds to wait; None uses _DEFAULT_READY_TIMEOUT.

Raises:
Return type:

None

stop()[source]

Stop the background refresh thread.

Idempotent: safe to call when not running. Joins the thread with a short timeout so a stuck refresh doesn’t block shutdown.

Return type:

None

get_index_context(namespace)[source]

Return the cached IndexContext for namespace, or None.

Return type:

Optional[IndexContext]