Skip to content

Remove metadata DB - #3928

Open
cody-littley wants to merge 1 commit into
mainfrom
cjl/no-metadata-db
Open

Remove metadata DB#3928
cody-littley wants to merge 1 commit into
mainfrom
cjl/no-metadata-db

Conversation

@cody-littley

Copy link
Copy Markdown
Contributor

Describe your changes and provide context

Remove the metadata DB.

@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

PR Summary

High Risk
This changes how FlatKV derives version and AppHash-related roots, removes pre-migration historical query/export behavior, and shifts corruption detection to load time—core state-commit semantics with broad operational impact.

Overview
Removes FlatKV’s separate metadata PebbleDB and stops persisting a global version, global LtHash, and earliest-history watermark. The store’s committed version is now the minimum of the four data DBs’ _meta/version records, and the root hash is the homomorphic sum of their per-DB LtHashes. Commits only write per-DB batches (data + LocalMeta); WAL catchup no longer flushes a global metadata step.

Composite / read paths: FlatKVNeededAtHeight, flatKVEarliestVersion, and constructor-time GetEarliestVersion are gone. Read-only loads always open FlatKV when the backend exists, so heights that predate FlatKV history are no longer served memiavl-only—they fail the FlatKV load like any other load error (documented in renamed tests). Corrupt/unopenable FlatKV dirs are expected to fail on LoadLatest rather than at construction. Export metadata gating drops the pre-era “memiavl-only export” branch and always loads FlatKV at the export height for migration gating (still fail-loud on load failure).

Tooling & layout: Snapshot/working layout is account/code/storage/misc only; flat-layout migration and metadata-related config/tests are removed. GetLatestVersion reads working/misc; EarliestVersion / GetEarliestVersion are removed from the API. dump-flatkv drops metadata-probe logic and always runs LtHash verification when requested. New guards include requireAlignedDataDBs (reject a DB ahead of the WAL tail) and expanded replay/idempotency tests.

Reviewed by Cursor Bugbot for commit 7649c18. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 14, 2026, 8:40 PM

@seidroid seidroid 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.

The automated review did not complete; see the failing AI Review check for details.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.10924% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.79%. Comparing base (a34ceab) to head (7649c18).

Files with missing lines Patch % Lines
sei-db/state_db/sc/flatkv/verify.go 19.04% 12 Missing and 5 partials ⚠️
sei-db/state_db/sc/composite/store.go 86.20% 2 Missing and 2 partials ⚠️
sei-db/state_db/sc/flatkv/store.go 87.87% 2 Missing and 2 partials ⚠️
sei-db/state_db/sc/flatkv/store_meta.go 75.00% 3 Missing and 1 partial ⚠️
sei-db/tools/cmd/seidb/operations/dump_flatkv.go 0.00% 1 Missing and 1 partial ⚠️
sei-db/state_db/sc/flatkv/snapshot.go 83.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3928      +/-   ##
==========================================
- Coverage   59.48%   58.79%   -0.70%     
==========================================
  Files        2325     2254      -71     
  Lines      198660   191385    -7275     
==========================================
- Hits       118180   112522    -5658     
+ Misses      69240    68152    -1088     
+ Partials    11240    10711     -529     
Flag Coverage Δ
sei-chain-pr 29.00% <0.00%> (?)
sei-db 70.41% <ø> (-0.22%) ⬇️
sei-db-state-db ?
sei-db-state-db-pr 75.71% <74.35%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-db/state_db/sc/flatkv/config/config.go 76.27% <ø> (+3.96%) ⬆️
...db/state_db/sc/flatkv/config/flatkv_test_config.go 100.00% <ø> (ø)
sei-db/state_db/sc/flatkv/hashlog.go 77.77% <ø> (ø)
sei-db/state_db/sc/flatkv/ktype/meta.go 100.00% <ø> (ø)
sei-db/state_db/sc/flatkv/store_iteration.go 66.50% <ø> (ø)
sei-db/state_db/sc/flatkv/store_lifecycle.go 62.19% <100.00%> (+0.56%) ⬆️
sei-db/state_db/sc/flatkv/store_replay.go 74.31% <100.00%> (+3.43%) ⬆️
sei-db/state_db/sc/flatkv/store_write.go 81.66% <100.00%> (+1.17%) ⬆️
sei-db/state_db/sc/flatkv/snapshot.go 68.49% <83.33%> (+0.04%) ⬆️
sei-db/tools/cmd/seidb/operations/dump_flatkv.go 51.21% <0.00%> (+1.41%) ⬆️
... and 4 more

... and 72 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +359 to +360
miscDir := filepath.Join(dir, workingDirName, miscDBDir)
if _, err := os.Stat(miscDir); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we only look at miscDB for getting LatestVersion? Shall we look at the minimum of four?

Comment on lines +729 to +732
if meta.CommittedVersion != s.committedVersion {
return fmt.Errorf(
"flatkv: %s is at version %d but the store is at %d; this store holds a block "+
"its write-ahead log lost, which no replay can reconcile (restore from a snapshot)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SetInitialVersion writes the same watermark into four separate databases with four separate commits, and the new requireAlignedDataDBs guard refuses to open a store whose four watermarks disagree — so a crash in the middle of that loop produces exactly the state the guard rejects, and the code that would repair it lives after the load that now fails.

}

syncOpt := types.WriteOptions{Sync: s.config.Fsync}
for _, ndb := range s.namedDataDBs() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SetInitialVersion writes each data DB's watermark in its own separate durable batch — four independent Pebble commits, no atomicity across them. What if the node crash in between?

func (s *CommitStore) replayIntoMutableStore(targetVersion int64) (err error) {
// It runs at startup (open/openTo) and during Rollback, never concurrently with live commits.
func (s *CommitStore) replayIntoMutableStore(targetVersion int64) error {
if err := s.catchUpFromWAL(targetVersion); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First, replay bypasses the contiguity check that normally protects the watermark. Commit refuses to go backwards — it enforces version != s.committedVersion+1. But replay doesn't go through Commit; it calls commitBatches directly.

Second, prepareBatch only skips a DB when it has both no writes and is already at or past the version. The && is what matters here — if the replayed block touches this DB at all, the batch is built even though the DB is ahead.

Third, the batch stamps the replayed version unconditionally. There is no "only move forward"

So a DB sitting at version 3 that gets block 2 replayed into it is written back down to version 2.

The check has to happen before catchup, and it has to compare against the WAL rather than against the other DBs. Comparing DBs to each other pre-catchup would be wrong, because a plain torn commit legitimately leaves them disagreeing and that case is fully recoverable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants