Skip to content

Rework MDL enum constants values#4912

Open
pranavktiwari wants to merge 5 commits into12.3from
12.3-MDEV-39184
Open

Rework MDL enum constants values#4912
pranavktiwari wants to merge 5 commits into12.3from
12.3-MDEV-39184

Conversation

@pranavktiwari
Copy link
Copy Markdown

@pranavktiwari pranavktiwari commented Apr 7, 2026

fixes MDEV-39184

Problem:

MDL constants values of 0 assign some default values (MDL_INTENTION_EXCLUSIVE, BACKUP) before MDL_REQUEST_INIT(). That does not make sense if MDL_REQUEST_INIT() was not called. Please rework the values of 0 into (MDL_NOT_INITIALIZED, NOT_INITIALIZED). Described by these comments in the code:

Fix

1- Increment all values in enum_mdl_type by 1.
2- Add a 0 at the start of the incompatibility arrays so the enum indices continue to match their corresponding bitmasks.

This ensures that uninitialized MDL constants are correctly handled while preserving existing bitmask mappings.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 7, 2026

CLA assistant check
All committers have signed the CLA.

@midenok
Copy link
Copy Markdown
Contributor

midenok commented Apr 8, 2026

Hi @pranavktiwari,

Thank you for the patch! Now I see that change for MDL_BIT has negative effect on performance which is unwanted. I'd better tell in the description that it is investigation task and should be evaluated for push. Nonetheless, if we rework enum_mdl_type into bitmask values we would not need MDL_BIT() at all. What other problems occur if we try that?

It seems that I cannot recognize the changes for the second part of the ticket (about enum_mdl_namespace). Is it feasible to do these changes? Can you try to do it on the minimal set of code, without plugins and minor storage engines?

@FooBarrior FooBarrior requested a review from svoj April 8, 2026 09:47
We have 16 bits and we have enums till 15 (0 to 15) even after increment. So if I leave MDL_BIT unchanged (do not subtract 1), it will work as bit masking is supported and in the range.
…_KEY. 2- Modified different arrays due to the new value added in the enum. 3- enums are used to calculate the hash and due to a new enum, hash values have changed and this causes ordering issue in the MDL_locks store. Subtracted one from enum where hash is computed to stick to oringal values of the hash.
Adding NOT_INITIALIZED=0 shifted all existing namespace enum values by +1,
changing their hash_value() results. Since m_locks uses a Split-Ordered List
(lock-free hash table) which maintains a single linked list sorted by
my_reverse_bits(hash_value()), even a +1 shift causes completely different
bit-reversed positions, changing iteration order in metadata_lock_info.

Fix: Updated result file to match new iteration order instead of using the
fragile -1 workaround in hash_value(), since iteration order is an internal
implementation detail of the lock-free hash table and has no impact on MDL
correctness.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reworks MDL enum constant values so that 0 represents an uninitialized MDL state (instead of mapping to real lock types), and updates related mappings/output so metadata lock reporting continues to work.

Changes:

  • Shifted enum_mdl_type / backup-stage lock constants so MDL_NOT_INITIALIZED becomes 0.
  • Introduced MDL_key::NOT_INITIALIZED=0 namespace and updated handlers/mappings accordingly.
  • Updated incompatibility matrices, metadata-lock name tables, and adjusted mysql-test expected results.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sql/sp.h Adds handling for MDL_key::NOT_INITIALIZED in namespace→handler switch.
sql/mdl.h Updates MDL type and namespace enums and shifts backup lock constants.
sql/mdl.cc Adds NOT_INITIALIZED PSI stage entry, pads name tables, and pads incompatibility arrays.
plugin/metadata_lock_info/metadata_lock_info.cc Adds “Not initialised” entry to namespace name table.
mysql-test/main/mdl_sync.result Updates expected output ordering for MDL metadata_lock_info.
mysql-test/main/mdl.result Updates expected output ordering for MDL metadata_lock_info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sql/mdl.cc Outdated

PSI_stage_info MDL_key::m_namespace_to_wait_state_name[NAMESPACE_END]=
{
{0, "Not initilised", 0},
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The new stage name string has a spelling error: "Not initilised". This ends up visible in processlist/performance schema stage output; please fix the typo (and ideally keep spelling consistent with the information_schema.metadata_lock_info strings).

Suggested change
{0, "Not initilised", 0},
{0, "Not initialised", 0},

Copilot uses AI. Check for mistakes.
sql/mdl.cc Outdated

static const LEX_STRING lock_types[]=
{
{},
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The 0th entry in lock_types is now an empty LEX_STRING (str==NULL). If any code path ends up calling get_mdl_lock_name()/get_type_name() with MDL_NOT_INITIALIZED (e.g., debug logging on an uninitialized MDL_request), this can lead to undefined behavior when printing "%s". Consider providing a real name like "MDL_NOT_INITIALIZED" instead of an empty initializer to keep it safe and debuggable.

Suggested change
{},
{ C_STRING_WITH_LEN("MDL_NOT_INITIALIZED") },

Copilot uses AI. Check for mistakes.
sql/mdl.cc Outdated

static const LEX_STRING backup_lock_types[]=
{
{},
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Same issue as lock_types[]: backup_lock_types[0] is now an empty LEX_STRING (str==NULL). If a backup-namespace MDL_request/ticket is ever inspected or logged with type==0, printing the name can dereference/format a NULL string. Using an explicit "MDL_NOT_INITIALIZED" (or similar) entry at index 0 would avoid surprises.

Suggested change
{},
{ C_STRING_WITH_LEN("MDL_BACKUP_NOT_INITIALIZED") },

Copilot uses AI. Check for mistakes.
Incorporated code review comments of copilot.
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.

5 participants