Skip to content

treedb: honor checksum-skip for value-log leafref reads#841

Open
snissn wants to merge 3 commits intopr/entry-slice-telemetry-countersfrom
pr/leafref-checksum-skip
Open

treedb: honor checksum-skip for value-log leafref reads#841
snissn wants to merge 3 commits intopr/entry-slice-telemetry-countersfrom
pr/leafref-checksum-skip

Conversation

@snissn
Copy link
Copy Markdown
Owner

@snissn snissn commented Mar 18, 2026

Summary

This PR makes TreeDB leaf-ref read paths honor the existing checksum-skip policy used by fast/wal_on_fast profiles and -treedb-disable-read-checksum.

Before this change, value-log record CRC verification was skipped, but leaf pages loaded through value-log leaf refs were still always checksum-verified in hot read paths.

What changed

  • Added optional slab-reader checksum capability and plumbed it through value-log readers.
  • Tree read hot paths now conditionally skip leaf-ref page checksum verification when read checksums are disabled.
  • Added tests covering enabled vs disabled checksum policy for both GetAppend and iterator leaf-ref reads.
  • Added unified-bench profile test assertions for fast and wal_on_fast read-checksum behavior.

Files

  • TreeDB/tree/tree.go
  • TreeDB/tree/iterator.go
  • TreeDB/tree/tree_test.go
  • TreeDB/tree/iterator_test.go
  • TreeDB/db/value_reader.go
  • TreeDB/internal/valuelog/manager.go
  • cmd/unified_bench/profiles_treedb_index_test.go

Validation

Local tests

  • go test ./TreeDB/tree -run 'LeafRefChecksumPolicy|UsesAppendReaderForLeafRefPages' -count=1
  • go test ./cmd/unified_bench -run 'ApplyProfile_FastAndWALOnFastEnableIndexOptimizations' -count=1
  • go test ./TreeDB/db -run '^$' -count=1
  • go test ./TreeDB/internal/valuelog -run '^$' -count=1
  • go test ./TreeDB/caching -run '^$' -count=1
  • go vet ./...

unified-bench A/B (same command)

Command:
GOWORK=off make unified-bench && ./bin/unified-bench -dbs treedb -profile fast -keys 500000 -progress=false -treedb-index-outer-leaves-in-vlog=true -valsize=100 -checkpoint-between-tests -treedb-force-value-pointers=false -profile-dir=...

  • Patch: /home/mikers/tmp/leafcrc-fast-patch-1773798543
  • Base: /home/mikers/tmp/leafcrc-fast-base-1773798579

Read-path deltas (patch vs base):

  • random_read: +8.45% (409,912 -> 444,538)
  • random_read_parallel: +2.28% (3,565,184 -> 3,646,320)
  • random_read_batch: +6.39% (2,391,728 -> 2,544,510)
  • full_scan: +4.29%
  • prefix_scan: +3.91%
  • random_read_parallel_acquire_snapshot: -0.55%

CPU profile signal:

  • Base random_read shows checksum stack in hot path (Node.VerifyChecksum / page.CalculateChecksum / hash/crc32.* ~4.26% cum).
  • Patch random_read profile no longer shows these checksum symbols in top output.

run_celestia (serial)

  • fast (patched): /home/mikers/.celestia-app-mainnet-treedb-20260317155044/sync/sync-time.log
    • duration_seconds=293
    • max_rss_kb=10456660
    • end_app_bytes=5864844315
  • wal_on_fast (patched): /home/mikers/.celestia-app-mainnet-treedb-20260317155552/sync/sync-time.log
    • duration_seconds=380
    • max_rss_kb=12108616
    • end_app_bytes=6197787609
  • goleveldb fresh run: /home/mikers/.celestia-app-mainnet-goleveldb-20260317160312/sync/sync-time.log
    • duration_seconds=755
    • max_rss_kb=11686680
    • end_app_bytes=2951364090
    • recovered from one temporary statesync stuck-warning and completed successfully.

Copilot AI review requested due to automatic review settings March 18, 2026 02:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns TreeDB’s value-log “leaf-ref” read paths with the existing “disable read checksum” policy (used by fast / wal_on_fast profiles and -treedb-disable-read-checksum). Previously, disabling read checksums skipped value-log record CRC validation but still verified leaf page checksums for leaf pages stored in the value log.

Changes:

  • Added an optional ReadChecksumEnabled() capability on slab/value-log readers and plumbed it through DB/value-log reader types.
  • Updated Tree hot read paths (GetAppend and iterator leaf-ref reads) to conditionally skip leaf page checksum verification when read checksums are disabled.
  • Added/extended tests to cover enabled vs disabled behavior, including unified-bench profile assertions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
TreeDB/tree/tree.go Adds checksum-capability probing and gates leaf-ref page checksum verification on the configured policy.
TreeDB/tree/iterator.go Applies the same conditional checksum verification for iterator leaf-ref page loads.
TreeDB/db/value_reader.go Forwards ReadChecksumEnabled() from underlying value-log reader to the tree layer.
TreeDB/internal/valuelog/manager.go Exposes ReadChecksumEnabled() on Manager and snapshot Set to reflect the disable-read-checksum setting.
TreeDB/tree/tree_test.go Adds GetAppend coverage for leaf-ref checksum enabled/disabled behavior using a corrupted leaf page.
TreeDB/tree/iterator_test.go Adds iterator coverage for leaf-ref checksum enabled/disabled behavior using a corrupted leaf page.
cmd/unified_bench/profiles_treedb_index_test.go Asserts that fast and wal_on_fast profiles disable read checksums.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48766e1874

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f68ec13fa8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copilot AI review requested due to automatic review settings March 18, 2026 20:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes TreeDB’s leaf-ref (outer-leaf-in-vlog) read paths honor the same “skip read checksums” policy already used for value-log record CRC verification (e.g., fast / wal_on_fast profiles and -treedb-disable-read-checksum), and adds regression tests to ensure iterator and GetAppend behavior matches the configured policy.

Changes:

  • Add an optional ReadChecksumEnabled() capability on slab/value-log readers and plumb it through value-log reader layers into tree/iterator leaf-ref page verification.
  • Conditionally skip Node.VerifyChecksum() for leaf pages loaded via value-log leaf refs when read checksums are disabled.
  • Add tests for enabled vs disabled checksum behavior across GetAppend and iterator leaf-ref reads, plus unified-bench profile assertions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
TreeDB/tree/tree.go Adds checksum-capability plumbing and gates leaf-ref page checksum verification in hot paths; adjusts Get return behavior.
TreeDB/tree/iterator.go Gates iterator leaf-ref page checksum verification based on the tree’s checksum policy.
TreeDB/tree/tree_test.go Adds regression test ensuring GetAppend leaf-ref checksum policy is honored.
TreeDB/tree/iterator_test.go Adds regression test ensuring iterator leaf-ref checksum policy is honored.
TreeDB/db/value_reader.go Exposes ReadChecksumEnabled() via the DB’s slab reader wrapper so tree code can observe policy.
TreeDB/internal/valuelog/manager.go Implements ReadChecksumEnabled() on Manager and snapshot Set; minor robustness tweaks in stats helpers.
cmd/unified_bench/profiles_treedb_index_test.go Asserts fast/wal_on_fast profiles disable read checksums.
TreeDB/caching/expvar_stats.go Refactors process-wide expvar key selection into a helper predicate.
TreeDB/caching/db.go Adds per-DB append-only allocation counters and changes which counters are surfaced under certain stats keys.
Comments suppressed due to low confidence (1)

TreeDB/caching/db.go:17058

  • The treedb.process.append_only.mutable_new_alloc_with_queue_total / *_queue_bytes_sum stats are still sourced from global process-wide counters, while the corresponding treedb.cache.append_only.* stats just above are sourced from DB-local atomics. Since other treedb.process.append_only.* keys in this block mirror the DB-local values, this mixed sourcing is likely to confuse consumers. Consider making the process+cache variants consistently DB-local or consistently process-global (and adjust naming/tests accordingly).
	stats["treedb.process.append_only.mutable_from_lease_total"] = fmt.Sprintf("%d", appendOnlyMemLeaseHitTotal)
	stats["treedb.process.append_only.mutable_from_pool_total"] = fmt.Sprintf("%d", appendOnlyMemPoolHitTotal)
	stats["treedb.process.append_only.mutable_new_alloc_total"] = fmt.Sprintf("%d", appendOnlyMemNewAllocTotal)
	stats["treedb.process.append_only.mutable_new_alloc_with_queue_total"] = fmt.Sprintf("%d", appendOnlyMemNewAllocWithQueueTotal.Load())
	stats["treedb.process.append_only.mutable_new_alloc_queue_bytes_sum"] = fmt.Sprintf("%d", appendOnlyMemNewAllocQueueBytesSum.Load())

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

snissn pushed a commit that referenced this pull request Mar 18, 2026
# Conflicts:
#	TreeDB/caching/batch_arena_budget_test.go
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.

3 participants