partition_wave_ledger_by_datasource
Give each datasource linked to a project its own wave-ledger partition.
A lineage's ledger partition was keyed on its DAG configuration and project
alone. Two datasources of one type have equal step hashes, so every such
datasource linked to a project planned into one partition, and each lineage's
planning dropped the others' uncarried rows. The key now also names the
datasource (lineage_partition_key). This migration moves each existing row to
its lineage's key, derived from the key it is under and its datasource's task
hash, so no lineage sweeps its datasource again after the upgrade.
- A row's datasource is the one whose inventory (
file_metadata) holds its file. The match is made on the keyfile_metadatastores: a Windows path is folded first (fs_utils.canonical_key_if_path), so a row spelled as the share reports it still finds its file. A key that is not a path, such as anehr:<id>row's, is left as it is. - A row the inventory names no single datasource for, every EHR row among them,
belongs to the datasource of the run that last wrote it (
runs, byrun_id). - A row neither answer names one datasource for stays under the key it is under. No reader asks for that key any more, so the row is inert, as the partition of a superseded DAG configuration is. A lineage that still has its file as a candidate plans it again under its own key, and every step skips the work it has cached.
- A background run row's
ledger_partitiontag is re-derived from the run's own task hash, so recovery, and the cold-start check that matches runs to their configuration, read runs from before the upgrade under the new keys.
The rows are read first and then moved in one write transaction, which writes this migration's marker too. A key derived twice would name no partition, so a run that stops part way must leave nothing moved, and a run after one that finished must move nothing.
Module
Functions
apply
def apply(cache: CacheProtocol) ‑> int:Move every wave-ledger row to its own datasource's partition.
Arguments
cache: The cache backend.
Returns The number of ledger and run rows changed.