Document the repodata fingerprint invariant #178

Merged
benvin merged 2 commits from benvin/repodata-fingerprint-invariant into master 2026-10-25 22:53:04 +11:00
3 changed files with 10 additions and 1 deletions
+3 -1
View File
@@ -92,4 +92,6 @@ Repodata is regenerated from the metadata rows on every request by default. Set
`cache_repodata = true` on the remote to keep the generated `repomd.xml` and its
`primary`/`filelists`/`other` files in memory per replica. Each request checks a
cheap row fingerprint (count + newest id) in the database and rebuilds only when
it moved, so every replica picks up a scan's changes on its next request.
it moved, so every replica picks up a scan's changes on its next request. The
fingerprint relies on only one scan writing a remote's rows at a time; in the
deployed server, the sync lease serialises scans across replicas.
+1
View File
@@ -42,6 +42,7 @@ func (db *DB) DeleteRPMMetadata(ctx context.Context, repoName, filePath string)
// RPMMetadataFingerprint is a cheap change detector for a repo's rows: they are
// only ever inserted or deleted, so (count, max id) moves whenever they change.
// For github_rpm remotes it relies on the sync lease serialising scans.
func (db *DB) RPMMetadataFingerprint(ctx context.Context, repoName string) (count, maxID int64, err error) {
err = db.Pool.QueryRow(ctx, `SELECT count(*), coalesce(max(id), 0) FROM rpm_metadata WHERE repo_name = $1`, repoName).Scan(&count, &maxID)
return count, maxID, err
+6
View File
@@ -510,3 +510,9 @@ func TestSyncerScheduledPrime(t *testing.T) {
t.Fatalf("cold-cache prime: attempts=%d freshness=%v interval=%v, want 1/0/0", store.attempts, store.freshness, store.interval)
}
}
func TestSyncLeaseOutlivesScanTimeout(t *testing.T) {
if syncLeaseDuration <= defaultScanTimeout {
t.Fatalf("syncLeaseDuration %v must exceed defaultScanTimeout %v so scans stay serialised", syncLeaseDuration, defaultScanTimeout)
}
}