Skip to content

Commit 9728a9b

Browse files
committed
fix isKeyInRange when encounter MinObObj or MaxObObj
1 parent 2944cca commit 9728a9b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableRemoting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public ObPayload invokeSync(final ObTableConnection conn, final ObPayload reques
123123
boolean isNeedRefreshMeta = false;
124124
ObRpcResultCode resultCode = new ObRpcResultCode();
125125
resultCode.decode(buf);
126-
logger.debug("require_rerouting_: {}, need_refresh_kv_meta_: {}"
126+
logger.debug("require_rerouting: {}, need_refresh_kv_meta: {}"
127127
, response.getHeader().isRoutingWrong(), response.getHeader().isNeedRefreshKvMeta());
128128
if (response.getHeader().getPcode() != Pcodes.OB_TABLE_API_MOVE) {
129129
if (resultCode.getRcode() != 0) {

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/query/ObTableQuery.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,31 @@ private byte[] parseStartKeyToBytes(List<ObObj> key) {
108108
}
109109

110110
private boolean isKeyInRange(ObNewRange range, List<ObObj> key) {
111-
byte[] startKeyBytes = parseStartKeyToBytes(range.getStartKey().getObjs());
112-
byte[] endKeyBytes = parseStartKeyToBytes(range.getEndKey().getObjs());
113-
byte[] keyBytes = parseStartKeyToBytes(key);
111+
if (range.getStartKey().getObj(0).isMinObj() && range.getEndKey().getObj(0).isMaxObj()) {
112+
return true;
113+
} else if (range.getStartKey().getObj(0).isMinObj()) {
114+
byte[] keyBytes = parseStartKeyToBytes(key);
115+
byte[] endKeyBytes = parseStartKeyToBytes(range.getEndKey().getObjs());
116+
int endComparison = compareByteArrays(endKeyBytes, keyBytes);
117+
return endComparison > 0;
118+
} else if (range.getEndKey().getObj(0).isMaxObj()) {
119+
byte[] keyBytes = parseStartKeyToBytes(key);
120+
byte[] startKeyBytes = parseStartKeyToBytes(range.getStartKey().getObjs());
121+
int startComparison = compareByteArrays(startKeyBytes, keyBytes);
122+
return startComparison <= 0;
123+
} else {
124+
byte[] startKeyBytes = parseStartKeyToBytes(range.getStartKey().getObjs());
125+
byte[] endKeyBytes = parseStartKeyToBytes(range.getEndKey().getObjs());
126+
byte[] keyBytes = parseStartKeyToBytes(key);
114127

115-
int startComparison = compareByteArrays(startKeyBytes, keyBytes);
116-
int endComparison = compareByteArrays(endKeyBytes, keyBytes);
128+
int startComparison = compareByteArrays(startKeyBytes, keyBytes);
129+
int endComparison = compareByteArrays(endKeyBytes, keyBytes);
117130

118-
boolean withinStart = startComparison <= 0;
119-
boolean withinEnd = endComparison > 0;
131+
boolean withinStart = startComparison <= 0;
132+
boolean withinEnd = endComparison > 0;
120133

121-
return withinStart && withinEnd;
134+
return withinStart && withinEnd;
135+
}
122136
}
123137

124138

0 commit comments

Comments
 (0)