summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorSachin <sachinsetia1001@gmail.com>2021-01-29 11:59:14 +0000
committerAndrei <andrei.elkin@mariadb.com>2021-11-16 19:38:35 +0200
commitf9f578c7db1924456938a061b3c6287cd09c3963 (patch)
tree820b9bebd6e9ff52f11d0f3d75eed3f3343fcbf1 /sql/sql_class.h
parent5566cbadb03856aba9c236b131f544490cd2bee4 (diff)
downloadmariadb-git-bb-10.8-MENT-662-tmp.tar.gz
MDEV-662 Lag Free Alter On Slavebb-10.8-MENT-662-tmp
This commit implements two phase binloggable ALTER. When a new @@session.binlog_alter_two_phase = YES ALTER query gets logged in two parts, the START ALTER and the COMMIT or ROLLBACK ALTER. START Alter is written in binlog as soon as at its handling necessary locks are acquired for the table. The timing is such that any concurrent DML:s that update the same table are either committed, thus logged into binary log having done work on the old version of the table, or will be queued for execution on its new version. The "COMPLETE" COMMIT or ROLLBACK ALTER are written after the most of ALTER work is done. When its result is positive COMMIT ALTER is written, otherwise when there were errors since START ALTER, ROLLBACK ALTER is written. Replication of two-phase binloggable ALTER is cross-version safe. Specifically the OLD slave merely does not recognized the start alter part, still memorizing its gtid. Two phase logged ALTER is read from binlog by mysqlbinlog to produce BINLOG 'string', where 'string' contains base64 encoded Query_log_event containing either the start part of ALTER, or a completion part. The Query details can be displayed with `-v` flag, similarly to ROW format events. Notice, mysqlbinlog output containing parts of two-phase binloggable ALTER is processable correctly only by binlog_alter_two_phase server. Thanks to all people involved into early discussion of the feature including Kristian Nielsen, those who helped to design, implement and test: Sergei Golubchik, Andrei Elkin, Sujatha Sivakumar, Brandon Nesterenko, Alice Sherepa.
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 0d02f74686f..8e54f938574 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -81,6 +81,7 @@ class Wsrep_applier_service;
class Reprepare_observer;
class Relay_log_info;
struct rpl_group_info;
+struct rpl_parallel_thread;
class Rpl_filter;
class Query_log_event;
class Load_log_event;
@@ -853,6 +854,7 @@ typedef struct system_variables
vers_asof_timestamp_t vers_asof_timestamp;
ulong vers_alter_history;
+ ulong binlog_alter_two_phase;
} SV;
/**
@@ -2996,6 +2998,11 @@ public:
}
bool binlog_table_should_be_logged(const LEX_CSTRING *db);
+ // Accessors and setters of two-phase loggable ALTER binlog properties
+ uint16 get_binlog_flags_for_alter();
+ void set_binlog_flags_for_alter(uint16);
+ uint64 get_binlog_start_alter_seq_no();
+ void set_binlog_start_alter_seq_no(uint64);
#endif /* MYSQL_CLIENT */
public:
@@ -7776,5 +7783,30 @@ extern THD_list server_threads;
void setup_tmp_table_column_bitmaps(TABLE *table, uchar *bitmaps,
uint field_count);
+/*
+ RAII utility class to ease binlogging with temporary setting
+ THD etc context and restoring the original one upon logger execution.
+*/
+class Write_log_with_flags
+{
+ THD* m_thd;
+
+public:
+~Write_log_with_flags()
+ {
+ m_thd->set_binlog_flags_for_alter(0);
+ m_thd->set_binlog_start_alter_seq_no(0);
+ }
+
+ Write_log_with_flags(THD *thd, uint16 flags, uint64 seq_no= 0) : m_thd(thd)
+ {
+ m_thd->set_binlog_flags_for_alter(flags);
+ if (seq_no == 0)
+ seq_no= m_thd->get_binlog_start_alter_seq_no();
+ if (seq_no != 0)
+ m_thd->set_binlog_start_alter_seq_no(seq_no);
+ }
+};
+
#endif /* MYSQL_SERVER */
#endif /* SQL_CLASS_INCLUDED */