summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-05-06 10:45:17 +0300
committerAleksey Midenkov <midenok@gmail.com>2022-05-06 10:45:17 +0300
commit93e64d1f58420d572ad6071e7af64ad42314c504 (patch)
treeff7962eea68e81ad6e0b7adec379a90193b8f421
parentc8bcb6e8092f2dd29fd223d43277d93c20e61c4e (diff)
downloadmariadb-git-93e64d1f58420d572ad6071e7af64ad42314c504.tar.gz
cleanup: log_current_statement and OPTION_KEEP_LOG
rename OPTION_KEEP_LOG -> OPTION_BINLOG_THIS_TRX. Meaning: transaction cache will be written to binlog even on rollback. convert log_current_statement to OPTION_BINLOG_THIS_STMT. Meaning: the statement will be written to binlog (or trx binlog cache) even if it normally wouldn't be. setting OPTION_BINLOG_THIS_STMT must always set OPTION_BINLOG_THIS_TRX, otherwise the statement won't be logged if the transaction is rolled back. Use OPTION_BINLOG_THIS to set both.
-rw-r--r--sql/log.cc8
-rw-r--r--sql/slave.cc10
-rw-r--r--sql/sql_class.h6
-rw-r--r--sql/sql_insert.cc4
-rw-r--r--sql/sql_parse.cc8
-rw-r--r--sql/sql_priv.h5
-rw-r--r--sql/sql_table.cc20
-rw-r--r--sql/sys_vars.cc2
-rw-r--r--sql/transaction.cc12
-rw-r--r--sql/xa.cc8
10 files changed, 43 insertions, 40 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 6317538cb44..b6fde40abeb 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -2157,7 +2157,7 @@ inline bool is_prepared_xa(THD *thd)
/*
We flush the cache wrapped in a beging/rollback if:
. aborting a single or multi-statement transaction and;
- . the OPTION_KEEP_LOG is active or;
+ . the OPTION_BINLOG_THIS_TRX is active or;
. the format is STMT and a non-trans table was updated or;
. the format is MIXED and a temporary non-trans table was
updated or;
@@ -2168,7 +2168,7 @@ static bool trans_cannot_safely_rollback(THD *thd, bool all)
{
DBUG_ASSERT(ending_trans(thd, all));
- return ((thd->variables.option_bits & OPTION_KEEP_LOG) ||
+ return ((thd->variables.option_bits & OPTION_BINLOG_THIS_TRX) ||
(trans_has_updated_non_trans_table(thd) &&
thd->wsrep_binlog_format() == BINLOG_FORMAT_STMT) ||
(thd->transaction->all.has_modified_non_trans_temp_table() &&
@@ -2567,10 +2567,10 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
*/
if (unlikely(thd->wsrep_trx().is_streaming() ||
(trans_has_updated_non_trans_table(thd)) ||
- (thd->variables.option_bits & OPTION_KEEP_LOG)))
+ (thd->variables.option_bits & OPTION_BINLOG_THIS_TRX)))
#else
if (unlikely(trans_has_updated_non_trans_table(thd) ||
- (thd->variables.option_bits & OPTION_KEEP_LOG)))
+ (thd->variables.option_bits & OPTION_BINLOG_THIS_TRX)))
#endif /* WITH_WSREP */
{
char buf[1024];
diff --git a/sql/slave.cc b/sql/slave.cc
index 23a35c5805f..f6f243d7f03 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1368,13 +1368,13 @@ static bool sql_slave_killed(rpl_group_info *rgi)
if (rli->sql_driver_thd->killed || rli->abort_slave)
{
/*
- The transaction should always be binlogged if OPTION_KEEP_LOG is
+ The transaction should always be binlogged if OPTION_BINLOG_THIS_TRX is
set (it implies that something can not be rolled back). And such
case should be regarded similarly as modifing a
non-transactional table because retrying of the transaction will
lead to an error or inconsistency as well.
- Example: OPTION_KEEP_LOG is set if a temporary table is created
+ Example: OPTION_BINLOG_THIS_TRX is set if a temporary table is created
or dropped.
Note that transaction.all.modified_non_trans_table may be 1
@@ -1384,7 +1384,7 @@ static bool sql_slave_killed(rpl_group_info *rgi)
*/
if ((thd->transaction->all.modified_non_trans_table ||
- (thd->variables.option_bits & OPTION_KEEP_LOG)) &&
+ (thd->variables.option_bits & OPTION_BINLOG_THIS_TRX)) &&
rli->is_in_group())
{
char msg_stopped[]=
@@ -1396,10 +1396,10 @@ static bool sql_slave_killed(rpl_group_info *rgi)
"documentation for details).";
DBUG_PRINT("info", ("modified_non_trans_table: %d OPTION_BEGIN: %d "
- "OPTION_KEEP_LOG: %d is_in_group: %d",
+ "OPTION_BINLOG_THIS_TRX: %d is_in_group: %d",
thd->transaction->all.modified_non_trans_table,
MY_TEST(thd->variables.option_bits & OPTION_BEGIN),
- MY_TEST(thd->variables.option_bits & OPTION_KEEP_LOG),
+ MY_TEST(thd->variables.option_bits & OPTION_BINLOG_THIS_TRX),
rli->is_in_group()));
if (rli->abort_slave)
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 4ea74b479e7..01ec676e132 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3560,8 +3560,10 @@ public:
/* set during loop of derived table processing */
bool derived_tables_processing;
bool tablespace_op; /* This is TRUE in DISCARD/IMPORT TABLESPACE */
- /* True if we have to log the current statement */
- bool log_current_statement;
+ bool log_current_statement() const
+ {
+ return variables.option_bits & OPTION_BINLOG_THIS_STMT;
+ }
/**
True if a slave error. Causes the slave to stop. Not the same
as the statement execution error (is_error()), since
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index aecd70f1810..87177eac3bc 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -4344,7 +4344,7 @@ void select_insert::abort_result_set()
changed= (info.copied || info.deleted || info.updated);
transactional_table= table->file->has_transactions_and_rollback();
if (thd->transaction->stmt.modified_non_trans_table ||
- thd->log_current_statement)
+ thd->log_current_statement())
{
if (!can_rollback_data())
thd->transaction->all.modified_non_trans_table= TRUE;
@@ -5225,7 +5225,7 @@ void select_create::abort_result_set()
drop_open_table(thd, table, &create_table->db, &create_table->table_name);
table=0; // Safety
- if (thd->log_current_statement)
+ if (thd->log_current_statement())
{
if (mysql_bin_log.is_open())
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 308f2b5451d..f841af1fea6 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4931,7 +4931,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
status_var_increment(thd->status_var.com_drop_tmp_table);
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
- thd->variables.option_bits|= OPTION_KEEP_LOG;
+ thd->variables.option_bits|= OPTION_BINLOG_THIS_TRX;
}
/*
If we are a slave, we should add IF EXISTS if the query executed
@@ -7586,7 +7586,7 @@ void THD::reset_for_next_command(bool do_clear_error)
#endif /* WITH_WSREP */
query_start_sec_part_used= 0;
is_fatal_error= time_zone_used= 0;
- log_current_statement= 0;
+ variables.option_bits&= ~OPTION_BINLOG_THIS_STMT;
/*
Clear the status flag that are expected to be cleared at the
@@ -7595,12 +7595,12 @@ void THD::reset_for_next_command(bool do_clear_error)
server_status&= ~SERVER_STATUS_CLEAR_SET;
/*
If in autocommit mode and not in a transaction, reset
- OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
+ OPTION_STATUS_NO_TRANS_UPDATE | OPTION_BINLOG_THIS_TRX to not get warnings
in ha_rollback_trans() about some tables couldn't be rolled back.
*/
if (!in_multi_stmt_transaction_mode())
{
- variables.option_bits&= ~OPTION_KEEP_LOG;
+ variables.option_bits&= ~OPTION_BINLOG_THIS_TRX;
transaction->all.reset();
}
DBUG_ASSERT(security_ctx== &main_security_ctx);
diff --git a/sql/sql_priv.h b/sql/sql_priv.h
index b5efe53dfa4..decb60187df 100644
--- a/sql/sql_priv.h
+++ b/sql/sql_priv.h
@@ -134,7 +134,7 @@
#define OPTION_BEGIN (1ULL << 20) // THD, intern
#define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern
#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
-#define OPTION_KEEP_LOG (1ULL << 23) // THD, user
+#define OPTION_BINLOG_THIS_TRX (1ULL << 23) // THD
/* The following is used to detect a conflict with DISTINCT */
#define SELECT_ALL (1ULL << 24) // SELECT, user, parser
@@ -175,6 +175,9 @@
*/
#define OPTION_MASTER_SQL_ERROR (1ULL << 35)
+#define OPTION_BINLOG_THIS_STMT (1ULL << 36) // THD
+#define OPTION_BINLOG_THIS (OPTION_BINLOG_THIS_STMT | OPTION_BINLOG_THIS_TRX)
+
#define OPTION_SKIP_REPLICATION (1ULL << 37) // THD, user
#define OPTION_RPL_SKIP_PARALLEL (1ULL << 38)
#define OPTION_NO_QUERY_CACHE (1ULL << 39) // SELECT, user
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 24c4a08ea4b..43fa10fab3c 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -4437,8 +4437,7 @@ int create_table_impl(THD *thd,
*/
if (table_creation_was_logged)
{
- thd->variables.option_bits|= OPTION_KEEP_LOG;
- thd->log_current_statement= 1;
+ thd->variables.option_bits|= OPTION_BINLOG_THIS;
create_info->table_was_deleted= 1;
}
}
@@ -4496,8 +4495,7 @@ int create_table_impl(THD *thd,
We have to log this query, even if it failed later to ensure the
drop is done.
*/
- thd->variables.option_bits|= OPTION_KEEP_LOG;
- thd->log_current_statement= 1;
+ thd->variables.option_bits|= OPTION_BINLOG_THIS;
create_info->table_was_deleted= 1;
lex_string_set(&create_info->org_storage_engine_name,
ha_resolve_storage_engine_name(db_type));
@@ -4520,9 +4518,9 @@ int create_table_impl(THD *thd,
*/
/* Log CREATE IF NOT EXISTS on slave for distributed engines */
- if (thd->slave_thread && (db_type && db_type->flags &
- HTON_IGNORE_UPDATES))
- thd->log_current_statement= 1;
+ if (thd->slave_thread && db_type &&
+ db_type->flags & HTON_IGNORE_UPDATES)
+ thd->variables.option_bits|= OPTION_BINLOG_THIS;
goto warn;
}
else
@@ -4887,7 +4885,7 @@ err:
thd->transaction->stmt.mark_created_temp_table();
/* Write log if no error or if we already deleted a table */
- if (likely(!result) || thd->log_current_statement)
+ if (!result || thd->log_current_statement())
{
if (unlikely(result) && create_info->table_was_deleted &&
pos_in_locked_tables)
@@ -5353,7 +5351,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
&is_trans, C_ORDINARY_CREATE,
table)) > 0);
/* Remember to log if we deleted something */
- do_logging= thd->log_current_statement;
+ do_logging= thd->log_current_statement();
if (res)
goto err;
@@ -12285,7 +12283,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
if (!(res= handle_select(thd, lex, result, 0)))
{
if (create_info.tmp_table())
- thd->variables.option_bits|= OPTION_KEEP_LOG;
+ thd->variables.option_bits|= OPTION_BINLOG_THIS_TRX;
}
delete result;
}
@@ -12345,7 +12343,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
{
/* So that CREATE TEMPORARY TABLE gets to binlog at commit/rollback */
if (create_info.tmp_table())
- thd->variables.option_bits|= OPTION_KEEP_LOG;
+ thd->variables.option_bits|= OPTION_BINLOG_THIS_TRX;
/* in case of create temp tables if @@session_track_state_change is
ON then send session state notification in OK packet */
if (create_info.options & HA_LEX_CREATE_TMP_TABLE)
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 505a05637d6..da308f5b734 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -4441,7 +4441,7 @@ static bool fix_autocommit(sys_var *self, THD *thd, enum_var_type type)
transaction implicitly at the end (@sa stmt_causes_implicitcommit()).
*/
thd->variables.option_bits&=
- ~(OPTION_BEGIN | OPTION_KEEP_LOG | OPTION_NOT_AUTOCOMMIT |
+ ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX | OPTION_NOT_AUTOCOMMIT |
OPTION_GTID_BEGIN);
thd->transaction->all.modified_non_trans_table= false;
thd->transaction->all.m_unsafe_rollback_flags&= ~THD_TRANS::DID_WAIT;
diff --git a/sql/transaction.cc b/sql/transaction.cc
index 958abebfc47..bf8b95353fd 100644
--- a/sql/transaction.cc
+++ b/sql/transaction.cc
@@ -133,7 +133,7 @@ bool trans_begin(THD *thd, uint flags)
#endif /* WITH_WSREP */
}
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
/*
The following set should not be needed as transaction state should
@@ -280,7 +280,7 @@ bool trans_commit(THD *thd)
else
repl_semisync_master.wait_after_commit(thd, FALSE);
#endif
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
thd->transaction->all.reset();
thd->lex->start_transaction_opt= 0;
@@ -329,7 +329,7 @@ bool trans_commit_implicit(THD *thd)
res= MY_TEST(ha_commit_trans(thd, TRUE));
}
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
thd->transaction->all.reset();
/* The transaction should be marked as complete in P_S. */
@@ -374,7 +374,7 @@ bool trans_rollback(THD *thd)
repl_semisync_master.wait_after_rollback(thd, FALSE);
#endif
/* Reset the binlog transaction marker */
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG |
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX |
OPTION_GTID_BEGIN);
thd->transaction->all.reset();
thd->lex->start_transaction_opt= 0;
@@ -424,7 +424,7 @@ bool trans_rollback_implicit(THD *thd)
of new transacton in @@autocommit=1 mode. This is necessary to
preserve backward compatibility.
*/
- thd->variables.option_bits&= ~(OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BINLOG_THIS_TRX);
thd->transaction->all.reset();
/* Rollback should clear transaction_rollback_request flag. */
@@ -669,7 +669,7 @@ bool trans_rollback_to_savepoint(THD *thd, LEX_CSTRING name)
if (ha_rollback_to_savepoint(thd, sv))
res= TRUE;
- else if (((thd->variables.option_bits & OPTION_KEEP_LOG) ||
+ else if (((thd->variables.option_bits & OPTION_BINLOG_THIS_TRX) ||
thd->transaction->all.modified_non_trans_table) &&
!thd->slave_thread)
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
diff --git a/sql/xa.cc b/sql/xa.cc
index af7c7388c57..457aacfeb30 100644
--- a/sql/xa.cc
+++ b/sql/xa.cc
@@ -396,7 +396,7 @@ bool xa_trans_force_rollback(THD *thd)
rc= true;
}
thd->variables.option_bits&=
- ~(OPTION_BEGIN | OPTION_KEEP_LOG | OPTION_GTID_BEGIN);
+ ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX | OPTION_GTID_BEGIN);
thd->transaction->all.reset();
thd->server_status&=
~(SERVER_STATUS_IN_TRANS | SERVER_STATUS_IN_TRANS_READONLY);
@@ -533,7 +533,7 @@ bool trans_xa_prepare(THD *thd)
{
if (!mdl_request.ticket)
ha_rollback_trans(thd, TRUE);
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
thd->transaction->all.reset();
thd->server_status&=
~(SERVER_STATUS_IN_TRANS | SERVER_STATUS_IN_TRANS_READONLY);
@@ -713,7 +713,7 @@ bool trans_xa_commit(THD *thd)
DBUG_RETURN(TRUE);
}
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
thd->transaction->all.reset();
thd->server_status&=
~(SERVER_STATUS_IN_TRANS | SERVER_STATUS_IN_TRANS_READONLY);
@@ -1080,7 +1080,7 @@ bool mysql_xa_recover(THD *thd)
static bool slave_applier_reset_xa_trans(THD *thd)
{
- thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->variables.option_bits&= ~(OPTION_BEGIN | OPTION_BINLOG_THIS_TRX);
thd->server_status&=
~(SERVER_STATUS_IN_TRANS | SERVER_STATUS_IN_TRANS_READONLY);
DBUG_PRINT("info", ("clearing SERVER_STATUS_IN_TRANS"));