Skip to content

fix: seed in-memory metrics from DB on startup#97

Merged
jxom merged 4 commits intomainfrom
test/status-fallback
Feb 25, 2026
Merged

fix: seed in-memory metrics from DB on startup#97
jxom merged 4 commits intomainfrom
test/status-fallback

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented Feb 25, 2026

Summary

After a process restart, the in-memory watermarks and row counts start at zero, causing /status to show empty/zero values until new writes arrive. This PR seeds the atomics from the database during chain initialization:

  • Watermarks: MAX(block_num) per table via index-only scans (instant)
  • Row counts: Approximate counts from pg_stat_user_tables (instant, no table scan)

This ensures tidx status shows accurate data immediately after restart.

Changes

  • src/cli/up.rs: Add seed_metrics_from_db() called during initialize_chain()

Testing

  • cargo check passes
  • Manually verified on production server (67.213.124.223) in previous deployment

jxom and others added 4 commits February 25, 2026 14:46
The previous filter (ClientRead + 30s) missed active COPY operations
from the old container, causing migrations to block indefinitely on
lock acquisition after container restarts.

Amp-Thread-ID: https://ampcode.com/threads/T-019c92c9-0c02-7101-9241-b7875567efc6
Co-authored-by: Amp <amp@ampcode.com>
SyncEngine::new calls eth_chainId which fails fatally on network blips,
permanently killing the chain's sync task. Now retries every 10s.

Amp-Thread-ID: https://ampcode.com/threads/T-019c92c9-0c02-7101-9241-b7875567efc6
Co-authored-by: Amp <amp@ampcode.com>
Populate watermarks (MAX block_num per table) and approximate row counts
(from pg_stat_user_tables) into the in-memory atomics during chain
initialization. This ensures the status display shows accurate data
immediately after a process restart, rather than starting from zero
until new writes arrive.

Amp-Thread-ID: https://ampcode.com/threads/T-019c930c-df99-724a-a41b-65c98b607256
Co-authored-by: Amp <amp@ampcode.com>
@jxom jxom merged commit fbd6e41 into main Feb 25, 2026
1 check passed
o-az pushed a commit that referenced this pull request Apr 27, 2026
* feat: show backfill ETA in status display

Amp-Thread-ID: https://ampcode.com/threads/T-019c92c9-0c02-7101-9241-b7875567efc6
Co-authored-by: Amp <amp@ampcode.com>

* fix: terminate all stale connections before migrations

The previous filter (ClientRead + 30s) missed active COPY operations
from the old container, causing migrations to block indefinitely on
lock acquisition after container restarts.

Amp-Thread-ID: https://ampcode.com/threads/T-019c92c9-0c02-7101-9241-b7875567efc6
Co-authored-by: Amp <amp@ampcode.com>

* fix: retry sync engine creation on transient RPC failures

SyncEngine::new calls eth_chainId which fails fatally on network blips,
permanently killing the chain's sync task. Now retries every 10s.

Amp-Thread-ID: https://ampcode.com/threads/T-019c92c9-0c02-7101-9241-b7875567efc6
Co-authored-by: Amp <amp@ampcode.com>

* fix: seed in-memory metrics from DB on startup

Populate watermarks (MAX block_num per table) and approximate row counts
(from pg_stat_user_tables) into the in-memory atomics during chain
initialization. This ensures the status display shows accurate data
immediately after a process restart, rather than starting from zero
until new writes arrive.

Amp-Thread-ID: https://ampcode.com/threads/T-019c930c-df99-724a-a41b-65c98b607256
Co-authored-by: Amp <amp@ampcode.com>

---------

Co-authored-by: Amp <amp@ampcode.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