Seed leases alternate between priorities; article relay can be off
Half the live leases go to higher-priority ranges, the rest to the others, so a slow recent gap runs beside older history. With no article connections the article relay answers 503 instead of waiting forever. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cc69a617f
commit
cc861ce8ae
4 files changed
+30
-2
No files matched your search
@@ -73,12 +73,21 @@ class SeedOrchestrator {
|
||||
WHERE status = 'leased' AND heartbeat_at < now() - make_interval(secs => ?) AND attempts >= ?`,
|
||||
[LEASE_TTL_SECONDS, MAX_ATTEMPTS]
|
||||
)
|
||||
// Priorities take turns: while ranges of a higher priority are leased for less than half of
|
||||
// the work in progress they go first, otherwise the rest does (a 2026 gap fetches ~5x slower
|
||||
// than older history; LOG.md 2026-10-06 (10)).
|
||||
const { rows: mix } = await db.rawQuery(
|
||||
`SELECT count(*) FILTER (WHERE priority > 0) AS high, count(*) AS all FROM seed_ranges
|
||||
WHERE status = 'leased' AND heartbeat_at >= now() - make_interval(secs => ?)`,
|
||||
[LEASE_TTL_SECONDS]
|
||||
)
|
||||
const order = Number(mix[0].high) * 2 < Number(mix[0].all) + 1 ? 'priority DESC, id' : 'priority ASC, id'
|
||||
const { rows } = await db.rawQuery(
|
||||
`UPDATE seed_ranges SET status = 'leased', node_id = ?, leased_at = now(), heartbeat_at = now(), attempts = attempts + 1
|
||||
WHERE id = (
|
||||
SELECT id FROM seed_ranges
|
||||
WHERE status = 'queued' OR (status = 'leased' AND heartbeat_at < now() - make_interval(secs => ?))
|
||||
ORDER BY priority DESC, id LIMIT 1 FOR UPDATE SKIP LOCKED)
|
||||
ORDER BY ${order} LIMIT 1 FOR UPDATE SKIP LOCKED)
|
||||
RETURNING id, group_name, next_id, end_id`,
|
||||
[nodeId, LEASE_TTL_SECONDS]
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user