Skip to content

Commit

Permalink
[misc] failover query relaunched correction
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 30, 2016
1 parent cbddaca commit c050427
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
Expand Up @@ -267,8 +267,8 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws
HandleErrorResult handleErrorResult = new HandleErrorResult(true);
if (method != null) {
if ("executeQuery".equals(method.getName())) {
if (args[0] instanceof String) {
String query = ((String) args[0]).toUpperCase();
if (args[1] instanceof String) {
String query = ((String) args[1]).toUpperCase();
if (!query.equals("ALTER SYSTEM CRASH")
&& !query.startsWith("KILL")) {
handleErrorResult.resultObject = method.invoke(currentProtocol, args);
Expand Down Expand Up @@ -300,9 +300,11 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws
* @return true if can be re-executed
*/
public boolean isQueryRelaunchable(Method method, Object[] args) {
if (method != null && "executeQuery".equals(method.getName())) {
if (args[0] instanceof String) {
return ((String) args[0]).toUpperCase().startsWith("SELECT");
if (method != null) {
if ("executeQuery".equals(method.getName()) && args[1] instanceof String) {
return ((String) args[1]).toUpperCase().startsWith("SELECT");
} else if ("executePreparedQuery".equals(method.getName()) && args[2] instanceof String) {
return ((String) args[2]).toUpperCase().startsWith("SELECT");
}
}
return false;
Expand Down
Expand Up @@ -414,7 +414,7 @@ private void setSessionOptions() throws QueryException {
private void handleConnectionPhases() throws QueryException {
InputStream reader = null;
try {
reader = new BufferedInputStream(socket.getInputStream());
reader = new BufferedInputStream(socket.getInputStream(), 16384);
packetFetcher = new ReadPacketFetcher(reader);
writer = new PacketOutputStream(socket.getOutputStream());

Expand All @@ -439,7 +439,7 @@ private void handleConnectionPhases() throws QueryException {
sslSocket.startHandshake();
socket = sslSocket;
writer = new PacketOutputStream(socket.getOutputStream());
reader = new BufferedInputStream(socket.getInputStream());
reader = new BufferedInputStream(socket.getInputStream(), 16384);
packetFetcher = new ReadPacketFetcher(reader);

packetSeq++;
Expand Down
Expand Up @@ -132,7 +132,7 @@ public void socketTimeoutTest() throws SQLException {
rs.next();

// wait for the connection to time out
ps = connection.prepareStatement("SELECT sleep(5)");
ps = connection.prepareStatement("DO sleep(5)");

// a timeout should occur here
try {
Expand Down
Expand Up @@ -97,6 +97,7 @@ public void failoverRelaunchedWhenSelect() throws Throwable {
try {
st.execute("SELECT * from selectFailover" + jobId);
} catch (SQLException e) {
e.printStackTrace();
Assert.fail("must not have thrown error");
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/mariadb/jdbc/failover/BaseReplication.java
Expand Up @@ -72,13 +72,14 @@ public void failoverSlaveAndMasterRewrite() throws Throwable {

try {
Statement stmt = connection.createStatement();
stmt.addBatch("SELECT 1");
stmt.addBatch("SELECT 2");
stmt.addBatch("DO 1");
stmt.addBatch("DO 2");
int[] resultData = stmt.executeBatch();
int secondSlaveId = getServerId(connection);
assertEquals("the 2 batch queries must have been executed when failover", 2, resultData.length);
assertTrue(secondSlaveId != firstSlaveId && secondSlaveId != masterServerId);
} catch (SQLException e) {
e.printStackTrace();
Assert.fail();
}
} finally {
Expand Down

0 comments on commit c050427

Please sign in to comment.