summaryrefslogtreecommitdiff
path: root/storage/innobase/mtr/mtr0mtr.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-11-13 20:45:28 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-11-13 20:45:28 +0200
commit749ecedfece22d5bdb27a5f682d430e1aa6ec194 (patch)
tree1afe5554a6dc3060204da84eca4f5029e71745b0 /storage/innobase/mtr/mtr0mtr.cc
parentb63dc3f3703af888c564521d9a22c661940c02d1 (diff)
parentf9f2f37495e70128142ea56544b40854f6b2afe5 (diff)
downloadmariadb-git-749ecedfece22d5bdb27a5f682d430e1aa6ec194.tar.gz
MDEV-24188: Merge 10.3 into 10.4
Diffstat (limited to 'storage/innobase/mtr/mtr0mtr.cc')
-rw-r--r--storage/innobase/mtr/mtr0mtr.cc72
1 files changed, 46 insertions, 26 deletions
diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc
index 5ca74659813..3ed9856a58a 100644
--- a/storage/innobase/mtr/mtr0mtr.cc
+++ b/storage/innobase/mtr/mtr0mtr.cc
@@ -308,24 +308,6 @@ struct DebugCheck {
};
#endif
-/** Find buffer fix count of the given block acquired by the
-mini-transaction */
-struct FindBlock
-{
- int32_t num_fix;
- const buf_block_t *const block;
-
- FindBlock(const buf_block_t *block_buf): num_fix(0), block(block_buf) {}
-
- bool operator()(const mtr_memo_slot_t* slot)
- {
- if (slot->object == block)
- ut_d(if (slot->type != MTR_MEMO_MODIFY))
- num_fix++;
- return true;
- }
-};
-
/** Release a resource acquired by the mini-transaction. */
struct ReleaseBlocks {
/** Release specific object */
@@ -753,12 +735,48 @@ inline lsn_t mtr_t::finish_write(ulint len)
return start_lsn;
}
-uint32_t mtr_t::get_fix_count(const buf_block_t *block)
+/** Find out whether a block was X-latched by the mini-transaction */
+struct FindBlockX
{
- Iterate<FindBlock> iteration((FindBlock(block)));
- if (m_memo.for_each_block(iteration))
- return iteration.functor.num_fix;
- return 0;
+ const buf_block_t &block;
+
+ FindBlockX(const buf_block_t &block): block(block) {}
+
+ /** @return whether the block was not found x-latched */
+ bool operator()(const mtr_memo_slot_t *slot) const
+ {
+ return slot->object != &block || slot->type == MTR_MEMO_PAGE_X_FIX;
+ }
+};
+
+#ifdef UNIV_DEBUG
+/** Assert that the block is not present in the mini-transaction */
+struct FindNoBlock
+{
+ const buf_block_t &block;
+
+ FindNoBlock(const buf_block_t &block): block(block) {}
+
+ /** @return whether the block was not found */
+ bool operator()(const mtr_memo_slot_t *slot) const
+ {
+ return slot->object != &block;
+ }
+};
+#endif /* UNIV_DEBUG */
+
+bool mtr_t::have_x_latch(const buf_block_t &block) const
+{
+ if (m_memo.for_each_block(CIterate<FindBlockX>(FindBlockX(block))))
+ {
+ ut_ad(m_memo.for_each_block(CIterate<FindNoBlock>(FindNoBlock(block))));
+ ut_ad(!memo_contains_flagged(&block,
+ MTR_MEMO_PAGE_S_FIX | MTR_MEMO_PAGE_SX_FIX |
+ MTR_MEMO_BUF_FIX | MTR_MEMO_MODIFY));
+ return false;
+ }
+ ut_ad(rw_lock_own(&block.lock, RW_LOCK_X));
+ return true;
}
#ifdef UNIV_DEBUG
@@ -775,15 +793,17 @@ mtr_t::memo_contains(
return(false);
}
+ const rw_lock_t *lock = static_cast<const rw_lock_t*>(object);
+
switch (type) {
case MTR_MEMO_X_LOCK:
- ut_ad(rw_lock_own((rw_lock_t*) object, RW_LOCK_X));
+ ut_ad(rw_lock_own(lock, RW_LOCK_X));
break;
case MTR_MEMO_SX_LOCK:
- ut_ad(rw_lock_own((rw_lock_t*) object, RW_LOCK_SX));
+ ut_ad(rw_lock_own(lock, RW_LOCK_SX));
break;
case MTR_MEMO_S_LOCK:
- ut_ad(rw_lock_own((rw_lock_t*) object, RW_LOCK_S));
+ ut_ad(rw_lock_own(lock, RW_LOCK_S));
break;
}