-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not send MySQL batches at once if pipelining is disabled (#1257)
* Do not send MySQL batches at once if pipelining is disabled Fixes #1254 For example, if you send queries through ProxySQL, the batched operation will fail. Also: - make sure errors are reported correctly - created a ProxySQL rule to be able to easily create more tests for it Signed-off-by: Thomas Segismont <[email protected]> * ExtendedBatchQueryCommandCodec: use Bitset instead of array of booleans Signed-off-by: Thomas Segismont <[email protected]> Signed-off-by: Thomas Segismont <[email protected]>
- Loading branch information
1 parent
2e09f59
commit d00b8ae
Showing
12 changed files
with
347 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLBatchInsertExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
|
||
package io.vertx.mysqlclient; | ||
|
||
import io.vertx.ext.unit.junit.VertxUnitRunner; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(VertxUnitRunner.class) | ||
public class MySQLBatchInsertExceptionTest extends MySQLBatchInsertExceptionTestBase { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...sql-client/src/test/java/io/vertx/mysqlclient/MySQLPipelinedBatchInsertExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
|
||
package io.vertx.mysqlclient; | ||
|
||
import io.vertx.ext.unit.junit.VertxUnitRunner; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(VertxUnitRunner.class) | ||
public class MySQLPipelinedBatchInsertExceptionTest extends MySQLBatchInsertExceptionTestBase { | ||
|
||
protected MySQLConnectOptions createOptions() { | ||
return super.createOptions().setPipeliningLimit(64); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
vertx-mysql-client/src/test/java/io/vertx/mysqlclient/ProxySQLBatchInsertExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
|
||
package io.vertx.mysqlclient; | ||
|
||
import io.vertx.ext.unit.junit.VertxUnitRunner; | ||
import io.vertx.mysqlclient.junit.ProxySQLRule; | ||
import org.junit.ClassRule; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(VertxUnitRunner.class) | ||
public class ProxySQLBatchInsertExceptionTest extends MySQLBatchInsertExceptionTestBase { | ||
|
||
@ClassRule | ||
public static ProxySQLRule proxySql = new ProxySQLRule(rule); | ||
|
||
@Override | ||
protected MySQLConnectOptions createOptions() { | ||
return proxySql.options(super.createOptions()); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
vertx-mysql-client/src/test/java/io/vertx/mysqlclient/junit/ProxySQLRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.vertx.mysqlclient.junit; | ||
|
||
import io.vertx.mysqlclient.MySQLConnectOptions; | ||
import org.junit.rules.ExternalResource; | ||
import org.testcontainers.containers.Container; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static java.lang.String.*; | ||
|
||
public class ProxySQLRule extends ExternalResource { | ||
|
||
private static final String MONITORING_USER = "proxysql"; | ||
private static final String MONITORING_USER_PASSWORD = "proxysql1234#"; | ||
|
||
private final MySQLRule mySQLRule; | ||
private GenericContainer<?> proxySql; | ||
|
||
public ProxySQLRule(MySQLRule mySQLRule) { | ||
this.mySQLRule = mySQLRule; | ||
} | ||
|
||
@Override | ||
protected void before() throws Throwable { | ||
proxySql = new GenericContainer<>("proxysql/proxysql") | ||
.withCreateContainerCmdModifier(createContainerCmd -> { | ||
createContainerCmd.getHostConfig().withNetworkMode(mySQLRule.network()); | ||
}) | ||
.withExposedPorts(6032, 6033, 6070) | ||
.waitingFor(Wait.forLogMessage(".*Latest ProxySQL version available.*\\n", 1)); | ||
|
||
proxySql.start(); | ||
|
||
execStatement("UPDATE global_variables SET variable_value='false' WHERE variable_name='admin-hash_passwords'", 10); | ||
execStatement("LOAD ADMIN VARIABLES TO RUNTIME"); | ||
|
||
execStatement(format("UPDATE global_variables SET variable_value='%s' WHERE variable_name='mysql-monitor_username'", MONITORING_USER)); | ||
execStatement(format("UPDATE global_variables SET variable_value='%s' WHERE variable_name='mysql-monitor_password'", MONITORING_USER_PASSWORD)); | ||
|
||
execStatement("LOAD MYSQL VARIABLES TO RUNTIME"); | ||
|
||
execStatement(format("INSERT INTO mysql_servers(hostgroup_id, hostname, port) VALUES (0,'%s',3306)", mySQLRule.networkAlias())); | ||
execStatement("LOAD MYSQL SERVERS TO RUNTIME"); | ||
|
||
execStatement(format("INSERT INTO mysql_users (username,password) VALUES ('%s','%s')", mySQLRule.options().getUser(), mySQLRule.options().getPassword())); | ||
execStatement("LOAD MYSQL USERS TO RUNTIME"); | ||
} | ||
|
||
private void execStatement(String statement) throws Exception { | ||
execStatement(statement, 0); | ||
} | ||
|
||
private void execStatement(String statement, int retry) throws Exception { | ||
RuntimeException failure; | ||
for (int i = 0; ; i++) { | ||
Container.ExecResult result = proxySql.execInContainer("mysql", "-u", "admin", "-p" + "admin", "-h", "127.0.0.1", "-P", "6032", "-e", statement); | ||
if (result.getExitCode() == 0) { | ||
return; | ||
} | ||
if (i >= retry && !result.getStderr().contains("ERROR 2002")) { | ||
failure = new RuntimeException("Failed to execute statement: " + statement + "\n" + result.getStderr()); | ||
break; | ||
} | ||
TimeUnit.MILLISECONDS.sleep(200); | ||
} | ||
throw failure; | ||
} | ||
|
||
public MySQLConnectOptions options(MySQLConnectOptions other) { | ||
return new MySQLConnectOptions(other) | ||
.setHost(proxySql.getHost()) | ||
.setPort(proxySql.getMappedPort(6033)); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
if (proxySql != null) { | ||
proxySql.stop(); | ||
} | ||
} | ||
} |
Oops, something went wrong.