diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2022-10-25 14:25:42 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2022-10-25 14:25:42 +0300 |
commit | aeccbbd926e759a5c3b9818d9948a35918404478 (patch) | |
tree | e3ee68a92d2c77f986979e1638169280ede35a96 /storage/innobase/include | |
parent | 75f7c5681c2592b50c26feff2371bd7ee973e535 (diff) | |
parent | 4b4c2b8cc0da949895292121ed5ef3e0c2dbaae1 (diff) | |
download | mariadb-git-aeccbbd926e759a5c3b9818d9948a35918404478.tar.gz |
Merge 10.5 into 10.6
To prevent ASAN heap-use-after-poison in the MDEV-16549 part of
./mtr --repeat=6 main.derived
the initialization of Name_resolution_context was cleaned up.
Diffstat (limited to 'storage/innobase/include')
-rw-r--r-- | storage/innobase/include/trx0trx.h | 56 | ||||
-rw-r--r-- | storage/innobase/include/ut0lst.h | 31 |
2 files changed, 55 insertions, 32 deletions
diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 91d1ec94e1b..2f8bee1bc4d 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -570,15 +570,20 @@ struct trx_t : ilist_node<> { private: /** - Count of references. + Least significant 31 bits is count of references. We can't release the locks nor commit the transaction until this reference is 0. We can change the state to TRX_STATE_COMMITTED_IN_MEMORY to signify that it is no longer "active". - */ + If the most significant bit is set this transaction should stop inheriting + (GAP)locks. Generally set to true during transaction prepare for RC or lower + isolation, if requested. Needed for replication replay where + we don't want to get blocked on GAP locks taken for protecting + concurrent unique insert or replace operation. + */ alignas(CPU_LEVEL1_DCACHE_LINESIZE) - Atomic_counter<int32_t> n_ref; + Atomic_relaxed<uint32_t> skip_lock_inheritance_and_n_ref; public: @@ -983,26 +988,48 @@ public: void savepoints_discard(trx_named_savept_t *savept); - bool is_referenced() const { return n_ref > 0; } + bool is_referenced() const + { + return (skip_lock_inheritance_and_n_ref & ~(1U << 31)) > 0; + } void reference() { -#ifdef UNIV_DEBUG - auto old_n_ref= -#endif - n_ref++; - ut_ad(old_n_ref >= 0); + ut_d(auto old_n_ref =) + skip_lock_inheritance_and_n_ref.fetch_add(1); + ut_ad(int32_t(old_n_ref << 1) >= 0); } - void release_reference() { -#ifdef UNIV_DEBUG - auto old_n_ref= + ut_d(auto old_n_ref =) + skip_lock_inheritance_and_n_ref.fetch_sub(1); + ut_ad(int32_t(old_n_ref << 1) > 0); + } + + bool is_not_inheriting_locks() const + { + return skip_lock_inheritance_and_n_ref >> 31; + } + + void set_skip_lock_inheritance() + { + ut_d(auto old_n_ref=) skip_lock_inheritance_and_n_ref.fetch_add(1U << 31); + ut_ad(!(old_n_ref >> 31)); + } + + void reset_skip_lock_inheritance() + { +#if defined __GNUC__ && (defined __i386__ || defined __x86_64__) + __asm__("lock btrl $31, %0" : : "m"(skip_lock_inheritance_and_n_ref)); +#elif defined _MSC_VER && (defined _M_IX86 || defined _M_X64) + _interlockedbittestandreset( + reinterpret_cast<volatile long *>(&skip_lock_inheritance_and_n_ref), + 31); +#else + skip_lock_inheritance_and_n_ref.fetch_and(~1U << 31); #endif - n_ref--; - ut_ad(old_n_ref > 0); } /** @return whether the table has lock on @@ -1032,6 +1059,7 @@ public: ut_ad(UT_LIST_GET_LEN(lock.evicted_tables) == 0); ut_ad(!dict_operation); ut_ad(!apply_online_log); + ut_ad(!is_not_inheriting_locks()); } /** This has to be invoked on SAVEPOINT or at the end of a statement. diff --git a/storage/innobase/include/ut0lst.h b/storage/innobase/include/ut0lst.h index 9a5f3059826..7b7ed7b8e80 100644 --- a/storage/innobase/include/ut0lst.h +++ b/storage/innobase/include/ut0lst.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2019, MariaDB Corporation. +Copyright (c) 2019, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,8 +25,7 @@ Created 9/10/1995 Heikki Tuuri Rewritten by Sunny Bains Dec 2011. ***********************************************************************/ -#ifndef ut0lst_h -#define ut0lst_h +#pragma once /* Do not include univ.i because univ.i includes this. */ @@ -474,17 +473,17 @@ template <typename List, class Functor> void ut_list_validate(const List& list, Functor& functor) { ut_list_map(list, functor); - +#ifdef UNIV_DEBUG /* Validate the list backwards. */ - ulint count = 0; + ulint count = list.count; for (typename List::elem_type* elem = list.end; elem != 0; elem = (elem->*list.node).prev) { - ++count; + --count; } - - ut_a(count == list.count); + ut_ad(!count); +#endif } /** Check the consistency of a doubly linked list. @@ -494,23 +493,24 @@ template <typename List, class Functor> inline void ut_list_validate(const List& list, const Functor& functor) { ut_list_map(list, functor); - +#ifdef UNIV_DEBUG /* Validate the list backwards. */ - ulint count = 0; + ulint count = list.count; for (typename List::elem_type* elem = list.end; elem != 0; elem = (elem->*list.node).prev) { - ++count; + --count; } - ut_a(count == list.count); + ut_ad(!count); +#endif } template <typename List> inline void ut_list_validate(const List& list) { - ut_list_validate(list, NullValidate()); + ut_d(ut_list_validate(list, NullValidate())); } #ifdef UNIV_DEBUG @@ -561,8 +561,3 @@ ut_list_move_to_front( ut_list_prepend(list, elem); } } - -#ifdef UNIV_DEBUG -#endif - -#endif /* ut0lst.h */ |