~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

pds-server: a fold indexes each frame once, however large

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:store/fold-indexes-each-frame-once

After an importRepo of a large repository, compacting the account's log took about an hour, and the account's next write (activateAccount in a move) waited for it: the owner's 24,342-record repository could not be activated. Compaction now reads the import's commit once.

Claude Opus 5.5 · high

What changes

The fold. Folding an account's log into its table reads each block, event and space item of the sealed logs alone, by its frame's index. A fold now keeps every frame's index it makes until it ends (checkpoint::Indexes), counted with what it holds of its account's store (Holding::more), instead of in its block cache, which keeps no entry larger than an eighth of it (pds-store/src/table.rs:1208; the fold's cache is 1 to 4 MiB, cache::Cache::fold_blocks). Reading through the shared cache (frame_item) is as it was.

A commit's replay. Memtable::put_commit asked, for each block a commit references, whether the commit puts it by searching all its puts: for an import, every record against every other. It now looks each up in a set.

Why

An import is one commit of every record, in one frame: the owner's repository is a 28 MB frame of about 55,000 items, whose index (51 bytes an item, about 2.8 MB) is larger than the fold's cache keeps. So Frames::item (checkpoint.rs:2403 on main) found no index for each item it read, read the whole 28 MB frame again and skimmed it to make one, and dropped it: compaction wrote its table at about 6 KB a second. Meanwhile, as spec/STORE.md ("Bounds") says, an account whose log holds 2 MiB more than its table waits for the compaction under way before its next write, so the move's activateAccount waited for the whole of it. The spec's bound holds as written; the fold was the slow part.

Raising the fold's cache would only move the size of frame that goes quadratic; the index of a frame is at most a few percent of the frame, which the fold reads whole to make it, and less than the memtable already counts for those items.

How it was checked

  • checkpoint::tests::a_fold_indexes_each_frame_once: an import of 12,000 records, whose frame's index is larger than any fold cache keeps; read as the fold reads them, the frame is read whole once and each item alone, and the log compacts within 30 seconds, every record then read from the table. With the fold's indexes kept in a cache of the fold's largest size again (the bug planted), the frame is read whole once for each item and the check fails.
  • The owner's backup CAR imported into a local build with this and the pull pds-server: imported records keep their blocks through the log, which it needs to get past compaction's first check of that repository: see the comment on this pull for the numbers.

Shortcomings

  • A read of a block from the log through the shared block cache (frame_item), before the log is compacted, still makes a frame's index again when it is too large for that cache: an eighth of half of PDS_CACHE_BYTES, 16 MiB by default, a frame of about 300,000 items. Compaction now ends such a window in seconds.
  • just nightly was not run here; the nightly workflow runs it on main.
Approved

This pull makes a fold keep each frame's index in a per-fold Indexes map, whatever its size. The map is counted through Holding::more. Before, the index went through the block cache, which refuses entries over an eighth of its size, so an import's frame was re-read whole for every item. Memtable::put_commit now looks each block up in a HashSet, where it used to search all the commit's puts for each one.

I found nothing that would make it wrong:

  • The fold's results are the same, because checked still verifies each CID. The shared-cache path (frame_item) keeps its behaviour, now built from the same helpers.
  • The held bytes are added to the store's folding count as they are made, so the memory bound in spec/STORE.md still covers them. The count drops to zero when Holding is dropped.
  • The change adds no spec behaviour that needs writing down. spec/STORE.md says nothing about the fold's index cache, and its "Bounds" text still holds as written.
  • The changeset is written for the people who run the server.
  • The test covers the planted bug: it fails if the frame is read whole more than once, and it checks that the log compacts within 30 seconds.

I could not build or run it, so I did not check that the dropped cache field leaves no unused variable in legacy_fold or Fold::fold. The compiler would flag that.

The owner's backup CAR (24,342 records, 186 collections, 17 MB) imported into a local build of this pull merged with pds-server: imported records keep their blocks through the log, on its own port and data directory: importRepo 200 in 5.6 s; getRepo as the admin while deactivated 200, 16,990,107 bytes, whose goat repo ls equals the backup's line for line (24,342 records, every CID); the log compacted into its table before activateAccount answered, 6.0 s after the import began, activateAccount itself 355 ms; listRecords of every collection gives goat's counts and CIDs; no store failure, through a restart too. listMissingBlobs 7,380, as the CAR's blob refs count. On main (4409a5c) the same import logs the store failure and the server stops; with the first pull alone, compaction ran at about 6 KB/s and activateAccount waited on it.

Approved

Since my approval at 8ed5715, the pull only adds a type Indexed alias for whole_frame_item's return type and rewords its doc comment. Behaviour is unchanged, so what I approved stands.

All checks have passed

3 passed, 1 skipped

Merged as 8254df6