Skip to content

Commit

Permalink
move MEM_ROOT::read_only into flags
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Nov 25, 2023
1 parent d1ca8fb commit 69d78cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
6 changes: 2 additions & 4 deletions include/my_alloc.h
Expand Up @@ -23,6 +23,8 @@
#define ALLOC_MAX_BLOCK_TO_DROP 4096
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10

#define ROOT_FLAG_READ_ONLY 4

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -52,10 +54,6 @@ typedef struct st_mem_root
unsigned short first_block_usage;
unsigned short flags;

#ifdef PROTECT_STATEMENT_MEMROOT
int read_only;
#endif

void (*error_handler)(void);
const char *name;
} MEM_ROOT;
Expand Down
9 changes: 2 additions & 7 deletions mysys/my_alloc.c
Expand Up @@ -24,6 +24,7 @@
#define EXTRA_DEBUG

#define ROOT_FLAG_THREAD_SPECIFIC 1
#define ROOT_FLAG_READ_ONLY 4

/* data packed in MEM_ROOT -> min_malloc */

Expand Down Expand Up @@ -74,9 +75,6 @@ void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size,
mem_root->first_block_usage= 0;
mem_root->total_alloc= 0;
mem_root->name= name;
#ifdef PROTECT_STATEMENT_MEMROOT
mem_root->read_only= 0;
#endif

#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
Expand Down Expand Up @@ -218,10 +216,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_ENTER("alloc_root");
DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name));
DBUG_ASSERT(alloc_root_inited(mem_root));

#ifdef PROTECT_STATEMENT_MEMROOT
DBUG_ASSERT(mem_root->read_only == 0);
#endif
DBUG_ASSERT((mem_root->flags & ROOT_FLAG_READ_ONLY) == 0);

DBUG_EXECUTE_IF("simulate_out_of_memory",
{
Expand Down
6 changes: 3 additions & 3 deletions sql/sp_head.cc
Expand Up @@ -1477,7 +1477,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
{
// Don't count a call ended with an error as normal run
executed_counter= 0;
main_mem_root.read_only= 0;
main_mem_root.flags &= ~ROOT_FLAG_READ_ONLY;
reset_instrs_executed_counter();
}
#endif
Expand Down Expand Up @@ -1597,10 +1597,10 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
#ifdef PROTECT_STATEMENT_MEMROOT
if (!err_status)
{
if (!main_mem_root.read_only &&
if (!(main_mem_root.flags & ROOT_FLAG_READ_ONLY) &&
has_all_instrs_executed())
{
main_mem_root.read_only= 1;
main_mem_root.flags |= ROOT_FLAG_READ_ONLY;
}
++executed_counter;
DBUG_PRINT("info", ("execute counter: %lu", executed_counter));
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_prepare.cc
Expand Up @@ -176,7 +176,7 @@ class Prepared_statement: public Statement
/*
The following data member is wholly for debugging purpose.
It can be used for possible crash analysis to determine how many times
the stored routine was executed before the mem_root marked read_only
the stored routine was executed before the mem_root marked ROOT_FLAG_READ_ONLY
was requested for a memory chunk. Additionally, a value of this data
member is output to the log with DBUG_PRINT.
*/
Expand Down Expand Up @@ -4489,7 +4489,7 @@ Prepared_statement::execute_loop(String *expanded_query,
#ifdef PROTECT_STATEMENT_MEMROOT
// There was reprepare so the counter of runs should be reset
executed_counter= 0;
mem_root->read_only= 0;
mem_root->flags &= ~ROOT_FLAG_READ_ONLY;
#endif
goto reexecute;
}
Expand All @@ -4498,7 +4498,7 @@ Prepared_statement::execute_loop(String *expanded_query,
#ifdef PROTECT_STATEMENT_MEMROOT
if (!error)
{
mem_root->read_only= 1;
mem_root->flags |= ROOT_FLAG_READ_ONLY;
++executed_counter;

DBUG_PRINT("info", ("execute counter: %lu", executed_counter));
Expand All @@ -4507,7 +4507,7 @@ Prepared_statement::execute_loop(String *expanded_query,
{
// Error on call shouldn't be counted as a normal run
executed_counter= 0;
mem_root->read_only= 0;
mem_root->flags &= ~ROOT_FLAG_READ_ONLY;
}
#endif

Expand Down

0 comments on commit 69d78cd

Please sign in to comment.