Skip to content

Commit

Permalink
#3555, carry PR#5178 to dev-4.x (#5731)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuohai666 authored May 21, 2020
1 parent d3aa8e1 commit 8ad915c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.binary.execute;

import lombok.Getter;
import org.apache.shardingsphere.database.protocol.error.CommonErrorCode;
import org.apache.shardingsphere.database.protocol.mysql.constant.MySQLColumnType;
import org.apache.shardingsphere.database.protocol.mysql.packet.MySQLPacket;
Expand Down Expand Up @@ -57,6 +58,10 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {

private volatile boolean isQuery;

@Getter
private volatile boolean isUpdateResponse;

@Getter
private volatile boolean isErrorResponse;

private int currentSequenceId;
Expand All @@ -77,6 +82,7 @@ public Collection<DatabasePacket> execute() {
return Collections.singletonList(createErrorPacket(((ErrorResponse) backendResponse).getCause()));
}
if (backendResponse instanceof UpdateResponse) {
isUpdateResponse = true;
return Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
isQuery = true;
Expand Down Expand Up @@ -108,11 +114,6 @@ public boolean isQuery() {
return isQuery;
}

@Override
public boolean isErrorResponse() {
return isErrorResponse;
}

@Override
public boolean next() throws SQLException {
return databaseCommunicationEngine.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.text.query;

import lombok.Getter;
import org.apache.shardingsphere.database.protocol.error.CommonErrorCode;
import org.apache.shardingsphere.database.protocol.mysql.constant.MySQLColumnType;
import org.apache.shardingsphere.database.protocol.mysql.packet.MySQLPacket;
Expand Down Expand Up @@ -57,6 +58,10 @@ public final class MySQLComQueryPacketExecutor implements QueryCommandExecutor {

private volatile boolean isQuery;

@Getter
private volatile boolean isUpdateResponse;

@Getter
private volatile boolean isErrorResponse;

private int currentSequenceId;
Expand All @@ -76,6 +81,7 @@ public Collection<DatabasePacket> execute() {
return Collections.singletonList(createErrorPacket(((ErrorResponse) backendResponse).getCause()));
}
if (backendResponse instanceof UpdateResponse) {
isUpdateResponse = true;
return Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
isQuery = true;
Expand Down Expand Up @@ -124,11 +130,6 @@ public boolean isQuery() {
return isQuery;
}

@Override
public boolean isErrorResponse() {
return isErrorResponse;
}

@Override
public boolean next() throws SQLException {
return textProtocolBackendHandler.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void writeQueryData(final ChannelHandlerContext context,
context.write(new PostgreSQLReadyForQueryPacket());
return;
}
if (queryCommandExecutor.isErrorResponse()) {
if (queryCommandExecutor.isErrorResponse() || queryCommandExecutor.isUpdateResponse()) {
context.write(new PostgreSQLReadyForQueryPacket());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.shardingproxy.frontend.postgresql.command.query.binary.bind;

import lombok.Getter;
import org.apache.shardingsphere.database.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.database.protocol.postgresql.constant.PostgreSQLColumnType;
import org.apache.shardingsphere.database.protocol.postgresql.packet.PostgreSQLPacket;
Expand Down Expand Up @@ -60,6 +61,10 @@ public final class PostgreSQLComBindExecutor implements QueryCommandExecutor {

private volatile boolean isQuery;

@Getter
private volatile boolean isUpdateResponse;

@Getter
private volatile boolean isErrorResponse;

public PostgreSQLComBindExecutor(final PostgreSQLComBindPacket packet, final BackendConnection backendConnection) {
Expand All @@ -84,6 +89,7 @@ public Collection<DatabasePacket> execute() {
result.add(createErrorPacket((ErrorResponse) backendResponse));
}
if (backendResponse instanceof UpdateResponse) {
isUpdateResponse = true;
result.add(createUpdatePacket((UpdateResponse) backendResponse));
}
if (backendResponse instanceof QueryResponse) {
Expand Down Expand Up @@ -123,11 +129,6 @@ public boolean isQuery() {
return isQuery;
}

@Override
public boolean isErrorResponse() {
return isErrorResponse;
}

@Override
public boolean next() throws SQLException {
return null != databaseCommunicationEngine && databaseCommunicationEngine.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.shardingproxy.frontend.postgresql.command.query.text;

import lombok.Getter;
import org.apache.shardingsphere.database.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.database.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.PostgreSQLColumnDescription;
Expand Down Expand Up @@ -54,6 +55,10 @@ public final class PostgreSQLComQueryExecutor implements QueryCommandExecutor {

private volatile boolean isQuery;

@Getter
private volatile boolean isUpdateResponse;

@Getter
private volatile boolean isErrorResponse;

public PostgreSQLComQueryExecutor(final PostgreSQLComQueryPacket comQueryPacket, final BackendConnection backendConnection) {
Expand All @@ -71,6 +76,7 @@ public Collection<DatabasePacket> execute() {
return Collections.singletonList(createErrorPacket((ErrorResponse) backendResponse));
}
if (backendResponse instanceof UpdateResponse) {
isUpdateResponse = true;
return Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
Optional<PostgreSQLRowDescriptionPacket> result = createQueryPacket((QueryResponse) backendResponse);
Expand Down Expand Up @@ -108,11 +114,6 @@ public boolean isQuery() {
return isQuery;
}

@Override
public boolean isErrorResponse() {
return isErrorResponse;
}

@Override
public boolean next() throws SQLException {
return textProtocolBackendHandler.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
*/
public interface QueryCommandExecutor extends CommandExecutor {

/**
* Judge is update response.
*
* @return is update response or not
*/
boolean isUpdateResponse();

/**
* Judge is error response.
*
Expand Down

0 comments on commit 8ad915c

Please sign in to comment.