Skip to content

Commit 06ef550

Browse files
committed
MDEV-24167: Replace trx_purge_latch
1 parent 63dd2a9 commit 06ef550

File tree

10 files changed

+53
-53
lines changed

10 files changed

+53
-53
lines changed

mysql-test/suite/perfschema/r/sxlock_func.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ wait/synch/sxlock/innodb/fil_space_latch
1212
wait/synch/sxlock/innodb/fts_cache_init_rw_lock
1313
wait/synch/sxlock/innodb/fts_cache_rw_lock
1414
wait/synch/sxlock/innodb/index_tree_rw_lock
15-
wait/synch/sxlock/innodb/trx_purge_latch
1615
select name from performance_schema.rwlock_instances
1716
where name in
1817
(
@@ -25,7 +24,6 @@ where name in
2524
order by name;
2625
name
2726
wait/synch/sxlock/innodb/dict_operation_lock
28-
wait/synch/sxlock/innodb/trx_purge_latch
2927
drop table if exists t1;
3028
create table t1(a int) engine=innodb;
3129
begin;

storage/innobase/handler/ha_innodb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static PSI_rwlock_info all_innodb_rwlocks[] = {
569569
PSI_RWLOCK_KEY(fts_cache_rw_lock),
570570
PSI_RWLOCK_KEY(fts_cache_init_rw_lock),
571571
{ &trx_i_s_cache_lock_key, "trx_i_s_cache_lock", 0 },
572-
PSI_RWLOCK_KEY(trx_purge_latch),
572+
{ &trx_purge_latch_key, "trx_purge_latch", 0 },
573573
PSI_RWLOCK_KEY(index_tree_rw_lock),
574574
};
575575
# endif /* UNIV_PFS_RWLOCK */

storage/innobase/include/sync0types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ enum latch_level_t {
224224
SYNC_RSEG_HEADER_NEW,
225225
SYNC_NOREDO_RSEG,
226226
SYNC_REDO_RSEG,
227-
SYNC_PURGE_LATCH,
228227
SYNC_TREE_NODE,
229228
SYNC_TREE_NODE_FROM_HASH,
230229
SYNC_TREE_NODE_NEW,
@@ -296,7 +295,6 @@ enum latch_id_t {
296295
LATCH_ID_FIL_SPACE,
297296
LATCH_ID_FTS_CACHE,
298297
LATCH_ID_FTS_CACHE_INIT,
299-
LATCH_ID_TRX_PURGE,
300298
LATCH_ID_IBUF_INDEX_TREE,
301299
LATCH_ID_INDEX_TREE,
302300
LATCH_ID_DICT_TABLE_STATS,

storage/innobase/include/trx0purge.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Created 3/26/1996 Heikki Tuuri
2929

3030
#include "trx0rseg.h"
3131
#include "que0types.h"
32+
#include "srw_lock.h"
3233

3334
#include <queue>
3435

@@ -127,11 +128,9 @@ class purge_sys_t
127128
{
128129
public:
129130
/** latch protecting view, m_enabled */
130-
MY_ALIGNED(CACHE_LINE_SIZE)
131-
mutable rw_lock_t latch;
131+
MY_ALIGNED(CACHE_LINE_SIZE) mutable srw_lock latch;
132132
private:
133133
/** The purge will not remove undo logs which are >= this view */
134-
MY_ALIGNED(CACHE_LINE_SIZE)
135134
ReadViewBase view;
136135
/** whether purge is enabled; protected by latch and std::atomic */
137136
std::atomic<bool> m_enabled;
@@ -249,23 +248,20 @@ class purge_sys_t
249248
/** A wrapper around ReadView::changes_visible(). */
250249
bool changes_visible(trx_id_t id, const table_name_t &name) const
251250
{
252-
ut_ad(rw_lock_own(&latch, RW_LOCK_S));
253251
return view.changes_visible(id, name);
254252
}
255253
/** A wrapper around ReadView::low_limit_no(). */
256254
trx_id_t low_limit_no() const
257255
{
258-
#if 0 /* Unfortunately we don't hold this assertion, see MDEV-22718. */
259-
ut_ad(rw_lock_own(&latch, RW_LOCK_S));
260-
#endif
256+
/* MDEV-22718 FIXME: We are not holding latch here! */
261257
return view.low_limit_no();
262258
}
263259
/** A wrapper around trx_sys_t::clone_oldest_view(). */
264260
void clone_oldest_view()
265261
{
266-
rw_lock_x_lock(&latch);
262+
latch.wr_lock();
267263
trx_sys.clone_oldest_view(&view);
268-
rw_lock_x_unlock(&latch);
264+
latch.wr_unlock();
269265
}
270266
};
271267

storage/innobase/row/row0umod.cc

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ static bool row_undo_mod_must_purge(undo_node_t* node, mtr_t* mtr)
214214
ut_ad(btr_cur->index->is_primary());
215215
DEBUG_SYNC_C("rollback_purge_clust");
216216

217-
mtr->s_lock(&purge_sys.latch, __FILE__, __LINE__);
218-
219217
if (!purge_sys.changes_visible(node->new_trx_id, node->table->name)) {
220218
return false;
221219
}
@@ -239,6 +237,7 @@ row_undo_mod_clust(
239237
{
240238
btr_pcur_t* pcur;
241239
mtr_t mtr;
240+
bool have_latch = false;
242241
dberr_t err;
243242
dict_index_t* index;
244243
bool online;
@@ -365,42 +364,53 @@ row_undo_mod_clust(
365364
goto mtr_commit_exit;
366365
}
367366

367+
ut_ad(rec_get_deleted_flag(btr_pcur_get_rec(pcur),
368+
dict_table_is_comp(node->table)));
369+
368370
if (index->table->is_temporary()) {
369371
mtr.set_log_mode(MTR_LOG_NO_REDO);
372+
if (btr_cur_optimistic_delete(&pcur->btr_cur, 0,
373+
&mtr)) {
374+
goto mtr_commit_exit;
375+
}
376+
btr_pcur_commit_specify_mtr(pcur, &mtr);
370377
} else {
378+
index->set_modified(mtr);
379+
have_latch = true;
380+
purge_sys.latch.rd_lock();
371381
if (!row_undo_mod_must_purge(node, &mtr)) {
372382
goto mtr_commit_exit;
373383
}
374-
index->set_modified(mtr);
375-
}
376-
377-
ut_ad(rec_get_deleted_flag(btr_pcur_get_rec(pcur),
378-
dict_table_is_comp(node->table)));
379-
if (btr_cur_optimistic_delete(&pcur->btr_cur, 0, &mtr)) {
380-
goto mtr_commit_exit;
384+
if (btr_cur_optimistic_delete(&pcur->btr_cur, 0,
385+
&mtr)) {
386+
goto mtr_commit_exit;
387+
}
388+
purge_sys.latch.rd_unlock();
389+
btr_pcur_commit_specify_mtr(pcur, &mtr);
390+
have_latch = false;
381391
}
382392

383-
btr_pcur_commit_specify_mtr(pcur, &mtr);
384-
385393
mtr.start();
386394
if (!btr_pcur_restore_position(
387395
BTR_MODIFY_TREE | BTR_LATCH_FOR_DELETE,
388396
pcur, &mtr)) {
389397
goto mtr_commit_exit;
390398
}
391399

400+
ut_ad(rec_get_deleted_flag(btr_pcur_get_rec(pcur),
401+
dict_table_is_comp(node->table)));
402+
392403
if (index->table->is_temporary()) {
393404
mtr.set_log_mode(MTR_LOG_NO_REDO);
394405
} else {
406+
have_latch = true;
407+
purge_sys.latch.rd_lock();
395408
if (!row_undo_mod_must_purge(node, &mtr)) {
396409
goto mtr_commit_exit;
397410
}
398411
index->set_modified(mtr);
399412
}
400413

401-
ut_ad(rec_get_deleted_flag(btr_pcur_get_rec(pcur),
402-
dict_table_is_comp(node->table)));
403-
404414
/* This operation is analogous to purge, we can free
405415
also inherited externally stored fields. We can also
406416
assume that the record was complete (including BLOBs),
@@ -409,8 +419,7 @@ row_undo_mod_clust(
409419
rollback=false, just like purge does. */
410420
btr_cur_pessimistic_delete(&err, FALSE, &pcur->btr_cur, 0,
411421
false, &mtr);
412-
ut_ad(err == DB_SUCCESS
413-
|| err == DB_OUT_OF_FILE_SPACE);
422+
ut_ad(err == DB_SUCCESS || err == DB_OUT_OF_FILE_SPACE);
414423
} else if (!index->table->is_temporary() && node->new_trx_id) {
415424
/* We rolled back a record so that it still exists.
416425
We must reset the DB_TRX_ID if the history is no
@@ -421,7 +430,8 @@ row_undo_mod_clust(
421430
goto mtr_commit_exit;
422431
}
423432
rec_t* rec = btr_pcur_get_rec(pcur);
424-
mtr.s_lock(&purge_sys.latch, __FILE__, __LINE__);
433+
have_latch = true;
434+
purge_sys.latch.rd_lock();
425435
if (!purge_sys.changes_visible(node->new_trx_id,
426436
node->table->name)) {
427437
goto mtr_commit_exit;
@@ -493,6 +503,10 @@ row_undo_mod_clust(
493503
}
494504

495505
mtr_commit_exit:
506+
if (have_latch) {
507+
purge_sys.latch.rd_unlock();
508+
}
509+
496510
btr_pcur_commit_specify_mtr(pcur, &mtr);
497511

498512
func_exit:

storage/innobase/row/row0vers.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ row_vers_build_for_consistent_read(
11241124
ut_ad(index->is_primary());
11251125
ut_ad(mtr->memo_contains_page_flagged(rec, MTR_MEMO_PAGE_X_FIX
11261126
| MTR_MEMO_PAGE_S_FIX));
1127-
ut_ad(!rw_lock_own(&(purge_sys.latch), RW_LOCK_S));
11281127

11291128
ut_ad(rec_offs_validate(rec, index, *offsets));
11301129

@@ -1237,7 +1236,6 @@ row_vers_build_for_semi_consistent_read(
12371236
ut_ad(index->is_primary());
12381237
ut_ad(mtr->memo_contains_page_flagged(rec, MTR_MEMO_PAGE_X_FIX
12391238
| MTR_MEMO_PAGE_S_FIX));
1240-
ut_ad(!rw_lock_own(&(purge_sys.latch), RW_LOCK_S));
12411239

12421240
ut_ad(rec_offs_validate(rec, index, *offsets));
12431241

storage/innobase/srv/srv0srv.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,21 +1492,21 @@ bool purge_sys_t::running() const
14921492
/** Stop purge during FLUSH TABLES FOR EXPORT */
14931493
void purge_sys_t::stop()
14941494
{
1495-
rw_lock_x_lock(&latch);
1495+
latch.wr_lock();
14961496

14971497
if (!enabled())
14981498
{
14991499
/* Shutdown must have been initiated during FLUSH TABLES FOR EXPORT. */
15001500
ut_ad(!srv_undo_sources);
1501-
rw_lock_x_unlock(&latch);
1501+
latch.wr_unlock();
15021502
return;
15031503
}
15041504

15051505
ut_ad(srv_n_purge_threads > 0);
15061506

15071507
const auto paused= m_paused++;
15081508

1509-
rw_lock_x_unlock(&latch);
1509+
latch.wr_unlock();
15101510

15111511
if (!paused)
15121512
{
@@ -1529,7 +1529,7 @@ void purge_sys_t::resume()
15291529
ut_ad(srv_force_recovery < SRV_FORCE_NO_BACKGROUND);
15301530
ut_ad(!sync_check_iterate(sync_check()));
15311531
purge_coordinator_task.enable();
1532-
rw_lock_x_lock(&latch);
1532+
latch.wr_lock();
15331533
int32_t paused= m_paused--;
15341534
ut_a(paused);
15351535

@@ -1540,7 +1540,7 @@ void purge_sys_t::resume()
15401540
srv_wake_purge_thread_if_not_active();
15411541
MONITOR_ATOMIC_INC(MONITOR_PURGE_RESUME_COUNT);
15421542
}
1543-
rw_lock_x_unlock(&latch);
1543+
latch.wr_unlock();
15441544
}
15451545

15461546
/*******************************************************************//**

storage/innobase/sync/sync0debug.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ LatchDebug::LatchDebug()
483483
LEVEL_MAP_INSERT(SYNC_RSEG_HEADER_NEW);
484484
LEVEL_MAP_INSERT(SYNC_NOREDO_RSEG);
485485
LEVEL_MAP_INSERT(SYNC_REDO_RSEG);
486-
LEVEL_MAP_INSERT(SYNC_PURGE_LATCH);
487486
LEVEL_MAP_INSERT(SYNC_TREE_NODE);
488487
LEVEL_MAP_INSERT(SYNC_TREE_NODE_FROM_HASH);
489488
LEVEL_MAP_INSERT(SYNC_TREE_NODE_NEW);
@@ -738,7 +737,6 @@ LatchDebug::check_order(
738737
case SYNC_IBUF_BITMAP_MUTEX:
739738
case SYNC_REDO_RSEG:
740739
case SYNC_NOREDO_RSEG:
741-
case SYNC_PURGE_LATCH:
742740
case SYNC_PURGE_QUEUE:
743741
case SYNC_DICT_OPERATION:
744742
case SYNC_DICT_HEADER:
@@ -1318,8 +1316,6 @@ sync_latch_meta_init()
13181316
LATCH_ADD_RWLOCK(FTS_CACHE_INIT, SYNC_FTS_CACHE_INIT,
13191317
fts_cache_init_rw_lock_key);
13201318

1321-
LATCH_ADD_RWLOCK(TRX_PURGE, SYNC_PURGE_LATCH, trx_purge_latch_key);
1322-
13231319
LATCH_ADD_RWLOCK(IBUF_INDEX_TREE, SYNC_IBUF_INDEX_TREE,
13241320
index_tree_rw_lock_key);
13251321

storage/innobase/trx/trx0purge.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Created 3/26/1996 Heikki Tuuri
3636
#include "srv0mon.h"
3737
#include "srv0srv.h"
3838
#include "srv0start.h"
39-
#include "sync0sync.h"
4039
#include "trx0rec.h"
4140
#include "trx0roll.h"
4241
#include "trx0rseg.h"
@@ -45,6 +44,10 @@ Created 3/26/1996 Heikki Tuuri
4544

4645
#include <unordered_map>
4746

47+
#ifdef UNIV_PFS_RWLOCK
48+
extern mysql_pfs_key_t trx_purge_latch_key;
49+
#endif /* UNIV_PFS_RWLOCK */
50+
4851
/** Maximum allowable purge history length. <=0 means 'infinite'. */
4952
ulong srv_max_purge_lag = 0;
5053

@@ -172,7 +175,7 @@ void purge_sys_t::create()
172175
offset= 0;
173176
hdr_page_no= 0;
174177
hdr_offset= 0;
175-
rw_lock_create(trx_purge_latch_key, &latch, SYNC_PURGE_LATCH);
178+
latch.init(trx_purge_latch_key);
176179
mutex_create(LATCH_ID_PURGE_SYS_PQ, &pq_mutex);
177180
truncate.current= NULL;
178181
truncate.last= NULL;
@@ -193,7 +196,7 @@ void purge_sys_t::close()
193196
ut_ad(trx->state == TRX_STATE_ACTIVE);
194197
trx->state= TRX_STATE_NOT_STARTED;
195198
trx->free();
196-
rw_lock_free(&latch);
199+
latch.destroy();
197200
mutex_free(&pq_mutex);
198201
mem_heap_free(heap);
199202
heap= nullptr;

storage/innobase/trx/trx0rec.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,14 +2201,14 @@ trx_undo_get_undo_rec(
22012201
const table_name_t& name,
22022202
trx_undo_rec_t** undo_rec)
22032203
{
2204-
rw_lock_s_lock(&purge_sys.latch);
2204+
purge_sys.latch.rd_lock();
22052205

22062206
bool missing_history = purge_sys.changes_visible(trx_id, name);
22072207
if (!missing_history) {
22082208
*undo_rec = trx_undo_get_undo_rec_low(roll_ptr, heap);
22092209
}
22102210

2211-
rw_lock_s_unlock(&purge_sys.latch);
2211+
purge_sys.latch.rd_unlock();
22122212

22132213
return(missing_history);
22142214
}
@@ -2271,7 +2271,6 @@ trx_undo_prev_version_build(
22712271
byte* buf;
22722272

22732273
ut_ad(!index->table->is_temporary());
2274-
ut_ad(!rw_lock_own(&purge_sys.latch, RW_LOCK_S));
22752274
ut_ad(index_mtr->memo_contains_page_flagged(index_rec,
22762275
MTR_MEMO_PAGE_S_FIX
22772276
| MTR_MEMO_PAGE_X_FIX));
@@ -2365,14 +2364,12 @@ trx_undo_prev_version_build(
23652364

23662365
if ((update->info_bits & REC_INFO_DELETED_FLAG)
23672366
&& row_upd_changes_disowned_external(update)) {
2368-
bool missing_extern;
2367+
purge_sys.latch.rd_lock();
23692368

2370-
rw_lock_s_lock(&purge_sys.latch);
2371-
2372-
missing_extern = purge_sys.changes_visible(
2369+
bool missing_extern = purge_sys.changes_visible(
23732370
trx_id, index->table->name);
23742371

2375-
rw_lock_s_unlock(&purge_sys.latch);
2372+
purge_sys.latch.rd_unlock();
23762373

23772374
if (missing_extern) {
23782375
/* treat as a fresh insert, not to

0 commit comments

Comments
 (0)