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

[CBRD-23633] protocol: Prevent endless busy waiting for query execution in abnormal network circumstance #2252

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/broker/cas_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ extern "C"
PROTOCOL_V6 = 6, /* cci/cas4m support unsigned integer type */
PROTOCOL_V7 = 7, /* timezone types, to pin xasl entry for retry */
PROTOCOL_V8 = 8, /* JSON type */
CURRENT_PROTOCOL = PROTOCOL_V8
PROTOCOL_V9 = 9, /* cas health check: get function status */
CURRENT_PROTOCOL = PROTOCOL_V9
};
typedef enum t_cas_protocol T_CAS_PROTOCOL;

Expand Down
13 changes: 12 additions & 1 deletion src/jdbc/cubrid/jdbc/jci/UConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public class UConnection {
public static final int PROTOCOL_V6 = 6;
public static final int PROTOCOL_V7 = 7;
public static final int PROTOCOL_V8 = 8;
public static final int PROTOCOL_V9 = 9;

/* Current protocol version */
private final static byte CAS_PROTOCOL_VERSION = PROTOCOL_V8;
private final static byte CAS_PROTOCOL_VERSION = PROTOCOL_V9;
private final static byte CAS_PROTO_INDICATOR = 0x40;
private final static byte CAS_PROTO_VER_MASK = 0x3F;
private final static byte CAS_RENEWED_ERROR_CODE = (byte) 0x80;
Expand Down Expand Up @@ -200,6 +201,7 @@ public class UConnection {
private byte[] broker_info = null;
private byte[] casinfo = null;
private int brokerVersion = 0;
private static int protocolVersion = 0;

private boolean isServerSideJdbc = false;
boolean skip_checkcas = false;
Expand Down Expand Up @@ -1936,6 +1938,8 @@ private void connectDB(int timeout) throws IOException, UJciException {
(int) broker_info[BROKER_INFO_PATCH_VERSION]);
}

protocolVersion = (int)version & CAS_PROTO_VER_MASK;

if (protoVersionIsAbove(PROTOCOL_V4)) {
casId = is.readInt();
} else {
Expand Down Expand Up @@ -2058,6 +2062,13 @@ public boolean protoVersionIsAbove(int ver) {
return false;
}

public static boolean protoVersionIsLower(int ver) {
if (protocolVersion < ver){
return true;
}
return false;
}

Comment on lines +2065 to +2071
Copy link
Member

Choose a reason for hiding this comment

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

there is protoVersionIsUnder(). why we need it?

Copy link
Contributor Author

@beyondykk9 beyondykk9 Apr 20, 2020

Choose a reason for hiding this comment

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

We need a new method like as protoVersionIsUnder in order to avoid side effect.
The readability could be considered by code refactoring in the future.

private void setConnectInfo(String info) throws UJciException {
StringTokenizer st = new StringTokenizer(info, ":");
if (st.countTokens() != 2) {
Expand Down
4 changes: 4 additions & 0 deletions src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public int read(byte[] b, int off, int len, int timeout) throws IOException, UJc
String msg = UErrorCode.codeToMessage(UErrorCode.ER_TIMEOUT);
throw new SocketTimeoutException(msg);
}
if (UConnection.protoVersionIsLower(UConnection.PROTOCOL_V9)) {
BrokerHandler.pingBroker(ip, port, PING_TIMEOUT);
continue;
}
if (BrokerHandler.statusBroker(ip, port, pid, session, PING_TIMEOUT) != 1) {
if (retry) {
throw new UJciException(UErrorCode.ER_COMMUNICATION);
Expand Down