Skip to content

Faster backfill and smaller storage: split backfill, packed message-ids, sealed blobs, auto compact - #1

Merged
xbmc4lyfe merged 160 commits into
rustfrom
faster-backfill
Oct 6, 2026
Merged

xbmc4lyfe merged 160 commits into
rustfrom
faster-backfill

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Summary

Speeds up backfill and shrinks the database:

  • Spread connections across servers: groups are spread over servers with weighted rendezvous ranking. A server is marked article-only only after 3 GROUP refusals. Header requests are bigger (request_size 10000, batch_size 500000).
  • Split backfill by date: when two or more indexing servers carry a group and its backlog is over split_min_backlog (10M), the group's history is cut into UTC day chunks. Idle workers on any server that carries the group claim the chunks.
    • Chunks live in the backfill_chunks table in atlas.db. Claims are atomic, and a stale claim is taken over after 30 minutes.
    • A date-to-article binary search handles gaps in article numbers and servers with different retention.
    • The Backfill page shows split groups and their day chunks.
  • Packed message-ids: local parts are packed by alphabet (tags 3–7: digits, base36, base62, base64url), and old rows keep their meaning.
  • Sealed files: a file that's complete, or untouched for 3 days, is sealed into one zstd blob.
    • Shard writers seal files between saves, within a budget of 2,000 files or 100 ms.
    • --compact seals every file that's due while it copies, and re-encodes message-ids.
    • NZBs are byte for byte identical.
  • auto_run_compact (default false): compacts every 24 hours inside the indexer.
    • It can be stopped at any point; originals stay in place until each shard is swapped.
    • A failed shard is kept as it was and retried 24 hours later.
    • A lock file keeps the menu from writing while a compaction runs.

Spec: docs/superpowers/specs/2026-10-05-faster-backfill-smaller-storage-design.md
Plan: docs/superpowers/plans/2026-10-05-faster-backfill-smaller-storage.md

Upgrading an existing database

  1. On first start, the shards get two nullable columns (files.touched_at, files.blob). Adding them is instant and doesn't rewrite any table.
  2. Files from before the upgrade aren't sealed while indexing runs. Run atlas --compact once, with the indexer stopped, to re-encode and seal them. Expect roughly 138 GB to drop to about 60 GB.

Known limits

  • A server's retention is judged from its oldest article. A server whose retention starts partway through the split's oldest day can finish that day with part of it missing.
  • Days that expire on every server during a long backfill stay pending and are retried hourly.
  • Holes of more than ~12,700 article numbers are crossed by sampling, then the skipped span is read once.

Test plan

  • just format, just lint and just test are clean (131+ tests).
  • New tests:
    • Date search: gaps, holes of millions of numbers, sparse runs before and after holes.
    • Split backfill: two servers, a server that doesn't carry the group, servers with different retention.
    • Chunk claims, packing round trips, blob codec including corrupt input.
    • Sealing: NZBs byte for byte equal, late articles, legacy duplicates.
    • Compact: run twice, a corrupt blob, a failed shard, a stop.
    • Auto compaction.
  • Each task was reviewed, and the whole branch had a final review. Two data-loss bugs it found are fixed, each with a test that failed first.
  • Run atlas --compact on the real database, then compare NZBs and stats.

🤖 Generated with Claude Code

xbmc4lyfe and others added 30 commits October 5, 2026 13:35
…, auto compact

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A server is article only after 3 GROUP refusals in a row, not one
  (news.frugalusenet.com was switched off by one odd group name).
- Groups their first server doesnt carry fall back by connection
  weighted rendezvous hashing instead of the first server in the list,
  and remember where they live.
- request_size 10000 / batch_size 500000 by default: measured 3-6x the
  headers/s per connection on old articles (examples/probe_xover.rs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Replace select-then-update in claim with atomic UPDATE...RETURNING
- Wrap insert loop in add with unchecked_transaction
- Add doc comments to create, is_split, finish, release
- Add concurrent-connection test verifying atomicity

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Replace split_groups() + per-group progress() calls with one SELECT
that aggregates all backfill_chunks data in a single scan. Store
stats as tuple (groups, splitting, done, total, done_last_hour) to
avoid per-group allocations. Draw shows: "split groups: N (M in
progress), day chunks D of T done, L in the last hour".

Add test verifying aggregate query on in-memory db.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Blobs are rewritten too: domain uses are counted inside blobs, segments
of dropped domains become whole ids and kept ones are repacked. Files are
copied in id order next to their rows and due ones sealed on the way, so
the copy has no free pages. A corrupt blob stops the shard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compaction now tries every shard: a failed one keeps its original and the
rest are swapped and their backups removed, then run reports each failure.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
compact::run takes a stop flag (checked per file, per phase, before the swap,
and inside long SQL statements) and leaves the originals alone when stopped.
The indexer's db writers are joined before compacting, a missing shard after
compaction stops the indexer, and the 24 hour clock counts from the first
start.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ompact

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A probe that landed on 100+ missing numbers sent the binary search left,
pulling chunk starts far back and cutting chunk ends short, soo a day's
articles past the gap were never fetched. Probes now scan forward in
doubling windows (spreading out past 6,400 numbers) and only go left when
nothing exists after the probe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…minute

Every save tick used to scan 8,000 files rows and, on first start, seal
every pre-upgrade file online. Now a writer seals the files its own saves
completed (up to 50,000 remembered), walks the files table at most every
SEAL_WALK_EVERY seconds, skips the tick while more saves are queued, and
leaves files never touched since the upgrade to --compact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Writers are joined on shutdown, soo every queued save plus a seal tick per
batch ran before the indexer could exit. A writer now skips sealing once its
queue is closed, and drops queued slices whose pass is gone (their cursor
didnt move, the headers get fetched again).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A group taken out of config.json, or indexed live only, kept its pending
day chunks and idle workers still claimed and fetched them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI search saves and the broken release purge wrote into the original shard
after the compaction took its copy, and were lost at the swap. Compaction
now holds an atlas.compacting lock file (pid and start time, removed on
every exit, ignored once that process is gone) and those writes refuse
while it's there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xbmc4lyfe and others added 4 commits October 6, 2026 07:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l it looks at

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w the reach moved past is ignored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

Round 26 fixes are in 4021482.

🤖 Addressed by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4021482c9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/compact.rs Resolved
Comment thread src/indexer.rs Resolved
Comment thread src/compact.rs Resolved
xbmc4lyfe and others added 4 commits October 6, 2026 09:38
…ts longer on a slow runner

Each chunk of the speculative window cost more the more articles the deep
server held, and ubuntu's 2-core runner ran out of its 180 s while still
making progress (58 of 90 chunks). The window and the sweep it proves are
the same with 2190 forged days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot in memory

A shard can have as many domains as a poster makes up, and four shards
are compacted at once: a map of them all could run out of memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plain group cursor stays only for a lone unkeyed server: one left
over from a server since removed would have the keyed one skip ranges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ir articles, none held

A loose file can have any number of articles, and both the original's and
the copy's were held at once. Each is now a count and a sum of row hashes,
whatever their order; a copy that lost second copies of a message-id is
worked out in a database file of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Atlas/src/config.rs

Lines 199 to 202 in bb7199a

// largest remainder, at least one each
let mut shares: Vec<(usize, usize, usize)> =
connections.iter().enumerate().map(|(i, c)| (i, (total * c / sum).max(1), (total * c) % sum)).collect();
let mut given: usize = shares.iter().map(|s| s.1).sum();

P2 Badge Keep worker shares within parallel_groups

When three or more servers have skewed connection counts, applying .max(1) after proportional division can make given exceed total, and the code only corrects undersubscription. For example, parallel_groups = 3 with connection counts [100, 1, 1] produces [2, 1, 1], so run_servers spawns four workers despite the configured cap, increasing concurrent parsing and memory use. Reserve one worker per server before distributing the remainder, or explicitly remove any over-allocation.


Atlas/src/convert.rs

Lines 647 to 648 in bb7199a

})?
.collect::<rusqlite::Result<_>>()?;

P2 Badge Stream validation of oversized releases during conversion

When a legacy database contains a release with an unbounded number of articles, this validation collects every old article into one Vec; it then collects the converted side again with store::articles and renders both complete NZBs in memory. The newest 200 releases are always checked, so a large attacker-posted release can make --convert or startup conversion exhaust memory after the full copy has completed, and every retry reaches the same failure. Compare the ordered rows or rendered output with a streaming digest instead.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/indexer.rs Resolved
Comment thread src/convert.rs Resolved
Comment thread src/db.rs Resolved
…s it

Its database file attached the shard and stayed open till the end of the
compaction, and Windows wont rename an open file: it is detached once
counted, and the count is dropped before the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

…and the release check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

Atlas/src/store.rs

Lines 1423 to 1426 in 561c277

if others {
index_release(&tx, &key, release_id)?;
}
let index = others.then_some((release_id, &key));

P2 Badge Keep the release ID index current after deleting an empty file

When a release temporarily receives a second filename whose articles are all duplicates, index_release writes its completion marker, but the new empty file is subsequently deleted. Fresh evidence after ebc381f is that later articles added to the remaining sole file take others == false, so they are not added to the already-marked index; if another filename later supplies one of those message IDs, the stale index misses it and Atlas again stores a cross-file duplicate, inflating the NZB and release totals. Clear/rebuild the marker when the empty file is removed, or continue maintaining an existing index even while the release has one file.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

xbmc4lyfe and others added 3 commits October 6, 2026 10:34
…e it was alone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne file is left

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… conversion's swap is taken out of the way

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

Round 28 fixes are in f7a771f, including the review-comment finding: the release index and marker are cleared when a duplicate-only file is deleted (929c37f). Also 561c277 fixes the Windows CI failure (scratch db left the original shard attached during the swap).

🤖 Addressed by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@xbmc4lyfe
xbmc4lyfe merged commit de598b6 into rust Oct 6, 2026
3 checks passed
@xbmc4lyfe
xbmc4lyfe deleted the faster-backfill branch October 6, 2026 17:33
This was referenced Oct 6, 2026
xbmc4lyfe added a commit that referenced this pull request Nov 7, 2026
* spots: check spot signatures as Spotweb does

A spot's From header carries RSA signatures (PKCS #1 v1.5, SHA-1): the
header signed by Spotnet's keys 2-4, or a self-signed key-7 spot with a
hashcash, and the message-id signed by the spotter's own key. Spots are
now kept only when these hold, checked on the overview and again on the
HEAD (for spots noted before), and the spotter id stored is the one the
spotter's signature proves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* spots: review fixes for signature checks

Build the signed text as bytes, so a multibyte character before the '<'
can't panic the spot task; reject an empty nickname and a user key that
won't decode, as Spotweb does; take only signatures exactly as long as
the key; note which verdicts rest on decoded text; and say whether the
spotter's key signed the message-id itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant