Commit 8121d03f authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-25404 fixup: Fix ssux_lock_low::u_wr_upgrade()

The U-to-X upgrade turned out to be incorrect. A debug assertion
failed in wr_wait(), called from mtr_defer_drop_ahi() in a stress
test with innodb_adaptive_hash_index=ON.

A correct upgrade procedure ought to be readers.fetch_add(WRITER-1)
to register ourselves as a WRITER (or waiting writer) and to release
the reference that was being held for the U lock.

Thanks to Matthias Leich for catching the problem.
parent 54c460ac
......@@ -217,11 +217,9 @@ class ssux_lock_low final
void u_wr_upgrade()
{
DBUG_ASSERT(writer.is_locked());
uint32_t lk= 1;
if (!readers.compare_exchange_strong(lk, WRITER,
std::memory_order_acquire,
std::memory_order_relaxed))
wr_wait(lk);
uint32_t lk= readers.fetch_add(WRITER - 1, std::memory_order_acquire);
if (lk != 1)
wr_wait(lk - 1);
}
void wr_u_downgrade()
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment