You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2023/06/27 06:37:52 UTC

[shardingsphere] branch master updated: Support Change replication source statement for mysql (#26610)

This is an automated email from the ASF dual-hosted git repository.

tuichenchuxin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 5bf72b359a0 Support Change replication source statement for mysql (#26610)
5bf72b359a0 is described below

commit 5bf72b359a0bda80bdb3582b6fc6e90739db031f
Author: niu niu <zi...@aliyun.com>
AuthorDate: Tue Jun 27 14:37:42 2023 +0800

    Support Change replication source statement for mysql (#26610)
    
    * Support change replication source for mysql (#25535)
    
    * Add test parse
---
 .../src/main/antlr4/imports/mysql/MySQLKeyword.g4  | 128 +++++++++++++++++++++
 .../src/main/antlr4/imports/mysql/RLStatement.g4   |  56 +++++++++
 .../sql/parser/autogen/MySQLStatement.g4           |   1 +
 .../statement/type/MySQLRLStatementVisitor.java    |   7 ++
 .../core/database/visitor/SQLVisitorRule.java      |   2 +
 .../MySQLChangeReplicationSourceToStatement.java   |  28 +++++
 .../cases/parser/jaxb/RootSQLParserTestCases.java  |   4 +
 ...ChangeReplicationSourceToStatementTestCase.java |  26 +++++
 .../case/rl/change-replication-source-to.xml       |  21 ++++
 .../supported/rl/change-replication-source-to.xml  |  21 ++++
 10 files changed, 294 insertions(+)

diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
index e5f6f806fd8..956365d61de 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
@@ -123,6 +123,10 @@ AVG
     : A V G
     ;
 
+ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
+    : A S S I G N UL_ G T I D S UL_ T O UL_ A N O N Y M O U S UL_ T R A N S A C T I O N S
+    ;
+
 BIT_XOR
     : B I T UL_ X O R
     ;
@@ -915,6 +919,18 @@ GROUP_REPLICATION
     : G R O U P UL_ R E P L I C A T I O N
     ;
 
+GET_SOURCE_PUBLIC_KEY
+    : G E T UL_ S O U R C E UL_ P U B L I C UL_ K E Y
+    ;
+
+GTID_ONLY
+    : G T I D UL_ O N L Y
+    ;
+
+GENERATE
+    : G E N E R A T E
+    ;
+
 HANDLER
     : H A N D L E R
     ;
@@ -2075,6 +2091,10 @@ REQUIRE_ROW_FORMAT
     : R E Q U I R E UL_ R O W UL_ F O R M A T
     ;
 
+REQUIRE_TABLE_PRIMARY_KEY_CHECK
+    : R E Q U I R E UL_ T A B L E UL_ P R I M A R Y UL_ K E Y UL_ C H E C K
+    ;
+
 RESET
     : R E S E T
     ;
@@ -2539,6 +2559,114 @@ SYSTEM
     : S Y S T E M
     ;
 
+SOURCE_BIND
+    : S O U R C E UL_ B I N D
+    ;
+
+SOURCE_HOST
+    : S O U R C E UL_ H O S T
+    ;
+
+SOURCE_USER
+    : S O U R C E UL_ U S E R
+    ;
+
+SOURCE_PASSWORD
+    : S O U R C E UL_ P A S S W O R D
+    ;
+
+SOURCE_PORT
+    : S O U R C E UL_ P O R T
+    ;
+
+SOURCE_LOG_FILE
+    : S O U R C E UL_ L O G UL_ F I L E
+    ;
+
+SOURCE_LOG_POS
+    : S O U R C E UL_ L O G UL_ P O S
+    ;
+
+SOURCE_AUTO_POSITION
+    : S O U R C E UL_ A U T O UL_ P O S I T I O N
+    ;
+
+SOURCE_HEARTBEAT_PERIOD
+    : S O U R C E UL_ H E A R T B E A T UL_ P E R I O D
+    ;
+
+SOURCE_CONNECT_RETRY
+    : S O U R C E UL_ C O N N E C T UL_ R E T R Y
+    ;
+
+SOURCE_RETRY_COUNT
+    : S O U R C E UL_ R E T R Y UL_ C O U N T
+    ;
+
+SOURCE_CONNECTION_AUTO_FAILOVER
+    : S O U R C E UL_ C O N N E C T I O N UL_ A U T O UL_ F A I L O V E R
+    ;
+
+SOURCE_DELAY
+    : S O U R C E UL_ D E L A Y
+    ;
+
+SOURCE_COMPRESSION_ALGORITHMS
+    : S O U R C E UL_ C O M P R E S S I O N UL_ A L G O R I T H M S
+    ;
+
+SOURCE_ZSTD_COMPRESSION_LEVEL
+    : S O U R C E UL_ Z S T D UL_ C O M P R E S S I O N UL_ L E V E L
+    ;
+
+SOURCE_SSL
+    : S O U R C E UL_ S S L
+    ;
+
+SOURCE_SSL_CA
+    : S O U R C E UL_ S S L UL_ C A
+    ;
+
+SOURCE_SSL_CAPATH
+    : S O U R C E UL_ S S L UL_ C A P A T H
+    ;
+
+SOURCE_SSL_CERT
+    : S O U R C E UL_ S S L UL_ C E R T
+    ;
+
+SOURCE_SSL_CRL
+    : S O U R C E UL_ S S L UL_ C R L
+    ;
+
+SOURCE_SSL_CRLPATH
+    : S O U R C E UL_ S S L UL_ C R L P A T H
+    ;
+
+SOURCE_SSL_KEY
+    : S O U R C E UL_ S S L UL_ K E Y
+    ;
+
+SOURCE_SSL_CIPHER
+    : S O U R C E UL_ S S L UL_ C I P H E R
+    ;
+
+SOURCE_SSL_VERIFY_SERVER_CERT
+    : S O U R C E UL_ S S L UL_ V E R I F Y UL_ S E R V E R UL_ C E R T
+    ;
+
+SOURCE_TLS_VERSION
+    : S O U R C E UL_ T L S UL_ V E R S I O N
+    ;
+
+SOURCE_TLS_CIPHERSUITES
+    : S O U R C E UL_ T L S UL_ C I P H E R S U I T E S
+    ;
+
+SOURCE_PUBLIC_KEY_PATH
+    : S O U R C E UL_ P U B L I C UL_ K E Y UL_ P A T H
+    ;
+
 TABLE
     : T A B L E
     ;
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/RLStatement.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/RLStatement.g4
index 166b0278c47..a3620e8e999 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/RLStatement.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/RLStatement.g4
@@ -31,6 +31,10 @@ changeReplicationFilter
     : CHANGE REPLICATION FILTER filterDefs channelOption?
     ;
 
+changeReplicationSourceTo
+    : CHANGE REPLICATION SOURCE TO changeReplicationSourceOptionDefs channelOption?
+    ;
+
 startSlave
     : START SLAVE threadTypes? utilOption? connectionOptions channelOption?
     ;
@@ -142,3 +146,55 @@ wildTables
 wildTable
     : string_
     ;
+
+changeReplicationSourceOptionDefs
+    : changeReplicationSourceOption (COMMA_ changeReplicationSourceOption)*
+    ;
+
+changeReplicationSourceOption
+    : SOURCE_BIND EQ_ string_
+    | SOURCE_HOST EQ_ string_
+    | SOURCE_USER EQ_ string_
+    | SOURCE_PASSWORD EQ_ string_
+    | SOURCE_PORT EQ_ NUMBER_
+    | PRIVILEGE_CHECKS_USER EQ_ (NULL | ACCOUNT)
+    | REQUIRE_ROW_FORMAT EQ_ NUMBER_
+    | REQUIRE_TABLE_PRIMARY_KEY_CHECK EQ_ tablePrimaryKeyCheckDef
+    | ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS EQ_ assignGtidsToAnonymousTransactionsDef
+    | SOURCE_LOG_FILE EQ_ string_
+    | SOURCE_LOG_POS EQ_ NUMBER_
+    | SOURCE_AUTO_POSITION EQ_ NUMBER_
+    | RELAY_LOG_FILE EQ_ string_
+    | RELAY_LOG_POS EQ_ NUMBER_
+    | SOURCE_HEARTBEAT_PERIOD EQ_ NUMBER_
+    | SOURCE_CONNECT_RETRY EQ_ NUMBER_
+    | SOURCE_RETRY_COUNT EQ_ NUMBER_
+    | SOURCE_CONNECTION_AUTO_FAILOVER EQ_ NUMBER_
+    | SOURCE_DELAY EQ_ NUMBER_
+    | SOURCE_COMPRESSION_ALGORITHMS EQ_ string_
+    | SOURCE_ZSTD_COMPRESSION_LEVEL EQ_ NUMBER_
+    | SOURCE_SSL EQ_ NUMBER_
+    | SOURCE_SSL_CA EQ_ string_
+    | SOURCE_SSL_CAPATH EQ_ string_
+    | SOURCE_SSL_CERT EQ_ string_
+    | SOURCE_SSL_CRL EQ_ string_
+    | SOURCE_SSL_CRLPATH EQ_ string_
+    | SOURCE_SSL_KEY EQ_ string_
+    | SOURCE_SSL_CIPHER EQ_ string_
+    | SOURCE_SSL_VERIFY_SERVER_CERT EQ_ NUMBER_
+    | SOURCE_TLS_VERSION EQ_ string_
+    | SOURCE_TLS_CIPHERSUITES EQ_ string_
+    | SOURCE_PUBLIC_KEY_PATH EQ_ string_
+    | GET_SOURCE_PUBLIC_KEY EQ_ NUMBER_
+    | NETWORK_NAMESPACE EQ_ string_
+    | IGNORE_SERVER_IDS EQ_ ignoreServerIds
+    | GTID_ONLY EQ_ NUMBER_
+    ;
+
+tablePrimaryKeyCheckDef
+    : (STREAM | ON | OFF | GENERATE)
+    ;
+
+assignGtidsToAnonymousTransactionsDef
+    : (OFF | LOCAL | string_)
+    ;
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4 b/parser/sql/dialect/mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
index db1de9027b8..78327eff296 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/MySQLStatement.g4
@@ -108,6 +108,7 @@ execute
     | checkTable
     | checksumTable
     | clone
+    | changeReplicationSourceTo
     | startSlave
     | stopSlave
     | analyzeTable
diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLRLStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLRLStatementVisitor.java
index 1141adfd5e6..dc4268db533 100644
--- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLRLStatementVisitor.java
+++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLRLStatementVisitor.java
@@ -19,11 +19,13 @@ package org.apache.shardingsphere.sql.parser.mysql.visitor.statement.type;
 
 import org.apache.shardingsphere.sql.parser.api.ASTNode;
 import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.RLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeReplicationSourceToContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeMasterToContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.StartSlaveContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.StopSlaveContext;
 import org.apache.shardingsphere.sql.parser.mysql.visitor.statement.MySQLStatementVisitor;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.rl.MySQLChangeMasterStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.rl.MySQLChangeReplicationSourceToStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.rl.MySQLStartSlaveStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.rl.MySQLStopSlaveStatement;
 
@@ -46,4 +48,9 @@ public final class MySQLRLStatementVisitor extends MySQLStatementVisitor impleme
     public ASTNode visitStopSlave(final StopSlaveContext ctx) {
         return new MySQLStopSlaveStatement();
     }
+    
+    @Override
+    public ASTNode visitChangeReplicationSourceTo(final ChangeReplicationSourceToContext ctx) {
+        return new MySQLChangeReplicationSourceToStatement();
+    }
 }
diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index 97185d63a1f..38b719c9e00 100644
--- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -469,6 +469,8 @@ public enum SQLVisitorRule {
     
     CHANGE_MASTER("ChangeMaster", SQLStatementType.RL),
     
+    CHANGE_REPLICATION_SOURCE_TO("ChangeReplicationSourceTo", SQLStatementType.RL),
+    
     START_SLAVE("StartSlave", SQLStatementType.RL),
     
     STOP_SLAVE("StopSlave", SQLStatementType.RL),
diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/rl/MySQLChangeReplicationSourceToStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/rl/MySQLChangeReplicationSourceToStatement.java
new file mode 100644
index 00000000000..c046496ddc0
--- /dev/null
+++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/rl/MySQLChangeReplicationSourceToStatement.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.rl;
+
+import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.rl.RLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+
+/**
+ * My SQL change replication source statement.
+ */
+public final class MySQLChangeReplicationSourceToStatement extends AbstractSQLStatement implements RLStatement, MySQLStatement {
+}
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
index 1498265e0cf..dfa8802acc8 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
@@ -423,6 +423,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.SetTransactionStatementTestCase;
 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.UnlockStatementTestCase;
 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.XATestCase;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rl.ChangeReplicationSourceToStatementTestCase;
 import org.mockito.internal.configuration.plugins.Plugins;
 
 import javax.xml.bind.annotation.XmlElement;
@@ -1664,6 +1665,9 @@ public final class RootSQLParserTestCases {
     @XmlElement(name = "alter-readwrite-splitting-storage-unit-status-disable")
     private final List<AlterReadwriteSplittingStorageUnitStatusStatementTestCase> alterReadwriteSplittingStorageUnitStatusStatementDisableTestCases = new LinkedList<>();
     
+    @XmlElement(name = "change-replication-source-to")
+    private final List<ChangeReplicationSourceToStatementTestCase> changeReplicationSourceToStatementTestCases = new LinkedList<>();
+    
     /**
      * Get all SQL parser test cases.
      *
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rl/ChangeReplicationSourceToStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rl/ChangeReplicationSourceToStatementTestCase.java
new file mode 100644
index 00000000000..d82a97a5bf4
--- /dev/null
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rl/ChangeReplicationSourceToStatementTestCase.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rl;
+
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+
+/**
+ * Change replication source to statement test case.
+ */
+public final class ChangeReplicationSourceToStatementTestCase extends SQLParserTestCase {
+}
diff --git a/test/it/parser/src/main/resources/case/rl/change-replication-source-to.xml b/test/it/parser/src/main/resources/case/rl/change-replication-source-to.xml
new file mode 100644
index 00000000000..d6cb15a133f
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/rl/change-replication-source-to.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<sql-parser-test-cases>
+    <change-replication-source-to sql-case-id="change_replication_source_to" />
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/rl/change-replication-source-to.xml b/test/it/parser/src/main/resources/sql/supported/rl/change-replication-source-to.xml
new file mode 100644
index 00000000000..a57bb19a9fb
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/rl/change-replication-source-to.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<sql-cases>
+    <sql-case id="change_replication_source_to" value="CHANGE REPLICATION SOURCE TO SOURCE_USER = 'plug_user', SOURCE_PASSWORD = 'plug_user', SOURCE_RETRY_COUNT = 0" db-types="MySQL" />
+</sql-cases>