Skip to content

add MemIndexPage::err_ to cache the result error of ReadPage#422

Merged
lzxddz merged 2 commits intomainfrom
lzx-debug-build
Mar 18, 2026
Merged

add MemIndexPage::err_ to cache the result error of ReadPage#422
lzxddz merged 2 commits intomainfrom
lzx-debug-build

Conversation

@lzxddz
Copy link
Collaborator

@lzxddz lzxddz commented Mar 17, 2026

Here are some reminders before you submit the pull request

  • Add tests for the change
  • Document changes
  • Reference the link of issue using fixes eloqdb/eloqstore#issue_id
  • Reference the link of RFC if exists
  • Pass ctest --test-dir build/tests/

Summary by CodeRabbit

  • New Features
    • Added buffer-pool usage and capacity reporting for monitoring and capacity checks.
  • Bug Fixes
    • Added per-page error tracking to preserve pinned pages on load failures.
    • Improved error handling during allocation, deallocation and asynchronous reads to reduce races and ensure correct cleanup.

@lzxddz lzxddz requested a review from thweetkomputer March 17, 2026 11:09
@lzxddz lzxddz added the test label Mar 17, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Walkthrough

Adds per-page error state to MemIndexPage (new private member and public accessors) and updates IndexPageManager allocation, deallocation, and async load/wait paths to preserve or clear that state depending on pinning; also exposes buffer-pool query helpers (IsFull, GetBufferPoolUsed, GetBufferPoolLimit).

Changes

Cohort / File(s) Summary
MemIndexPage API
include/storage/mem_index_page.h
Added void SetError(KvError), KvError Error() const, and private KvError err_ (initialized to NoError) to track per-page error state.
Index Page Manager logic
src/storage/index_page_manager.cpp, src/storage/index_page_manager.h
Allocation asserts pages start with NoError; FreeIndexPage resets error; async read/fail paths now store errors on pinned pages (SetError) and only free non-pinned failed pages; added buffer-pool accessors IsFull(), GetBufferPoolUsed(), GetBufferPoolLimit().

Sequence Diagram

sequenceDiagram
    participant AsyncLoader as Async Page Loader
    participant PageMgr as Index Page Manager
    participant Page as MemIndexPage
    participant PinTracker as Pin Tracker

    rect rgba(200,150,200,0.5)
    Note over AsyncLoader,PinTracker: Async read fails
    AsyncLoader->>PageMgr: report read error (err)
    PageMgr->>PinTracker: is page pinned?
    PinTracker-->>PageMgr: pinned / not pinned
    alt pinned
        PageMgr->>Page: SetError(err)
    else not pinned
        PageMgr->>PageMgr: FreePage(page)
    end
    end

    rect rgba(150,200,150,0.5)
    Note over AsyncLoader,PageMgr: Wait completes with error
    AsyncLoader->>PageMgr: wait returns error
    PageMgr->>Page: Error()
    Page-->>PageMgr: return stored error
    PageMgr->>PinTracker: is page pinned?
    PinTracker-->>PageMgr: pinned / not pinned
    alt not pinned and has error
        PageMgr->>PageMgr: FreePage(page)
    else pinned
        PageMgr->>PageMgr: keep page, propagate error
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • eatbreads
  • thweetkomputer

Poem

🐰 I found a page with a little ache,
I tucked its error in a cozy break,
If pinned it stays, if loose it flies,
I hop and guard with watchful eyes,
Pages safe beneath my floppy skies 📄✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is essentially just the unchecked template checklist with no actual content explaining the changes, rationale, testing status, or issue references. Fill in the description with actual change details, rationale, and completion status of checklist items. Mark completed items and provide issue/RFC references.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: adding MemIndexPage::err_ member to cache ReadPage error results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 lzx-debug-build
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/storage/index_page_manager.cpp`:
- Around line 499-506: The page error must be published before waking waiters:
ensure the error is assigned (call new_page->SetError(err) or set the err_
state) prior to any code that notifies/wakes waiters; then wake waiters and
finally either FreeIndexPage(new_page) (if not pinned) or keep it pinned—i.e.,
move the SetError(err) (or err_ assignment) to occur before the
waiter-notification path so woken waiters observe the published error when
checking err_/NoError.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a545820-3826-4fa2-abe7-3239b70e7e49

📥 Commits

Reviewing files that changed from the base of the PR and between 24483fb and 131948d.

📒 Files selected for processing (2)
  • include/storage/mem_index_page.h
  • src/storage/index_page_manager.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/storage/index_page_manager.cpp`:
- Around line 498-506: The code leaves failed pages swizzled when IsPinned() is
true, which can cause detached callers to block on Wait() forever; modify the
logic so that before any detached handle calls Wait() it first checks
new_page->Error() and returns immediately if an error is set, OR alternatively
unswizzle/free the failed page regardless of pin status (move
mapping->Unswizzling(new_page) and FreeIndexPage(new_page) into the error branch
so SetError(err) is not the only action). Update the code paths around
new_page->IsPinned(), SetError(err), mapping->Unswizzling, FreeIndexPage, and
any caller that uses Wait() to consult Error() first to avoid indefinite
blocking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 822cae4c-5f62-4222-a17f-5c7daa1c91d9

📥 Commits

Reviewing files that changed from the base of the PR and between 131948d and 2d28dd1.

📒 Files selected for processing (1)
  • src/storage/index_page_manager.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/storage/index_page_manager.cpp (1)

498-507: Add regression coverage for the pinned failure path.

This change now relies on SetError(), WakeAll(), and the final FreeIndexPage() after the last pin drops. That interaction is subtle, and the PR checklist still has tests unchecked.

If helpful, I can sketch a loader+waiter FindPage() test that exercises this branch.

Also applies to: 518-526

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/storage/index_page_manager.cpp` around lines 498 - 507, Add a regression
test exercising the pinned-failure path: create a loader that pins an index page
via FindPage()/IsPinned(), simulate a failure that calls SetError(err) on the
pinned page and invokes waiting_.WakeAll(), and concurrently start a waiter that
calls FindPage() and waits on the page; assert the waiter observes the error,
wakes, and that after the pin is released the page is freed (FreeIndexPage is
invoked). Target the code paths around IsPinned, SetError, waiting_.WakeAll, and
FreeIndexPage (also add the same test covering the similar branch around the
lines referenced 518-526) to ensure the interaction between SetError/WakeAll and
final FreeIndexPage after the last pin is exercised and prevents regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/storage/index_page_manager.cpp`:
- Around line 498-507: Add a regression test exercising the pinned-failure path:
create a loader that pins an index page via FindPage()/IsPinned(), simulate a
failure that calls SetError(err) on the pinned page and invokes
waiting_.WakeAll(), and concurrently start a waiter that calls FindPage() and
waits on the page; assert the waiter observes the error, wakes, and that after
the pin is released the page is freed (FreeIndexPage is invoked). Target the
code paths around IsPinned, SetError, waiting_.WakeAll, and FreeIndexPage (also
add the same test covering the similar branch around the lines referenced
518-526) to ensure the interaction between SetError/WakeAll and final
FreeIndexPage after the last pin is exercised and prevents regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 938e8394-9dfb-443a-93a6-f79a1ab39790

📥 Commits

Reviewing files that changed from the base of the PR and between 2d28dd1 and 5ac8e3e.

📒 Files selected for processing (1)
  • src/storage/index_page_manager.cpp

@lzxddz lzxddz merged commit 5a8215c into main Mar 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants