Skip to content

Commit f1c4f8b

Browse files
authored
cherrypick:fix uint for string length & update default maxWaitTime (#637)
* fix uint for string length * update default max wait time
1 parent ac7561a commit f1c4f8b

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

client/src/main/java/com/vesoft/nebula/driver/graph/decode/BytesReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package com.vesoft.nebula.driver.graph.decode;
77

8-
import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.bytesToInt16;
8+
import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.bytesToUInt16;
99
import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.charset;
1010
import static com.vesoft.nebula.driver.graph.decode.struct.SizeConstant.ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE;
1111

@@ -31,7 +31,7 @@ public ByteString read(int len) {
3131
}
3232

3333
public String readSizedString(ByteOrder byteOrder) {
34-
int length = bytesToInt16(read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
34+
int length = bytesToUInt16(read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
3535
int startIndex = index;
3636
index += length;
3737
ByteString strBytes = data.substring(startIndex, startIndex + length);

client/src/main/java/com/vesoft/nebula/driver/graph/decode/ValueParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) {
971971
case COLUMN_TYPE_LIST:
972972
ColumnType eleType = ColumnType.getColumnType(
973973
bytesToInt8(reader.read(VALUE_TYPE_SIZE)));
974-
int listSize = bytesToInt16(
974+
int listSize = bytesToUInt16(
975975
reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
976976
int nullBitSize = (listSize % 8 == 0) ? (listSize / 8) : (listSize / 8 + 1);
977977
ByteString nullBitBytes = reader.read(nullBitSize);
@@ -986,7 +986,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) {
986986
}
987987
return values;
988988
case COLUMN_TYPE_RECORD:
989-
int recordSize = bytesToInt16(
989+
int recordSize = bytesToUInt16(
990990
reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
991991
Map<String, ValueWrapper> map = new HashMap<>();
992992
for (int i = 0; i < recordSize; i++) {
@@ -1002,7 +1002,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) {
10021002
long nodeId = bytesToInt64(reader.read(NODE_ID_SIZE), byteOrder);
10031003
int nodeTypeId = getNodeTypeIdFromNodeId(nodeId);
10041004
int nodeGraphId = bytesToInt32(reader.read(GRAPH_ID_SIZE), byteOrder);
1005-
int nodePropNum = bytesToInt16(
1005+
int nodePropNum = bytesToUInt16(
10061006
reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
10071007
Map<String, ValueWrapper> nodeProperties = new HashMap<>();
10081008
for (int i = 0; i < nodePropNum; i++) {
@@ -1020,7 +1020,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) {
10201020
long rank = bytesToInt64(reader.read(RANK_SIZE), byteOrder);
10211021
int edgeGraphId = bytesToInt32(reader.read(GRAPH_ID_SIZE), byteOrder);
10221022
int edgeTypeId = bytesToInt32(reader.read(EDGE_TYPE_ID_SIZE), byteOrder);
1023-
int edgePropNum = bytesToInt16(
1023+
int edgePropNum = bytesToUInt16(
10241024
reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
10251025
Map<String, ValueWrapper> edgeProperties = new HashMap<>();
10261026
for (int i = 0; i < edgePropNum; i++) {
@@ -1038,7 +1038,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) {
10381038
edgeProperties,
10391039
graphSchemas);
10401040
case COLUMN_TYPE_PATH:
1041-
int elementNum = bytesToInt16(
1041+
int elementNum = bytesToUInt16(
10421042
reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder);
10431043
List<ValueWrapper> eleValues = new ArrayList<>();
10441044
for (int i = 0; i < elementNum; i++) {

client/src/main/java/com/vesoft/nebula/driver/graph/net/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Constants {
1717
static final long DEFAULT_HEALTH_CHECK_TIME_MS = 5 * 60 * 1000;
1818
static final boolean DEFAULT_TEST_ON_BORROW = true;
1919
static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = false;
20-
static final long DEFAULT_MAX_WAIT_MS = Long.MAX_VALUE;
20+
static final long DEFAULT_MAX_WAIT_MS = Long.MAX_VALUE / 1000;
2121
static final long DEFAULT_IDLE_EVICT_SCHEDULE_MS = -1;
2222
static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MS = 30 * 60 * 1000;
2323
static final boolean DEFAULT_STRICT_SERVER_HEALTHY = false;

client/src/main/java/com/vesoft/nebula/driver/graph/net/NebulaPool.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_ENABLE_TLS;
1010
import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_LIFE_TIME_MS;
1111
import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_PING_TIMEOUT_MS;
12+
import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_WAIT_MS;
1213

1314
import com.vesoft.nebula.driver.graph.data.HostAddress;
1415
import com.vesoft.nebula.driver.graph.exception.AuthFailedException;
@@ -75,8 +76,8 @@ private NebulaPool(Builder builder) throws IOErrorException, AuthFailedException
7576
}
7677

7778
ClientPoolFactory factory = new ClientPoolFactory(
78-
loadBalancer,
79-
builder);
79+
loadBalancer,
80+
builder);
8081
pool = new GenericObjectPool<>(factory, objConfig);
8182
hasInit.compareAndSet(false, true);
8283
}
@@ -96,7 +97,7 @@ public NebulaClient getClient() throws Exception {
9697
*/
9798
public void returnClient(NebulaClient client) {
9899
if (client.isClosed()
99-
|| (System.currentTimeMillis() - client.getCreateTime()) >= maxLifeMills) {
100+
|| (System.currentTimeMillis() - client.getCreateTime()) >= maxLifeMills) {
100101
try {
101102
pool.invalidateObject(client);
102103
} catch (Exception e) {
@@ -168,7 +169,7 @@ public static class Builder {
168169

169170
// the max wait time if blockWhenExhausted is true. if value is less than 0, always wait.
170171
// unit: millisecond
171-
protected long maxWaitMills = Constants.DEFAULT_MAX_WAIT_MS;
172+
protected long maxWaitMills = DEFAULT_MAX_WAIT_MS;
172173

173174
// the schedule time for test the idle session and evict it. if value is less than 0,
174175
// never evict the idle sessions.
@@ -272,7 +273,7 @@ public Builder withMinClientSize(int minClientSize) {
272273
*/
273274
public Builder withConnectTimeoutMills(long connectTimeoutMills) {
274275
if (connectTimeoutMills <= 0
275-
|| connectTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) {
276+
|| connectTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) {
276277
this.connectTimeoutMills = Constants.DEFAULT_MAX_TIMEOUT_MS;
277278
} else {
278279
this.connectTimeoutMills = connectTimeoutMills;
@@ -289,7 +290,7 @@ public Builder withConnectTimeoutMills(long connectTimeoutMills) {
289290
*/
290291
public Builder withRequestTimeoutMills(long requestTimeoutMills) {
291292
if (requestTimeoutMills <= 0
292-
|| requestTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) {
293+
|| requestTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) {
293294
this.requestTimeoutMills = Constants.DEFAULT_MAX_TIMEOUT_MS;
294295
} else {
295296
this.requestTimeoutMills = requestTimeoutMills;
@@ -306,7 +307,7 @@ public Builder withRequestTimeoutMills(long requestTimeoutMills) {
306307
*/
307308
public Builder withServerPingTimeoutMills(long serverPingTimeoutMills) {
308309
if (serverPingTimeoutMills < 0
309-
|| serverPingTimeoutMills > DEFAULT_MAX_PING_TIMEOUT_MS) {
310+
|| serverPingTimeoutMills > DEFAULT_MAX_PING_TIMEOUT_MS) {
310311
this.serverPingTimeoutMills = DEFAULT_MAX_PING_TIMEOUT_MS;
311312
} else {
312313
this.serverPingTimeoutMills = serverPingTimeoutMills;
@@ -357,7 +358,11 @@ public Builder withTestOnBorrow(boolean testOnBorrow) {
357358
* @return NebulaPool.Builder
358359
*/
359360
public Builder withMaxWaitMills(long maxWaitMills) {
360-
this.maxWaitMills = maxWaitMills <= 0 ? Long.MAX_VALUE : maxWaitMills;
361+
if (maxWaitMills <= 0 || maxWaitMills > DEFAULT_MAX_WAIT_MS) {
362+
this.maxWaitMills = DEFAULT_MAX_WAIT_MS;
363+
} else {
364+
this.maxWaitMills = maxWaitMills;
365+
}
361366
return this;
362367
}
363368

0 commit comments

Comments
 (0)