From 098e08f56beeae8cb1a8091c9cc06daeb647a088 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Mon, 20 Apr 2020 09:16:11 +0900 Subject: [PATCH] [CBRD-23633] protocol: Prevent endless busy waiting for query execution in abnormal network circumstance --- src/broker/cas_protocol.h | 3 ++- src/jdbc/cubrid/jdbc/jci/UConnection.java | 13 ++++++++++++- src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/broker/cas_protocol.h b/src/broker/cas_protocol.h index 445fd593c2d..da3abed9f5f 100644 --- a/src/broker/cas_protocol.h +++ b/src/broker/cas_protocol.h @@ -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; diff --git a/src/jdbc/cubrid/jdbc/jci/UConnection.java b/src/jdbc/cubrid/jdbc/jci/UConnection.java index dae4f566e79..e086c982b04 100644 --- a/src/jdbc/cubrid/jdbc/jci/UConnection.java +++ b/src/jdbc/cubrid/jdbc/jci/UConnection.java @@ -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; @@ -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; @@ -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 { @@ -2058,6 +2062,13 @@ public boolean protoVersionIsAbove(int ver) { return false; } + public static boolean protoVersionIsLower(int ver) { + if (protocolVersion < ver){ + return true; + } + return false; + } + private void setConnectInfo(String info) throws UJciException { StringTokenizer st = new StringTokenizer(info, ":"); if (st.countTokens() != 2) { diff --git a/src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java b/src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java index cf29cb6ef6c..d8749d5e5f5 100644 --- a/src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java +++ b/src/jdbc/cubrid/jdbc/jci/UTimedDataInputStream.java @@ -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);