IndexesMonitor¶
- class aerospike_sdk.index_monitor.IndexesMonitor[source]¶
Bases:
objectDaemon-thread background monitor that caches secondary index metadata.
Matches the JSDK
IndexesMonitordesign: 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 throughget_index_context(), which is non-blocking.The monitor starts lazily:
start()is invoked by the query builders on the first AELwhere()query that needs cached metadata, not byClient.connect. Callers that never use AEL filters pay zero daemon-thread cost.stop()is called from the matchingclosepaths 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).
- 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 callwait_until_ready()before relying onget_index_context().- Return type:
- 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;Noneuses_DEFAULT_READY_TIMEOUT.- Raises:
RuntimeError – If
start()was not called.TimeoutError – If the first refresh does not complete in time.
- Return type:
- 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: