Skip to content

MDEV-39795: Assertion `n_reserved > 0' failed#5356

Open
mariadb-TafzeelShams wants to merge 1 commit into
10.6from
10.6-MDEV-39795
Open

MDEV-39795: Assertion `n_reserved > 0' failed#5356
mariadb-TafzeelShams wants to merge 1 commit into
10.6from
10.6-MDEV-39795

Conversation

@mariadb-TafzeelShams

@mariadb-TafzeelShams mariadb-TafzeelShams commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
  • The Jira issue number for this PR is: MDEV-39795

Description

Problem:

  1. Assertion n_reserved > 0 failed in fseg_create():

fsp_reserve_free_extents() has a special condition for small tablespaces where it reserves individual pages instead of full extents. In such cases, n_reserved can be 0 even when the reservation succeeds, causing the assertion ut_ad(n_reserved > 0) to fail incorrectly.

The code was checking n_reserved to determine whether a reservation had already been attempted, but this logic breaks for small tablespaces where pages, rather than extents, are reserved.

  1. Encryption metadata not cleared for compressed-only pages:

buf_page_encrypt() only cleared encryption-related metadata fields (key-version and crypt-checksum) when the page was neither encrypted nor compressed. However, these fields should also be cleared when page_compressed is true but encrypted is false, to avoid leaving stale encryption metadata in compressed-only pages.

Solution:

buf_page_encrypt(): Refactored the early-return logic. Encryption metadata fields are now cleared whenever encrypted is false, regardless of page_compressed. The function returns early only when both !encrypted and !page_compressed.

fseg_create(): Introduced a boolean variable reserved to track whether fsp_reserve_free_extents() has been attempted, replacing the flawed check of n_reserved > 0. Added an early return when DB_DECRYPTION_FAILED is encountered during inode allocation.

my_error_innodb(): Added handling for DB_DECRYPTION_FAILED to report decryption errors to the user through ER_GET_ERRMSG.

Release Notes

Fixed assertion failure n_reserved > 0

How can this PR be tested?

Added MTR test case innodb_encrypt_compression_algorithm.test

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@mariadb-TafzeelShams
mariadb-TafzeelShams marked this pull request as ready for review July 8, 2026 00:49
Problem:
========

1. Assertion `n_reserved > 0` failed in fseg_create():

fsp_reserve_free_extents() has a special condition for small
tablespaces where it reserves individual pages instead of full
extents. In such cases, n_reserved can be 0 even when the
reservation succeeds, causing the assertion ut_ad(n_reserved > 0)
to fail incorrectly.

The code was checking n_reserved to determine whether a reservation
had already been attempted, but this logic breaks for small
tablespaces where pages, rather than extents, are reserved.

2. Encryption metadata not cleared for compressed-only pages:

buf_page_encrypt() only cleared encryption-related metadata
fields (key-version and crypt-checksum) when the page was
neither encrypted nor compressed. However, these fields should
also be cleared when page_compressed is true but encrypted is
false, to avoid leaving stale encryption metadata in
compressed-only pages.

Solution:
=========

buf_page_encrypt(): Refactored the early-return logic. Encryption
metadata fields are now cleared whenever encrypted is false,
regardless of page_compressed. The function returns early only
when both !encrypted and !page_compressed.

fseg_create(): Reintroduced a boolean variable `reserved` to track
whether fsp_reserve_free_extents() has been attempted (removed as
part of MDEV-38419 | c7313da), replacing assertion `n_reserved > 0`.
Added an early return when DB_DECRYPTION_FAILED is encountered
during inode allocation.

my_error_innodb(): Added handling for DB_DECRYPTION_FAILED to
report decryption errors to the user through ER_GET_ERRMSG.
reserved successfully.
See fsp_reserve_free_extents()
So try allocating the page or inode */
reserved = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

reserved = (*err == DB_SUCCESS);

case DB_CORRUPTION:
my_error(ER_NOT_KEYFILE, MYF(0), table);
break;
case DB_DECRYPTION_FAILED:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please test it without fixing page_compressed + encryption test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants