Skip to content

Fix loss of root/meta blkno after self-invalidation; defer invalidation processing under page locks#55

Open
Serge-sudo wants to merge 1 commit intoorioledb:patches17from
Serge-sudo:fixed-invalid-meta-blocknum
Open

Fix loss of root/meta blkno after self-invalidation; defer invalidation processing under page locks#55
Serge-sudo wants to merge 1 commit intoorioledb:patches17from
Serge-sudo:fixed-invalid-meta-blocknum

Conversation

@Serge-sudo
Copy link
Copy Markdown
Contributor

Fix an issue where B-tree descriptor state (metaPageBlkno and rootPageBlkno) could be lost after processing an invalidation message within the same transaction.

Previously, after o_btree_load_shmem() initialized the descriptor, a invalidation message could be processed before the descriptor was used. This caused the descriptor to be recreated, resetting metaPageBlkno and rootPageBlkno to InvalidBlockNumber, which led to assertion failures (e.g. in btree_ctid_get_and_inc).

While investigating, another problem was identified: invalidation message processing may occur while holding page locks. Invalidation handlers access system trees, and if required pages are evicted, they trigger page loads. This leads to load_page() being called while locks are held, hitting assertions that forbid holding locks during page load.

To address both issues:

  • Ensure descriptor state is not lost due to mid-operation self-invalidation

  • Introduce deferred invalidation handling:

    • Skip invalidation message processing when it is unsafe (e.g. while holding page locks)
    • Process pending invalidation messages at the next safe point

This prevents descriptor corruption and avoids unsafe page loads under locks.

downlink -> orioledb/orioledb#792

…on processing under page locks

Fix an issue where B-tree descriptor state (`metaPageBlkno` and `rootPageBlkno`) could be lost after processing an invalidation message within the same transaction.

Previously, after `o_btree_load_shmem()` initialized the descriptor, a invalidation message could be processed before the descriptor was used. This caused the descriptor to be recreated, resetting `metaPageBlkno` and `rootPageBlkno` to `InvalidBlockNumber`, which led to assertion failures (e.g. in `btree_ctid_get_and_inc`).

While investigating, another problem was identified: invalidation message processing may occur while holding page locks. Invalidation handlers access system trees, and if required pages are evicted, they trigger page loads. This leads to `load_page()` being called while locks are held, hitting assertions that forbid holding locks during page load.

To address both issues:

* Ensure descriptor state is not lost due to mid-operation self-invalidation
* Introduce deferred invalidation handling:

  * Skip invalidation message processing when it is unsafe (e.g. while holding page locks)
  * Process pending invalidation messages at the next safe point

This prevents descriptor corruption and avoids unsafe page loads under locks.
@Serge-sudo Serge-sudo force-pushed the fixed-invalid-meta-blocknum branch from b8d017d to 2c21d4d Compare March 19, 2026 15:01
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