Skip to content

Commit f3ff45f

Browse files
committed
MDEV-15658: Assertion failed in lock_rec_other_trx_holds_expl_callback
Fix a race condition that was introduced in debug code by MDEV-14638. lock_rec_other_trx_holds_expl(): After acquiring the lock_sys->mutex, check if the transaction might have been committed. Otherwise, the assertion in the trx_sys.rw_trx_hash traversal callback could fail.
1 parent 349560d commit f3ff45f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

storage/innobase/lock/lock0lock.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2014, 2018, MariaDB Corporation.
4+
Copyright (c) 2014, 2019, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -5527,6 +5527,20 @@ static void lock_rec_other_trx_holds_expl(trx_t *caller_trx, trx_t *trx,
55275527
{
55285528
ut_ad(!page_rec_is_metadata(rec));
55295529
lock_mutex_enter();
5530+
ut_ad(trx->is_referenced());
5531+
/* Prevent a data race with trx_prepare(), which could change the
5532+
state from ACTIVE to PREPARED. Other state changes should be
5533+
blocked by lock_mutex_own() and trx->is_referenced(). */
5534+
trx_mutex_enter(trx);
5535+
const trx_state_t state = trx->state;
5536+
trx_mutex_exit(trx);
5537+
ut_ad(state != TRX_STATE_NOT_STARTED);
5538+
if (state == TRX_STATE_COMMITTED_IN_MEMORY)
5539+
{
5540+
/* The transaction was committed before our lock_mutex_enter(). */
5541+
lock_mutex_exit();
5542+
return;
5543+
}
55305544
lock_rec_other_trx_holds_expl_arg arg= { page_rec_get_heap_no(rec), block,
55315545
trx };
55325546
trx_sys.rw_trx_hash.iterate(caller_trx,

0 commit comments

Comments
 (0)