Skip to main content

indexing

File metadata indexing: what to index, in what order, and telling the orchestrator.

The pod decides which configured datasources to index and in what order, records that decision in the background cache for the nightly refresh, cancels indexing runs for datasources it no longer has, and asks the orchestrator to start indexing.

Classes​

MetadataIndexingCoordinator​

class MetadataIndexingCoordinator(    ctx: PodContext,    *,    health: HealthReporter,    cache_state: BackgroundCacheState,    orchestrator_url: str | None,    in_background: Callable[[Callable[[], None], str], None],    dataset_grants: DatasetGrantRegistry | None = None,    served_configs: Callable[[], list[DatasourceConfig]] | None = None,):

Decides the pod's file metadata indexing order and asks for indexing.

Arguments

  • ctx: The pod's identity and services.
  • health: Datasource health, read to order indexing, and the heartbeat sent after a config reload.
  • cache_state: Whether the background cache can be used; indexing reads this flag but never sets it.
  • orchestrator_url: The orchestrator to notify, or None for a pod with no orchestrator.
  • in_background: Runs a blocking callable on a thread nothing waits for.
  • dataset_grants: The metadata runs' progress event grants the pod control server honours. None issues none.
  • served_configs: The configurations the pod serves its datasources with, sent with the start-up indexing order for an orchestrator that did not start the pod with them, e.g. a pod that took them from the hub. None sends none.

Methods​


cancel_unconfigured_indexing​

async def cancel_unconfigured_indexing(self) ‑> None:

Cancel any indexing run for a datasource this pod no longer has.

The snapshot stops the nightly refresh starting work for a removed datasource; this deals with the runs already submitted. They are not the pod's own runs to abandon — the orchestrator submits these, so they outlive the pod being stopped — and a walk of a large share can run for hours after the config that authorised it is gone.

Driven by what Prefect holds rather than by a config diff or by the pod's runs table, because those two each miss a case this must not miss: a datasource dropped while the pod was down leaves nothing to diff, and a run queued behind a concurrency limit has written no bookkeeping row yet but will start walking when its slot comes up.

Runs on every start and every reload, so a run that survives one pass is caught by the next.

Never raises: a removal must complete whatever Prefect says.

indexed_file_count​

def indexed_file_count(self, cache: CacheProtocol, record: FlowSpecRecord) ‑> int | None:

How many files are indexed for record's datasource right now.

The growth trigger's probe. None means "not measurable", which is never due: an unconfigured datasource (the gate loop reports that properly), or one with no filesystem root, where there is no root to count under and nothing to compare.

Never raises. A probe that could fail the tick would stop the periodic rerun as well, and this is the discretionary half of the check.

Takes the tick's already-open handle rather than opening its own. The probe runs once per lineage per tick, and the poller ticks for the pod's whole life — opening a handle here would accumulate the DB file plus its -wal and -shm siblings until the process hit its descriptor limit, which is the hazard PeriodicRerunSweep._periodic_rerun_background_dags exists to avoid.

Arguments

  • cache: The tick's open background cache.
  • record: The lineage whose datasource to measure.

Returns The count, or None when it cannot be taken.

kick_off_indexing_at_start​

def kick_off_indexing_at_start(self) ‑> None:

Record the indexing order, then ask the orchestrator to index.

The orchestrator no longer indexes on /pod/start; this is what starts file metadata indexing for the pod. Blocking (Hub calls, notify retries). Never raises.

on_datasources_changed​

async def on_datasources_changed(    self,    previous_names: set[str],    current_names: set[str],    new_datasource_configs: list[DatasourceConfig],) ‑> None:

Refresh health cache and send immediate heartbeat after reload.

Also notifies the orchestrator about any newly added datasets so it can schedule file_metadata_runtime for them immediately.

The health cache refresh and heartbeat are run in a thread to avoid blocking the pod's event loop (health checks can take up to 60s, heartbeat HTTP request up to 10s).

Thread safety: replacing the health monitor's cached health is an atomic reference swap under CPython's GIL, so no lock is needed.

plan_standalone_metadata_indexing​

def plan_standalone_metadata_indexing(    self,) ‑> MetadataKickoffPlan | None:

Decide the file metadata indexing order for a pod with no orchestrator.

For run_pod, which indexes alongside start rather than after it, so runs its own health check instead of reading the cached one. The decision is reported like the orchestrator path's.

Blocking (health checks and Hub calls). Never raises.

Returns The plan, or None if it could not be built.

record_configured_datasources​

def record_configured_datasources(    self, metadata: Mapping[str, DatasourceMetadata] | None = None,) ‑> None:

Write this pod's current datasource set to the background cache.

The snapshot file_metadata_refresh gates on. That sweep runs in the orchestrator with no pod handle and enumerates datasources from cached file_metadata rows, which outlive a datasource's removal from the pod config — so without this it re-indexes datasources this pod no longer has, at whatever size they were when they were dropped.

Written from configured_datasource_names, not from base_datasources: a datasource whose hub registration failed is still configured, and tombstoning it would stop the refresh re-indexing files this pod does still serve.

Also keeps the grants the metadata runs relay their progress events with to that same set (bitfount.progress_events.dataset_grants). Every path that submits a metadata run records the set first, so a run submitted from it finds its datasource's grant.

Once the snapshot is written, reconciles every published trial with it and with the unlink record (reconcile_dataset_removals), so a datasource removed from the pod config, even while the pod was down, or unlinked from a trial has its trial-derived rows taken out. This is the tick's only reconcile: the kick-off plan records the Hub's link report just before (record_dataset_links). No reconcile follows a failed write.

Blocking (SQLite), so async callers hand it to a thread.

Never raises. A pod that cannot write the snapshot must still start and still reload; the cost is that the nightly refresh keeps its previous answer until a later write succeeds. A pod that cannot keep the grants still indexes; its metadata runs report no progress. A reconcile that fails is logged and does not fail the snapshot; the next call retries.

Arguments

  • metadata: Indexing-order metadata by datasource name, from record_datasource_metadata. None keeps what the cache already holds.
def record_dataset_links(self, view: HubProjectView | None) ‑> None:

Record which of this pod's lineages the Hub reports unlinked.

Folds the Hub's per-trial linked datasets into the background cache, for the lineages in flow_specs. Only trials whose payload reported links are touched, so a Hub that does not report them records nothing.

Reconciles nothing itself. Its caller, _metadata_kickoff_plan, is followed in the same tick by record_configured_datasources, whose reconcile acts on this record, so an unlink is reconciled once, in the tick that makes it count.

Blocking (SQLite), so async callers hand it to a thread.

Never raises: an unreadable cache or a failed write only means the record stays as it was until a later probe succeeds.

Arguments

  • view: The Hub probe's answer; None when the Hub could not be reached, which is not evidence of an unlink and writes nothing.

record_datasource_metadata​

def record_datasource_metadata(    self,) ‑> MetadataKickoffPlan | None:

Decide the indexing order and write it with the datasource snapshot.

The snapshot is what file_metadata_refresh orders and skips by, so this runs whenever the health it depends on is refreshed.

Blocking on Hub calls that can hang, so async callers run it on a daemon thread (run_on_daemon_thread), which teardown does not join.

Never raises: a pod that cannot decide still starts, and the cache keeps its previous answer.

Returns The plan, or None if it could not be built.