Skip to content

Commit db5bb78

Browse files
committed
Allocate trx_sys.mvcc at link time
trx_sys.mvcc was allocated dynamically for no good reason.
1 parent f8882cc commit db5bb78

File tree

10 files changed

+31
-34
lines changed

10 files changed

+31
-34
lines changed

storage/innobase/handler/ha_innodb.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16226,7 +16226,7 @@ ha_innobase::external_lock(
1622616226
} else if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
1622716227
&& MVCC::is_view_active(trx->read_view)) {
1622816228
mutex_enter(&trx_sys.mutex);
16229-
trx_sys.mvcc->view_close(trx->read_view, true);
16229+
trx_sys.mvcc.view_close(trx->read_view, true);
1623016230
mutex_exit(&trx_sys.mutex);
1623116231
}
1623216232
}
@@ -16894,7 +16894,7 @@ ha_innobase::store_lock(
1689416894
/* At low transaction isolation levels we let
1689516895
each consistent read set its own snapshot */
1689616896
mutex_enter(&trx_sys.mutex);
16897-
trx_sys.mvcc->view_close(trx->read_view, true);
16897+
trx_sys.mvcc.view_close(trx->read_view, true);
1689816898
mutex_enter(&trx_sys.mutex);
1689916899
}
1690016900
}

storage/innobase/include/read0read.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ Created 2/16/1997 Heikki Tuuri
3030

3131
#include "read0types.h"
3232

33-
#include <algorithm>
34-
3533
/** The MVCC read view manager */
3634
class MVCC {
3735
public:
3836
/** Constructor
3937
@param size Number of views to pre-allocate */
40-
explicit MVCC(ulint size);
38+
void create(ulint size);
4139

4240
/** Destructor.
4341
Free all the views in the m_free list */
44-
~MVCC();
42+
void close();
4543

4644
/**
4745
Allocate and create a view.
@@ -106,11 +104,6 @@ class MVCC {
106104
@return oldest view if found or NULL */
107105
inline ReadView* get_oldest_view() const;
108106

109-
private:
110-
// Prevent copying
111-
MVCC(const MVCC&);
112-
MVCC& operator=(const MVCC&);
113-
114107
private:
115108
typedef UT_LIST_BASE_NODE_T(ReadView) view_list_t;
116109

storage/innobase/include/trx0sys.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ Created 3/26/1996 Heikki Tuuri
4747

4848
typedef UT_LIST_BASE_NODE_T(trx_t) trx_ut_list_t;
4949

50-
// Forward declaration
51-
class MVCC;
52-
class ReadView;
53-
5450
/** Checks if a page address is the trx sys header page.
5551
@param[in] page_id page id
5652
@return true if trx sys header page */
@@ -825,14 +821,16 @@ struct trx_sys_t {
825821

826822
MY_ALIGNED(CACHE_LINE_SIZE) trx_id_t m_max_trx_id;
827823

824+
bool m_initialised;
828825

829826
public:
830827
MY_ALIGNED(CACHE_LINE_SIZE)
831828
TrxSysMutex mutex; /*!< mutex protecting most fields in
832829
this structure except when noted
833830
otherwise */
834831

835-
MVCC* mvcc; /*!< Multi version concurrency control
832+
MY_ALIGNED(CACHE_LINE_SIZE)
833+
MVCC mvcc; /*!< Multi version concurrency control
836834
manager */
837835
trx_ut_list_t serialisation_list;
838836
/*!< Ordered on trx_t::no of all the
@@ -908,7 +906,8 @@ struct trx_sys_t {
908906
initialisation to create().
909907
*/
910908

911-
trx_sys_t(): rw_trx_ids(ut_allocator<trx_id_t>(mem_key_trx_sys_t_rw_trx_ids))
909+
trx_sys_t(): m_initialised(false),
910+
rw_trx_ids(ut_allocator<trx_id_t>(mem_key_trx_sys_t_rw_trx_ids))
912911
{}
913912

914913

@@ -977,6 +976,9 @@ struct trx_sys_t {
977976
}
978977

979978

979+
bool is_initialised() { return m_initialised; }
980+
981+
980982
/** Create the instance */
981983
void create();
982984

storage/innobase/read/read0read.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ ReadView::~ReadView()
339339

340340
/** Constructor
341341
@param size Number of views to pre-allocate */
342-
MVCC::MVCC(ulint size)
342+
void MVCC::create(ulint size)
343343
{
344344
UT_LIST_INIT(m_free, &ReadView::m_view_list);
345345
UT_LIST_INIT(m_views, &ReadView::m_view_list);
@@ -351,7 +351,7 @@ MVCC::MVCC(ulint size)
351351
}
352352
}
353353

354-
MVCC::~MVCC()
354+
void MVCC::close()
355355
{
356356
for (ReadView* view = UT_LIST_GET_FIRST(m_free);
357357
view != NULL;

storage/innobase/row/row0sel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5888,7 +5888,7 @@ row_search_check_if_query_cache_permitted(
58885888
&& !srv_read_only_mode
58895889
&& !MVCC::is_view_active(trx->read_view)) {
58905890

5891-
trx_sys.mvcc->view_open(trx->read_view, trx);
5891+
trx_sys.mvcc.view_open(trx->read_view, trx);
58925892
}
58935893
}
58945894

storage/innobase/srv/srv0srv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ srv_printf_innodb_monitor(
13671367

13681368
/* This is a dirty read, without holding trx_sys.mutex. */
13691369
fprintf(file, ULINTPF " read views open inside InnoDB\n",
1370-
trx_sys.mvcc->size());
1370+
trx_sys.mvcc.size());
13711371

13721372
n_reserved = fil_space_get_n_reserved_extents(0);
13731373
if (n_reserved > 0) {

storage/innobase/srv/srv0start.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,7 @@ innodb_shutdown()
28352835

28362836
ut_ad(dict_stats_event || !srv_was_started || srv_read_only_mode);
28372837
ut_ad(dict_sys || !srv_was_started);
2838-
ut_ad(trx_sys.mvcc || !srv_was_started);
2838+
ut_ad(trx_sys.is_initialised() || !srv_was_started);
28392839
ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
28402840
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
28412841
ut_ad(lock_sys || !srv_was_started);

storage/innobase/trx/trx0purge.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ trx_purge(
16001600
ut_a(purge_sys->n_submitted == purge_sys->n_completed);
16011601

16021602
rw_lock_x_lock(&purge_sys->latch);
1603-
trx_sys.mvcc->clone_oldest_view(&purge_sys->view);
1603+
trx_sys.mvcc.clone_oldest_view(&purge_sys->view);
16041604
rw_lock_x_unlock(&purge_sys->latch);
16051605

16061606
#ifdef UNIV_DEBUG

storage/innobase/trx/trx0sys.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,21 +445,22 @@ trx_sys_init_at_db_start()
445445
trx_dummy_sess = sess_open();
446446

447447
trx_lists_init_at_db_start();
448-
trx_sys.mvcc->clone_oldest_view(&purge_sys->view);
448+
trx_sys.mvcc.clone_oldest_view(&purge_sys->view);
449449
}
450450

451451
/** Create the instance */
452452
void
453453
trx_sys_t::create()
454454
{
455455
ut_ad(this == &trx_sys);
456-
ut_ad(!mvcc);
456+
ut_ad(!is_initialised());
457+
m_initialised = true;
457458
mutex_create(LATCH_ID_TRX_SYS, &mutex);
458459

459460
UT_LIST_INIT(serialisation_list, &trx_t::no_list);
460461
UT_LIST_INIT(mysql_trx_list, &trx_t::mysql_trx_list);
461462

462-
mvcc = UT_NEW_NOKEY(MVCC(1024));
463+
mvcc.create(1024);
463464

464465
rw_trx_hash.init();
465466
}
@@ -562,11 +563,11 @@ void
562563
trx_sys_t::close()
563564
{
564565
ut_ad(srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS);
565-
if (!mvcc) {
566+
if (!is_initialised()) {
566567
return;
567568
}
568569

569-
if (ulint size = mvcc->size()) {
570+
if (ulint size = mvcc.size()) {
570571
ib::error() << "All read views were not closed before"
571572
" shutdown: " << size << " read views open";
572573
}
@@ -590,13 +591,14 @@ trx_sys_t::close()
590591
}
591592
}
592593

593-
UT_DELETE(mvcc);
594+
mvcc.close();
594595

595596
ut_a(UT_LIST_GET_LEN(mysql_trx_list) == 0);
596597
ut_a(UT_LIST_GET_LEN(serialisation_list) == 0);
597598

598599
/* We used placement new to create this mutex. Call the destructor. */
599600
mutex_free(&mutex);
601+
m_initialised = false;
600602
}
601603

602604

storage/innobase/trx/trx0trx.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ trx_disconnect_from_mysql(
678678
UT_LIST_REMOVE(trx_sys.mysql_trx_list, trx);
679679

680680
if (trx->read_view != NULL) {
681-
trx_sys.mvcc->view_close(trx->read_view, true);
681+
trx_sys.mvcc.view_close(trx->read_view, true);
682682
}
683683

684684
if (prepared) {
@@ -1558,7 +1558,7 @@ trx_erase_lists(
15581558

15591559
mutex_enter(&trx_sys.mutex);
15601560
if (trx->read_view != NULL) {
1561-
trx_sys.mvcc->view_close(trx->read_view, true);
1561+
trx_sys.mvcc.view_close(trx->read_view, true);
15621562
}
15631563
}
15641564

@@ -1615,7 +1615,7 @@ trx_commit_in_memory(
16151615
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
16161616

16171617
if (trx->read_view != NULL) {
1618-
trx_sys.mvcc->view_close(trx->read_view, false);
1618+
trx_sys.mvcc.view_close(trx->read_view, false);
16191619
}
16201620

16211621
MONITOR_INC(MONITOR_TRX_NL_RO_COMMIT);
@@ -1647,7 +1647,7 @@ trx_commit_in_memory(
16471647
if (trx->read_only || trx->rsegs.m_redo.rseg == NULL) {
16481648
MONITOR_INC(MONITOR_TRX_RO_COMMIT);
16491649
if (trx->read_view != NULL) {
1650-
trx_sys.mvcc->view_close(
1650+
trx_sys.mvcc.view_close(
16511651
trx->read_view, false);
16521652
}
16531653
} else {
@@ -1911,7 +1911,7 @@ trx_assign_read_view(
19111911
return(NULL);
19121912

19131913
} else if (!MVCC::is_view_active(trx->read_view)) {
1914-
trx_sys.mvcc->view_open(trx->read_view, trx);
1914+
trx_sys.mvcc.view_open(trx->read_view, trx);
19151915
}
19161916

19171917
return(trx->read_view);

0 commit comments

Comments
 (0)