Skip to content

perf: shard pool guard to improve performance - #964

Merged
jiangzhe merged 1 commit into
mainfrom
shard-pool-guard
Aug 9, 2026
Merged

perf: shard pool guard to improve performance#964
jiangzhe merged 1 commit into
mainfrom
shard-pool-guard

Conversation

@jiangzhe

@jiangzhe jiangzhe commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Improvements
    • Improved buffer-pool guard and resource-lifecycle management across storage, catalog, file, index, recovery, and transaction operations.
    • Session-specific resource handling now provides better isolation while preserving safe sharing within a session.
    • Storage and checkpoint workflows now consistently reuse caller-provided resource contexts, improving reliability for concurrent and long-running operations.
  • Documentation
    • Clarified resource ownership, cloning, synchronization, and keepalive behavior.
  • Tests
    • Expanded coverage for guard sharing, independent roots, lifecycle tracking, concurrency, corruption handling, and recovery scenarios.

@jiangzhe jiangzhe self-assigned this Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change replaces implicit pool-guard creation with explicit base and session guard roots. It propagates guards through readonly access, file operations, catalog checkpoints, table persistence, recovery, indexes, and transaction paths. Tests verify guard identity and lifecycle behavior.

Changes

Pool-guard ownership and propagation

Layer / File(s) Summary
Base-guard and keepalive-root contracts
doradb-storage/src/buffer/*, doradb-storage/src/quiescent.rs
create_base_guard defines independent guard roots. Clones share keepalive roots. Tests verify root identity and lifecycle counts.
Readonly pool and file guard flow
doradb-storage/src/buffer/readonly.rs, doradb-storage/src/file/*
Readonly reads, invalidation, miss loading, write barriers, and active-root loading now receive caller-provided PoolGuard values.
Engine, session, catalog, and checkpoint propagation
doradb-storage/src/component.rs, doradb-storage/src/engine.rs, doradb-storage/src/session.rs, doradb-storage/src/catalog/*, doradb-storage/src/recovery/mod.rs, doradb-storage/src/trx/*, doradb-storage/src/table/persistence.rs
Engine-owned guards are separated from session-owned guards. Catalog, checkpoint, recovery, persistence, DDL, and maintenance paths pass explicit guards.
Index and test guard migration
doradb-storage/src/index/*, doradb-storage/src/table/*, doradb-storage/src/buffer/*
Index runtimes and tests use create_base_guard and cloned guards for mutable table-file and composite-index operations.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: sharding pool guards to improve performance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shard-pool-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 2 medium

Results:
2 new issues

Category Results
Complexity 2 medium

View in Codacy

🟢 Metrics 0 complexity · 22 duplication

Metric Results
Complexity 0
Duplication 22

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR shards buffer-pool guard roots by session to remove cross-session Arc reference-count contention while preserving pool identity and quiescent lifetime guarantees.

  • Adds independent pool-guard roots to each session and retains canonical roots for engine-owned work.
  • Threads owner-scoped guards through buffer, catalog, file, index, recovery, table, and transaction paths instead of creating roots in hot operations.
  • Renames guard creation APIs to make their allocation and lifecycle-boundary semantics explicit.
  • Adds lifecycle and root-identity tests and updates the associated architecture and performance documentation.

Confidence Score: 5/5

The PR appears safe to merge; no concrete correctness, lifecycle, security, or build failure was established.

Session-local roots are released through existing session lifecycle handling, idle sessions are removed before component teardown, and checked storage paths retain and pass matching pool guards across synchronous and detached work.

Important Files Changed

Filename Overview
doradb-storage/src/session.rs Stores one independent four-pool guard bundle per session and consistently exposes it through session runtime and transaction attachments.
doradb-storage/src/component.rs Separates canonical engine-owned pool roots from newly created session-local roots while retaining identical pool identities.
doradb-storage/src/buffer/arena.rs Renames base-guard construction and tests that independent roots share pool identity without sharing the outer reference-count root.
doradb-storage/src/buffer/readonly.rs Propagates caller-owned guards through invalidation, misses, write barriers, and detached I/O while retaining owned keepalives where work may outlive a borrow.
doradb-storage/src/engine.rs Removes canonical guard access from EngineCore and preserves shutdown ordering that releases idle session-owned roots before component teardown.
doradb-storage/src/file/cow_file.rs Extends CoW write barriers and active-root loading to use the caller’s readonly-pool guard.
doradb-storage/src/recovery/mod.rs Propagates recovery-owned pool guards through catalog and table-file reconstruction paths.
doradb-storage/src/quiescent.rs Adds test support for distinguishing shared SyncQuiescentGuard roots without changing production lifetime semantics.

Reviews (1): Last reviewed commit: "shard pool guard to improve performance" | Re-trigger Greptile

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.79254% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.55%. Comparing base (e5152e8) to head (d127bdb).

Files with missing lines Patch % Lines
doradb-storage/src/catalog/index.rs 69.23% 4 Missing ⚠️
doradb-storage/src/catalog/table.rs 93.75% 2 Missing ⚠️
doradb-storage/src/index/block_index.rs 66.66% 2 Missing ⚠️
doradb-storage/src/index/row_page_index.rs 94.44% 2 Missing ⚠️
doradb-storage/src/buffer/readonly.rs 99.25% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #964      +/-   ##
==========================================
+ Coverage   93.54%   93.55%   +0.01%     
==========================================
  Files         154      154              
  Lines      132893   133296     +403     
==========================================
+ Hits       124317   124709     +392     
- Misses       8576     8587      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

🧹 Nitpick comments (1)
doradb-storage/src/buffer/readonly.rs (1)

1285-1327: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a foreign-guard test for begin_write_barrier.

begin_write_barrier now validates the caller-supplied guard through pool.validate_guard(guard). The read path has test_global_readonly_pool_panics_on_foreign_guard to cover the identity-mismatch panic. No equivalent test exists for the write-barrier path. Add a test that calls begin_write_barrier with a guard from a different pool and asserts the panic.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@doradb-storage/src/buffer/readonly.rs` around lines 1285 - 1327, Add a test
in the existing readonly buffer tests module covering begin_write_barrier with a
PoolGuard created by a different ReadonlyBufferPool. Assert that the call panics
due to pool.validate_guard(guard), following the pattern of
test_global_readonly_pool_panics_on_foreign_guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@doradb-storage/src/buffer/readonly.rs`:
- Around line 1285-1327: Add a test in the existing readonly buffer tests module
covering begin_write_barrier with a PoolGuard created by a different
ReadonlyBufferPool. Assert that the call panics due to
pool.validate_guard(guard), following the pattern of
test_global_readonly_pool_panics_on_foreign_guard.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: fdd17b79-ce80-4f5b-b06a-8b8cf5771b5d

📥 Commits

Reviewing files that changed from the base of the PR and between e5152e8 and d127bdb.

⛔ Files ignored due to path filters (9)
  • docs/backlogs/closed/000175-scalable-shared-resource-lifetime-management.md is excluded by none and included by none
  • docs/engine-component-lifetime.md is excluded by none and included by none
  • docs/rfcs/0025-session-coordinated-cancellation-cleanup-ownership.md is excluded by none and included by none
  • docs/tasks/000102-separate-readonly-pool-interface-and-simplify-ownership.md is excluded by none and included by none
  • docs/tasks/000247-statement-public-transaction-cancellation-ownership.md is excluded by none and included by none
  • docs/tasks/000248-mandatory-operation-driver-and-concurrent-cleanup-executor.md is excluded by none and included by none
  • docs/tasks/000254-remove-engine-runtime-reference-accounting.md is excluded by none and included by none
  • docs/tasks/000255-session-local-runtime-reachability.md is excluded by none and included by none
  • docs/transaction-system.md is excluded by none and included by none
📒 Files selected for processing (42)
  • doradb-storage/src/buffer/arena.rs
  • doradb-storage/src/buffer/evict.rs
  • doradb-storage/src/buffer/evictor.rs
  • doradb-storage/src/buffer/fixed.rs
  • doradb-storage/src/buffer/guard.rs
  • doradb-storage/src/buffer/mod.rs
  • doradb-storage/src/buffer/pool_guard.rs
  • doradb-storage/src/buffer/readonly.rs
  • doradb-storage/src/catalog/checkpoint.rs
  • doradb-storage/src/catalog/index.rs
  • doradb-storage/src/catalog/mod.rs
  • doradb-storage/src/catalog/storage/mod.rs
  • doradb-storage/src/catalog/storage/tables.rs
  • doradb-storage/src/catalog/table.rs
  • doradb-storage/src/component.rs
  • doradb-storage/src/engine.rs
  • doradb-storage/src/file/cow_file.rs
  • doradb-storage/src/file/fs.rs
  • doradb-storage/src/file/multi_table_file.rs
  • doradb-storage/src/file/table_file.rs
  • doradb-storage/src/index/block_index.rs
  • doradb-storage/src/index/btree/cursor.rs
  • doradb-storage/src/index/btree/mod.rs
  • doradb-storage/src/index/btree/node.rs
  • doradb-storage/src/index/column_block_index.rs
  • doradb-storage/src/index/column_deletion_blob.rs
  • doradb-storage/src/index/disk_tree.rs
  • doradb-storage/src/index/non_unique_index.rs
  • doradb-storage/src/index/row_page_index.rs
  • doradb-storage/src/index/secondary_index.rs
  • doradb-storage/src/index/unique_index.rs
  • doradb-storage/src/quiescent.rs
  • doradb-storage/src/recovery/mod.rs
  • doradb-storage/src/session.rs
  • doradb-storage/src/table/access.rs
  • doradb-storage/src/table/gc.rs
  • doradb-storage/src/table/layout.rs
  • doradb-storage/src/table/mem_table.rs
  • doradb-storage/src/table/persistence.rs
  • doradb-storage/src/trx/mod.rs
  • doradb-storage/src/trx/purge.rs
  • doradb-storage/src/trx/retention.rs

@jiangzhe
jiangzhe merged commit 822dfe2 into main Aug 9, 2026
12 checks passed
@jiangzhe
jiangzhe deleted the shard-pool-guard branch August 9, 2026 01:43
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