Skip to content

perf: implement session-local runtime reachability and retire engine ref - #941

Merged
jiangzhe merged 2 commits into
mainfrom
session-runtime
Aug 5, 2026
Merged

perf: implement session-local runtime reachability and retire engine ref#941
jiangzhe merged 2 commits into
mainfrom
session-runtime

Conversation

@jiangzhe

@jiangzhe jiangzhe commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Refactor

    • Improved storage engine lifecycle and session handling for more reliable transaction, shutdown, and cleanup behavior.
    • Streamlined access to shared storage resources across catalog, table, index, and recovery operations.
    • Reduced unnecessary resource duplication and strengthened ownership of transaction and buffer resources.
  • Tests

    • Updated and expanded coverage for recovery, catalog, transaction lifecycle, shutdown, and resource management scenarios.
    • Added validation for dropped-table cleanup and session admission edge cases.

@jiangzhe jiangzhe self-assigned this Aug 4, 2026
@jiangzhe

jiangzhe commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • docs/tasks/000255-session-local-runtime-reachability.md is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b489313-f2fd-41f5-b41b-c13163175442

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR replaces EngineRef-based ownership with EngineCore, EngineInner, EnginePools, and SessionRuntime. Catalog, table, index, recovery, and transaction paths now use explicit capabilities and runtime-backed cleanup.

Changes

Engine and runtime ownership

Layer / File(s) Summary
Engine capabilities and pools
doradb-storage/src/engine.rs, doradb-storage/src/component.rs, doradb-storage/src/buffer/*
The engine now separates shared core capabilities from owner state. EnginePools stores canonical pool handles and guards.
Session and transaction lifecycle
doradb-storage/src/session.rs, doradb-storage/src/trx/*, doradb-storage/src/log/*
Session admission, transaction claims, attachments, rollback, shutdown blockers, and abandoned cleanup now use SessionRuntime and exact session operations.
Catalog and DDL integration
doradb-storage/src/catalog/*
Table and index DDL paths receive explicit catalog, pool, filesystem, transaction-system, core, and poisoner dependencies.
Index, table, and recovery integration
doradb-storage/src/index/*, doradb-storage/src/table/*, doradb-storage/src/recovery/*
Read handles retain separate index and disk guards. Tests and runtime paths use nested core and pool accessors. Recovery assertions use the new engine structure.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • jiangzhe/doradb#915: Introduces the session-operation coordinator used by this runtime migration.
  • jiangzhe/doradb#925: Refactors runtime-owned table DDL paths that this PR updates to the EngineCore and SessionRuntime model.
  • jiangzhe/doradb#927: Refactors runtime-owned index DDL paths used by this engine-capability migration.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Session
  participant EngineCore
  participant TransactionSystem
  participant Catalog
  Client->>Session: start operation
  Session->>EngineCore: admit runtime and resolve capabilities
  Session->>TransactionSystem: claim transaction operation
  TransactionSystem->>Catalog: execute catalog or table operation
  Catalog-->>TransactionSystem: return operation result
  TransactionSystem-->>Session: update runtime operation state
  Session-->>Client: return result
Loading
🚥 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 changes: introducing session-local runtime reachability and removing the obsolete engine reference model.
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 session-runtime

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 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -15 complexity · 44 duplication

Metric Results
Complexity -15
Duplication 44

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 4, 2026

Copy link
Copy Markdown

Greptile Summary

The PR replaces engine-wide runtime references and session-registry hot-path lookups with session-local runtime reachability while preserving lifecycle admission and terminal ownership.

  • Introduces EngineCore, SessionRuntime, and exact-state weak session handles.
  • Moves transaction checkout, terminal publication, and cleanup to direct session-state resolution.
  • Centralizes pool capabilities and narrows retained guards across catalog, table, index, recovery, and transaction operations.
  • Updates lifecycle documentation and tests for shutdown, recovery, cleanup, and session admission.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains in the eligible follow-up scope.

No blocking failure remains.

Important Files Changed

Filename Overview
doradb-storage/src/engine.rs Splits owner coordination from shared runtime capabilities and preserves lifecycle admission and reverse component teardown.
doradb-storage/src/session.rs Adds exact-state weak and strong session runtime types while retaining stable operation, observer, close, abandonment, and pointer-exact removal semantics.
doradb-storage/src/trx/mod.rs Refactors transaction checkout and terminal ownership around SessionRuntime while preserving operation-key, transaction-ID, lock-release, and cleanup checks.
doradb-storage/src/trx/sys.rs Carries exact session runtime authority through abandoned and failed-precommit cleanup submission.
doradb-storage/src/component.rs Centralizes typed pool capabilities and canonical pool guards without changing component shutdown dependencies.
doradb-storage/src/catalog/index.rs Narrows index DDL capability access while accepted execution remains backed by session runtime ownership.
doradb-storage/src/recovery/resources.rs Makes recovery retain independent pool capabilities and guards rather than relying on engine-wide references.
doradb-storage/src/index/owned_stream.rs Retains only the pool guards required by owned index-stream operations.

Reviews (2): Last reviewed commit: "resolve task" | Re-trigger Greptile

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: ba41a029fc

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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 (3)
doradb-storage/src/engine.rs (1)

517-518: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the weak registry field to separate it from the strong owner field.

EngineCore::session_registry is a Weak<SessionRegistry>, and EngineInner::session_registry is an Arc<SessionRegistry>. EngineInner also derefs to EngineCore. Field access prefers the inherent field, so inner.session_registry resolves to the strong Arc and only inner.core.session_registry reaches the Weak. The two identically named fields with opposite ownership strength make that distinction invisible at each call site, and the doc comment at Line 499 states the weak edge must never drive operation resolution.

Rename the weak field to make the ownership strength explicit at every use.

♻️ Proposed rename
-    /// Cold weak back-reference for pointer-exact idle-session removal.
-    pub(crate) session_registry: Weak<SessionRegistry>,
+    /// Cold weak back-reference for pointer-exact idle-session removal.
+    pub(crate) weak_session_registry: Weak<SessionRegistry>,

Update the bootstrap initializer accordingly:

-        session_registry: Arc::downgrade(&session_registry),
+        weak_session_registry: Arc::downgrade(&session_registry),
🤖 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/engine.rs` around lines 517 - 518, Rename the weak
registry field on EngineCore from session_registry to an ownership-explicit name
such as weak_session_registry, and update its bootstrap initializer and every
access accordingly. Leave EngineInner::session_registry unchanged so strong and
weak registry references remain clearly distinguishable at call sites.
doradb-storage/src/session.rs (1)

817-1005: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider one access style for EngineCore.

SessionRuntime exposes core() and also implements Deref<Target = EngineCore>. Call sites then mix both forms, for example self.core().catalog inside catalog_guard and admitted.runtime().poisoner in pin_observer. The behavior is identical, so this is only a readability concern. Keep Deref for capability field access and use core() only where an explicit &EngineCore is required, or drop one of the two.

🤖 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/session.rs` around lines 817 - 1005, Standardize
EngineCore access in SessionRuntime call sites: retain Deref for direct
capability field access, and use core() only when an explicit &EngineCore is
required. Update mixed usages such as catalog_guard and pin_observer without
changing behavior, and keep the existing SessionRuntime::core and Deref
implementations unless removing one is necessary for consistency.
doradb-storage/src/table/persistence.rs (1)

1680-1706: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use engine.maintenance_test directly in retry hook calls.

session.engine() returns the EngineCore, while these listeners are already bound from session.runtime() as engine. Use engine.maintenance_test for the hook call inside the existing runtime borrow to avoid a second accessor invocation in observe_active_root_retry and observe_frozen_page_retry.

🤖 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/table/persistence.rs` around lines 1680 - 1706, Update the
test hook call in observe_active_root_retry to pass engine.maintenance_test
directly instead of calling session.engine().maintenance_test. Apply the same
change in observe_frozen_page_retry, reusing the existing engine binding
obtained from session.runtime().
🤖 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/engine.rs`:
- Around line 517-518: Rename the weak registry field on EngineCore from
session_registry to an ownership-explicit name such as weak_session_registry,
and update its bootstrap initializer and every access accordingly. Leave
EngineInner::session_registry unchanged so strong and weak registry references
remain clearly distinguishable at call sites.

In `@doradb-storage/src/session.rs`:
- Around line 817-1005: Standardize EngineCore access in SessionRuntime call
sites: retain Deref for direct capability field access, and use core() only when
an explicit &EngineCore is required. Update mixed usages such as catalog_guard
and pin_observer without changing behavior, and keep the existing
SessionRuntime::core and Deref implementations unless removing one is necessary
for consistency.

In `@doradb-storage/src/table/persistence.rs`:
- Around line 1680-1706: Update the test hook call in observe_active_root_retry
to pass engine.maintenance_test directly instead of calling
session.engine().maintenance_test. Apply the same change in
observe_frozen_page_retry, reusing the existing engine binding obtained from
session.runtime().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: e74c2af4-d516-4255-9223-c2810fc3023e

📥 Commits

Reviewing files that changed from the base of the PR and between 2098cbb and ba41a02.

⛔ Files ignored due to path filters (8)
  • docs/architecture.md is excluded by none and included by none
  • docs/backlogs/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/lock-system.md is excluded by none and included by none
  • docs/public-error-audit.csv is excluded by !**/*.csv and included by none
  • docs/tasks/000255-session-local-runtime-reachability.md is excluded by none and included by none
  • docs/tasks/next-id is excluded by none and included by none
  • docs/transaction-system.md is excluded by none and included by none
📒 Files selected for processing (37)
  • doradb-storage/src/buffer/evict.rs
  • doradb-storage/src/buffer/readonly.rs
  • doradb-storage/src/catalog/checkpoint.rs
  • doradb-storage/src/catalog/history.rs
  • doradb-storage/src/catalog/index.rs
  • doradb-storage/src/catalog/mod.rs
  • doradb-storage/src/catalog/storage/columns.rs
  • doradb-storage/src/catalog/storage/indexes.rs
  • doradb-storage/src/catalog/storage/mod.rs
  • doradb-storage/src/catalog/storage/table_replay_silent_watermarks.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/index/mod.rs
  • doradb-storage/src/index/owned_stream.rs
  • doradb-storage/src/index/row_page_index.rs
  • doradb-storage/src/log/mod.rs
  • doradb-storage/src/log/prefix.rs
  • doradb-storage/src/recovery/mod.rs
  • doradb-storage/src/recovery/resources.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/mod.rs
  • doradb-storage/src/table/persistence.rs
  • doradb-storage/src/table/recover.rs
  • doradb-storage/src/trx/admission.rs
  • doradb-storage/src/trx/group.rs
  • doradb-storage/src/trx/mod.rs
  • doradb-storage/src/trx/purge.rs
  • doradb-storage/src/trx/retention.rs
  • doradb-storage/src/trx/stmt.rs
  • doradb-storage/src/trx/sys.rs
  • doradb-storage/src/trx/sys_trx.rs
💤 Files with no reviewable changes (3)
  • doradb-storage/src/log/prefix.rs
  • doradb-storage/src/trx/sys_trx.rs
  • doradb-storage/src/trx/group.rs

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.00637% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.48%. Comparing base (2098cbb) to head (ba41a02).

Files with missing lines Patch % Lines
doradb-storage/src/catalog/index.rs 79.54% 27 Missing ⚠️
doradb-storage/src/catalog/table.rs 95.78% 10 Missing ⚠️
doradb-storage/src/trx/mod.rs 95.23% 8 Missing ⚠️
doradb-storage/src/table/persistence.rs 97.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #941      +/-   ##
==========================================
+ Coverage   93.38%   93.48%   +0.09%     
==========================================
  Files         149      149              
  Lines      126873   127741     +868     
==========================================
+ Hits       118486   119414     +928     
+ Misses       8387     8327      -60     

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

@jiangzhe
jiangzhe merged commit d9684e3 into main Aug 5, 2026
10 checks passed
@jiangzhe
jiangzhe deleted the session-runtime branch August 5, 2026 00:15
@jiangzhe

jiangzhe commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

Closes #940

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