Skip to content

flatkv uses mutations - #4665

Merged
cody-littley merged 10 commits into
mainfrom
cjl/flatkv-uses-mutations
Oct 28, 2026
Merged

cody-littley merged 10 commits into
mainfrom
cjl/flatkv-uses-mutations

Conversation

@cody-littley

Copy link
Copy Markdown
Contributor

Refactor flatKV to utilize mutations. Dramatically reduces internal complexity of flatKV, and eliminates a lot of duplicate work.

@cursor

cursor Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Touches the live FlatKV commit, WAL replay, and LtHash pipeline—core state integrity paths—with a large removal of the previous async fold machinery.

Overview
FlatKV and Giga state commits now take explicit mutation.Mutation slices (physical key, previous value, new value) instead of applying NamedChangeSet inside the store with async read-modify-write folds. CommitStateChanges and replay/WAL paths were updated accordingly; SS replay still receives changesets via MutationsToChangeSets where needed. Callers build mutations with MutationsFromChangeSets(..., prior view) before commit, matching what the state DB does on the normal commit path.

The view engine’s BatchUpdate / BatchUpdater path is removed along with staged folds, version latches, and related shutdown tests—writes are plain BatchSet/Set again, and sealed diffs no longer wait on background folds.

LtHash hashing is simplified: the gather phase that diffed sealed views and fetched prior values is gone; HashEngine.ScheduleHash hashes caller-supplied DatabaseMutations directly. KeyMutation is replaced by the shared mutation.Mutation type across audit, import, and tests. Import translation and changeset conversion share changeSetEntryKey / rowValue instead of the old classify-and-prefix pipeline; keyArena is deleted.

Tests and recovery scenarios were updated to commit through the mutation helpers and to simulate per-DB skew by copying/restoring data DB snapshots rather than rewinding version metadata.

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

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 28, 2026, 4:47 PM

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.40102% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.95%. Comparing base (570d90a) to head (be4db01).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/db_engine/view/shard.go 81.25% 3 Missing ⚠️
sei-db/state_db/giga/state_db_replay.go 50.00% 3 Missing ⚠️
sei-db/state_db/sc/flatkv/store_apply.go 92.30% 3 Missing ⚠️
sei-db/state_db/sc/flatkv/import_translator.go 92.59% 2 Missing ⚠️
sei-db/state_db/sc/flatkv/store_write.go 95.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4665      +/-   ##
==========================================
- Coverage   60.05%   59.95%   -0.10%     
==========================================
  Files        2020     2017       -3     
  Lines      158499   157902     -597     
==========================================
- Hits        95187    94673     -514     
+ Misses      63307    63224      -83     
  Partials        5        5              
Flag Coverage Δ
sei-chain 57.97% <85.71%> (-0.04%) ⬇️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.14% <94.31%> (-0.26%) ⬇️

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

Files with missing lines Coverage Δ
sei-db/db_engine/view/view_manager_impl.go 91.38% <100.00%> (+0.59%) ⬆️
sei-db/state_db/giga/state_db.go 80.43% <100.00%> (ø)
sei-db/state_db/sc/flatkv/audit/snapshot_audit.go 86.40% <100.00%> (ø)
...ate_db/sc/flatkv/changeset_mutation_conversions.go 96.47% <100.00%> (+0.05%) ⬆️
sei-db/state_db/sc/flatkv/importer.go 93.90% <100.00%> (-0.51%) ⬇️
sei-db/state_db/sc/flatkv/lthash/hash_combiner.go 94.79% <ø> (-0.11%) ⬇️
sei-db/state_db/sc/flatkv/lthash/hash_engine.go 84.48% <100.00%> (+1.14%) ⬆️
...db/state_db/sc/flatkv/lthash/hash_engine_config.go 72.72% <100.00%> (+1.29%) ⬆️
.../state_db/sc/flatkv/lthash/hash_engine_messages.go 100.00% <ø> (+38.46%) ⬆️
sei-db/state_db/sc/flatkv/lthash/leaf_hasher.go 97.59% <100.00%> (+3.61%) ⬆️
... and 17 more

... and 32 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.

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

This PR changes flatKV so each block's writes and its lattice hash both come from one list of mutations (each carrying the key's previous and new value). That replaces the view manager's BatchUpdate folds and the hash engine's separate gather phase, and both public commit entry points now share one commitMutations path. I traced the account merge, empty-versus-nil values, import translation, replay skip lists, WAL slice ownership and hash-engine shutdown against the base branch and found no correctness defect, so nothing blocks; the codex reading (no findings) agrees with this and contributed nothing further.

Non-blocking

  • The lattice hash used to be computed from values read back out of the store; it is now computed from the PreviousValue each caller supplies (from MutationsFromChangeSets or from the WAL record), and nothing checks it against the store. Replay therefore no longer corrects itself when a database's rows are ahead of its recorded version: such a block is now hashed twice instead of being a no-op. Correctness now depends on each database writing its rows and its metadata in one batch, and on requireAlignedDataDBs refusing to open nil-WAL stores whose databases are at different heights. The tests that pinned the old idempotency (TestTornCommitStillRecoversFromWAL, TestCatchupReplaysAlreadyAppliedBlockOnSeededStore, and the version-only rewinds in the skew tests) were deleted or rewritten to restore whole databases. Consider a cheap test-build or debug check that a mutation's PreviousValue matches the prior view, so a caller mistake fails loudly instead of quietly forking the AppHash.

seidroid review · decision approve · session 129209995f3145d9bed8a398eba07a79 · turn resp_claude_1bb4bb60510ca9855c6dcdbca8ae4507 · item 160b973fe3475a779e28542a5dd50e27

Findings: 0 blocking | 1 non-blocking | 0 posted inline

return nil
writes := make([]view.Write, len(mutations))
for i := range mutations {
writes[i] = view.Write{Key: string(mutations[i].Key), Value: mutations[i].NewValue}

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.

Nit: This could be 10-20k allocations per superblock. Mutation keys are never modified, and the view only keeps the key string until the version retires (it clones on first insert into the long-lived map), so unsafe.String would avoid the copy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

change made

@cody-littley
cody-littley added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 19fb04d Oct 28, 2026
71 of 72 checks passed
@cody-littley
cody-littley deleted the cjl/flatkv-uses-mutations branch October 28, 2026 17:10
shemnon added a commit that referenced this pull request Oct 29, 2026
…recompile

Adapt the flatkv test store to CommitStateChanges taking mutations (#4665).
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