Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-30456 ALTER TABLE algorithm clause not replicated #2629

Open
wants to merge 2 commits into
base: 10.4
Choose a base branch
from

Conversation

sjaakola
Copy link
Contributor

  • The Jira issue number for this PR is: MDEV-30456

Description

If user has specified the desired alter algorithm by using session variable alter_algorithm, and not specifying the algorithm in the ALTER SQL statement, then the ALTER will be processed in sending node according the algorithm chosen by the alter_algorithm variable. But in receiving nodes, appliers cannot see this session variable, and will use the default algorithm when executing the ALTER.

The fix in this commit, will check if user has set alter_algorithm variable and has not explicitly specified the algorithm clause in the ALTER statement, and in such case will rewrite the original ALTER statement appended by the algorithm clause. This rewritten ALTER statement will be used in replication.

How can this PR be tested?

The commit has also new mtr test: galera.galera_alter_table_algorithm which verifies that ALTER query rewrite happens when needed

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch
  • [x ] This is a bug fix and the PR is based against the earliest maintained branch in which the bug can be reproduced

Backward compatibility

PR quality check

Copy link
Contributor

@dlenski dlenski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that this bug and this PR apply specifically to the case of Galera replication, and not to other types of replication that MariaDB supports.

I suggest modifying the PR title and description to clarify this.

Perhaps something like the following?

MDEV-30456 Galera replication ignores ALTER_ALGORITHM session variable

ALTER TABLE t1 ADD COLUMN f2 INTEGER, ALGORITHM=INSTANT;
show binlog events limit 1 offset 4;
Log_name Pos Event_type Server_id End_log_pos Info
binlog.000001 367 Query 1 489 use `test`; ALTER TABLE t1 ADD COLUMN f2 INTEGER, ALGORITHM=INSTANT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of the fields here (Pos, End_log_pos, and maybe Log_name and Server_id?) will vary from run to run of this test.

The only thing the test result actually cares about (I think) is the Info column, right?

Consider adding this before each invocation of show binlog events … in the .test file:

--replace_column 1 LOG_NAME 2 POS 4 SERVER_ID 5 END_LOG_POS

See mysql-test/main/alter_table.test, for example, where this is used in other pre-existing tests.

[mysqld.2]
log_slave_updates=ON
log_bin=binlog

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra blank line at end of file.

@@ -108,6 +108,12 @@ class Alter_info
// Number of partitions.
uint num_parts;
private:
#ifdef WITH_WSREP
/* wsrep patch needs to peak the algorithm clause used in ALTER statement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Typo: I believe you meant the word *pick, not peak, here.
  2. Why not simply make the algorithm member public: unconditionally?

If user has specified the desired alter algorithm by using session
variable alter_algorithm, and not specifying the algorithm in the
ALTER SQL statement, then the ALTER will be processed in sending node
according the algorithm chosen by the alter_algorithm variable.
But in receiving nodes, appliers cannot see this session variable,
and will use the default algorithm when executing the ALTER.

The fix in this commit, will check if user has set alter_algorithm
variable and has not specified the algorithm clause in the ALTER
statement, and in such case will rewrite the original ALTER statement
appended by the algorithm clause. This rewritten ALTER statement will
be used in replication.

The commit has also new mtr test: galera.galera_alter_table_algorithm
which verifies that ALTER query rewrite happens when needed
Fixing the regression happening with galera.galera_toi_ddl_nonconflicting
The problem, surfaced by the test, was due to multi-statement used in the test.
The test issues two queries, as multi-statement:

--send ALTER TABLE t1 ADD COLUMN f3 INTEGER; INSERT INTO t1 (f1, f2) VALUES (DEFAULT, 123);

With this, the session's THD structure has in query_string member
the full multi-statement, and this was used as base query in
TOI replication rewriting.

The fix is to pass actual length of the ALTER statement part for
TOI replication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants