Skip to content

Commit cdee1ad

Browse files
author
Tor Didriksen
committed
Bug #33768149 Clean up usage of init_sql_alloc
Remove the pre_alloc_size argument to init_sql_alloc, it has been ignored since the patch for Bug #26940369: REWRITE THE MEM_ROOT Remove calls to init_sql_alloc() for MEM_ROOT objects on the heap (part of other objects) or on the stack. Use CTOR to initialize instead. MEM_ROOT now has a DTOR which does Clear(), so most of the calls to this function can be removed. Set MEM_ROOT.m_error_handler if MYSQL_SERVER is defined. Change-Id: Iaeaaff7f2e9743a353c802829cd62ee9c73c7710
1 parent 2d27a95 commit cdee1ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+144
-192
lines changed

include/my_alloc.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -44,6 +44,10 @@
4444
#include "my_pointer_arithmetic.h"
4545
#include "mysql/psi/psi_memory.h"
4646

47+
#if defined(MYSQL_SERVER)
48+
extern "C" void sql_alloc_error_handler();
49+
#endif
50+
4751
/**
4852
* The MEM_ROOT is a simple arena, where allocations are carved out of
4953
* larger blocks. Using an arena over plain malloc gives you two main
@@ -88,7 +92,11 @@ struct MEM_ROOT {
8892
MEM_ROOT(PSI_memory_key key, size_t block_size)
8993
: m_block_size(block_size),
9094
m_orig_block_size(block_size),
91-
m_psi_key(key) {}
95+
m_psi_key(key) {
96+
#if defined(MYSQL_SERVER)
97+
m_error_handler = sql_alloc_error_handler;
98+
#endif
99+
}
92100

93101
// MEM_ROOT is movable but not copyable.
94102
MEM_ROOT(const MEM_ROOT &) = delete;

sql/auth/acl_table_user.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -68,7 +68,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
6868
#include "sql/sql_update.h" /* compare_records */
6969
#include "sql/system_variables.h" /* System_variables */
7070
#include "sql/table.h" /* TABLE, TABLE_SHARE, ... */
71-
#include "sql/thr_malloc.h" /* init_sql_alloc */
7271
#include "sql/tztime.h" /* Time_zone */
7372
#include "sql_string.h" /* String */
7473
#include "template_utils.h" /* down_cast */
@@ -1342,17 +1341,14 @@ std::string Acl_table_user_writer::get_current_credentials() {
13421341
*/
13431342
Acl_table_user_reader::Acl_table_user_reader(THD *thd, TABLE *table)
13441343
: Acl_table(thd, table, acl_table::Acl_table_operation::OP_READ),
1345-
m_restrictions(new Restrictions) {
1346-
init_sql_alloc(PSI_NOT_INSTRUMENTED, &m_mem_root, ACL_ALLOC_BLOCK_SIZE, 0);
1347-
}
1344+
m_restrictions(new Restrictions) {}
13481345

13491346
/**
13501347
Free resources before we destroy.
13511348
*/
13521349
Acl_table_user_reader::~Acl_table_user_reader() {
13531350
if (m_table_schema) delete m_table_schema;
13541351
if (m_restrictions) delete m_restrictions;
1355-
m_mem_root.Clear();
13561352
}
13571353

13581354
/**

sql/auth/acl_table_user.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -318,7 +318,7 @@ class Acl_table_user_reader : public Acl_table {
318318
private:
319319
User_table_schema *m_table_schema = nullptr;
320320
unique_ptr_destroy_only<RowIterator> m_iterator;
321-
MEM_ROOT m_mem_root;
321+
MEM_ROOT m_mem_root{PSI_NOT_INSTRUMENTED, ACL_ALLOC_BLOCK_SIZE};
322322
Restrictions *m_restrictions = nullptr;
323323
Json_object *m_user_application_user_metadata_json = nullptr;
324324
};

sql/auth/sql_auth_cache.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -183,8 +183,7 @@ static void set_hostname(ACL_HOST_AND_IP *host, const char *host_arg,
183183
Allocates the memory in the the global_acl_memory MEM_ROOT.
184184
*/
185185
void init_acl_memory() {
186-
init_sql_alloc(key_memory_acl_mem, &global_acl_memory, ACL_ALLOC_BLOCK_SIZE,
187-
0);
186+
init_sql_alloc(key_memory_acl_mem, &global_acl_memory, ACL_ALLOC_BLOCK_SIZE);
188187
}
189188

190189
/**
@@ -2691,7 +2690,7 @@ bool grant_reload(THD *thd, bool mdl_locked) {
26912690
undo opertion possible in case of failure.
26922691
*/
26932692
old_mem = move(memex);
2694-
init_sql_alloc(key_memory_acl_memex, &memex, ACL_ALLOC_BLOCK_SIZE, 0);
2693+
init_sql_alloc(key_memory_acl_memex, &memex, ACL_ALLOC_BLOCK_SIZE);
26952694
/*
26962695
tables[2].table i.e. procs_priv can be null if we are working with
26972696
pre 4.1 privilage tables

sql/auth/sql_user.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
22
This program is free software; you can redistribute it and/or modify
33
it under the terms of the GNU General Public License, version 2.0,
44
as published by the Free Software Foundation.
@@ -1808,8 +1808,7 @@ bool set_and_validate_user_attributes(
18081808
*/
18091809
acl_user->m_mfa->alter_mfa(mfa);
18101810
} else {
1811-
MEM_ROOT mr;
1812-
init_sql_alloc(PSI_NOT_INSTRUMENTED, &mr, 256, 0);
1811+
MEM_ROOT mr(PSI_NOT_INSTRUMENTED, 256);
18131812
I_multi_factor_auth *tmp = new (&mr) Multi_factor_auth_list(&mr);
18141813
if (tmp->is_alter_allowed(thd, Str)) {
18151814
mr.Clear();

sql/event_data_objects.cc

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2005, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2005, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -222,8 +222,6 @@ Event_queue_element_for_exec::~Event_queue_element_for_exec() {
222222
Event_basic::Event_basic()
223223
: m_schema_name(NULL_CSTR), m_event_name(NULL_CSTR), m_time_zone(nullptr) {
224224
DBUG_TRACE;
225-
/* init memory root */
226-
init_sql_alloc(key_memory_event_basic_root, &mem_root, 256, 512);
227225
}
228226

229227
/*
@@ -233,10 +231,7 @@ Event_basic::Event_basic()
233231
Event_basic::Event_basic()
234232
*/
235233

236-
Event_basic::~Event_basic() {
237-
DBUG_TRACE;
238-
mem_root.Clear();
239-
}
234+
Event_basic::~Event_basic() { DBUG_TRACE; }
240235

241236
/*
242237
Constructor

sql/event_data_objects.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _EVENT_DATA_OBJECTS_H_
22
#define _EVENT_DATA_OBJECTS_H_
3-
/* Copyright (c) 2004, 2021, Oracle and/or its affiliates.
3+
/* Copyright (c) 2004, 2022, Oracle and/or its affiliates.
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License, version 2.0,
@@ -37,6 +37,7 @@
3737
#include "my_psi_config.h"
3838
#include "my_time.h" // interval_type
3939
#include "mysql/components/services/bits/psi_statement_bits.h"
40+
#include "sql/psi_memory_key.h"
4041

4142
class String;
4243
class THD;
@@ -76,7 +77,7 @@ class Event_queue_element_for_exec {
7677

7778
class Event_basic {
7879
protected:
79-
MEM_ROOT mem_root;
80+
MEM_ROOT mem_root{key_memory_event_basic_root, 256};
8081

8182
public:
8283
LEX_CSTRING m_schema_name;

sql/events.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _EVENT_H_
22
#define _EVENT_H_
3-
/* Copyright (c) 2004, 2021, Oracle and/or its affiliates.
3+
/* Copyright (c) 2004, 2022, Oracle and/or its affiliates.
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License, version 2.0,
@@ -43,7 +43,7 @@
4343
#include "mysql/components/services/bits/psi_mutex_bits.h"
4444
#include "mysql/components/services/bits/psi_stage_bits.h"
4545
#include "mysql/components/services/bits/psi_thread_bits.h"
46-
#include "mysql/psi/psi_memory.h" // PSI_memory_key
46+
#include "sql/psi_memory_key.h"
4747

4848
class Event_db_repository;
4949
class Event_parse_data;
@@ -64,8 +64,6 @@ extern PSI_cond_key key_event_scheduler_COND_state;
6464
extern PSI_thread_key key_thread_event_scheduler, key_thread_event_worker;
6565
#endif /* HAVE_PSI_INTERFACE */
6666

67-
extern PSI_memory_key key_memory_event_basic_root;
68-
6967
/* Always defined, for SHOW PROCESSLIST. */
7068
extern PSI_stage_info stage_waiting_on_empty_queue;
7169
extern PSI_stage_info stage_waiting_for_next_activation;

sql/locked_tables_list.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -32,10 +32,7 @@ Locked_tables_list::Locked_tables_list()
3232
: m_locked_tables(nullptr),
3333
m_locked_tables_last(&m_locked_tables),
3434
m_reopen_array(nullptr),
35-
m_locked_tables_count(0) {
36-
init_sql_alloc(key_memory_locked_table_list, &m_locked_tables_root,
37-
MEM_ROOT_BLOCK_SIZE, 0);
38-
}
35+
m_locked_tables_count(0) {}
3936

4037
/**
4138
Enter LTM_LOCK_TABLES mode.

sql/locked_tables_list.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2008, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -26,6 +26,8 @@
2626
#include <sys/types.h>
2727
#include <vector>
2828
#include "my_alloc.h"
29+
#include "sql/psi_memory_key.h"
30+
#include "sql/sql_const.h"
2931

3032
struct MYSQL_LOCK;
3133
class MDL_context;
@@ -85,7 +87,8 @@ const char *get_locked_tables_mode_name(
8587

8688
class Locked_tables_list {
8789
private:
88-
MEM_ROOT m_locked_tables_root;
90+
MEM_ROOT m_locked_tables_root{key_memory_locked_table_list,
91+
MEM_ROOT_BLOCK_SIZE};
8992
TABLE_LIST *m_locked_tables;
9093
TABLE_LIST **m_locked_tables_last;
9194
/** An auxiliary array used only in reopen_tables(). */

sql/mysql_tzinfo_to_sql.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2004, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2004, 2022, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -326,6 +326,8 @@ static bool scan_tz_dir(char *name_end) {
326326
return false;
327327
}
328328

329+
extern "C" void sql_alloc_error_handler() {}
330+
329331
int main(int argc, char **argv) {
330332
MY_INIT(argv[0]);
331333

sql/psi_memory_key.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extern PSI_memory_key key_memory_DD_default_values;
6464
extern PSI_memory_key key_memory_DD_import;
6565
extern PSI_memory_key key_memory_DD_objects;
6666
extern PSI_memory_key key_memory_DD_String_type;
67+
extern PSI_memory_key key_memory_event_basic_root;
6768
extern PSI_memory_key key_memory_Event_queue_element_for_exec_names;
6869
extern PSI_memory_key key_memory_Event_scheduler_scheduler_param;
6970
extern PSI_memory_key key_memory_File_query_log_name;

sql/rpl_handler.cc

-2
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ Delegate::Delegate(
9797
#else
9898
if (mysql_rwlock_init(0, &lock)) return;
9999
#endif
100-
init_sql_alloc(key_memory_delegate, &memroot, 1024, 0);
101100
inited = true;
102101
}
103102

104103
Delegate::~Delegate() {
105104
inited = false;
106105
mysql_rwlock_destroy(&lock);
107-
memroot.Clear();
108106
}
109107

110108
int Delegate::add_observer(void *observer, st_plugin_int *plugin) {

sql/rpl_handler.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
#include "mysql/components/services/bits/psi_rwlock_bits.h"
3737
#include "mysql/psi/mysql_rwlock.h"
3838
#include "sql/locks/shared_spin_lock.h" // Shared_spin_lock
39-
#include "sql/sql_list.h" // List
40-
#include "sql/sql_plugin.h" // my_plugin_(un)lock
41-
#include "sql/sql_plugin_ref.h" // plugin_ref
39+
#include "sql/psi_memory_key.h"
40+
#include "sql/sql_list.h" // List
41+
#include "sql/sql_plugin.h" // my_plugin_(un)lock
42+
#include "sql/sql_plugin_ref.h" // plugin_ref
4243

4344
class Master_info;
4445
class String;
@@ -219,7 +220,7 @@ class Delegate {
219220
*/
220221
lock::Shared_spin_lock m_spin_lock;
221222
/** Memory pool to be used to allocate the observers list */
222-
MEM_ROOT memroot;
223+
MEM_ROOT memroot{key_memory_delegate, 1024};
223224
/** Flag statign whether or not this instance was initialized */
224225
bool inited;
225226
/**

sql/sp.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -2237,10 +2237,7 @@ sp_head *sp_load_for_information_schema(THD *thd, LEX_CSTRING db_name,
22372237
sp_head *sp_start_parsing(THD *thd, enum_sp_type sp_type, sp_name *sp_name) {
22382238
// The order is important:
22392239
// 1. new sp_head()
2240-
MEM_ROOT own_root;
2241-
2242-
init_sql_alloc(key_memory_sp_head_main_root, &own_root, MEM_ROOT_BLOCK_SIZE,
2243-
0);
2240+
MEM_ROOT own_root(key_memory_sp_head_main_root, MEM_ROOT_BLOCK_SIZE);
22442241

22452242
void *rawmem = own_root.Alloc(sizeof(sp_head));
22462243
if (!rawmem) return nullptr;

0 commit comments

Comments
 (0)