Skip to content

Commit

Permalink
MDEV-25404 fixup: Fix ssux_lock_low::u_wr_upgrade()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Apr 22, 2021
1 parent 54c460a commit 8121d03
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions storage/innobase/include/srw_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 8121d03

Please sign in to comment.