diff --git a/client/src/main/java/com/vesoft/nebula/driver/graph/decode/BytesReader.java b/client/src/main/java/com/vesoft/nebula/driver/graph/decode/BytesReader.java index a16aac50..0fa66b7d 100644 --- a/client/src/main/java/com/vesoft/nebula/driver/graph/decode/BytesReader.java +++ b/client/src/main/java/com/vesoft/nebula/driver/graph/decode/BytesReader.java @@ -5,7 +5,7 @@ package com.vesoft.nebula.driver.graph.decode; -import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.bytesToInt16; +import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.bytesToUInt16; import static com.vesoft.nebula.driver.graph.decode.DecodeUtils.charset; import static com.vesoft.nebula.driver.graph.decode.struct.SizeConstant.ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE; @@ -31,7 +31,7 @@ public ByteString read(int len) { } public String readSizedString(ByteOrder byteOrder) { - int length = bytesToInt16(read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); + int length = bytesToUInt16(read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); int startIndex = index; index += length; ByteString strBytes = data.substring(startIndex, startIndex + length); diff --git a/client/src/main/java/com/vesoft/nebula/driver/graph/decode/ValueParser.java b/client/src/main/java/com/vesoft/nebula/driver/graph/decode/ValueParser.java index 86290327..8d8befad 100644 --- a/client/src/main/java/com/vesoft/nebula/driver/graph/decode/ValueParser.java +++ b/client/src/main/java/com/vesoft/nebula/driver/graph/decode/ValueParser.java @@ -971,7 +971,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) { case COLUMN_TYPE_LIST: ColumnType eleType = ColumnType.getColumnType( bytesToInt8(reader.read(VALUE_TYPE_SIZE))); - int listSize = bytesToInt16( + int listSize = bytesToUInt16( reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); int nullBitSize = (listSize % 8 == 0) ? (listSize / 8) : (listSize / 8 + 1); ByteString nullBitBytes = reader.read(nullBitSize); @@ -986,7 +986,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) { } return values; case COLUMN_TYPE_RECORD: - int recordSize = bytesToInt16( + int recordSize = bytesToUInt16( reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); Map map = new HashMap<>(); for (int i = 0; i < recordSize; i++) { @@ -1002,7 +1002,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) { long nodeId = bytesToInt64(reader.read(NODE_ID_SIZE), byteOrder); int nodeTypeId = getNodeTypeIdFromNodeId(nodeId); int nodeGraphId = bytesToInt32(reader.read(GRAPH_ID_SIZE), byteOrder); - int nodePropNum = bytesToInt16( + int nodePropNum = bytesToUInt16( reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); Map nodeProperties = new HashMap<>(); for (int i = 0; i < nodePropNum; i++) { @@ -1020,7 +1020,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) { long rank = bytesToInt64(reader.read(RANK_SIZE), byteOrder); int edgeGraphId = bytesToInt32(reader.read(GRAPH_ID_SIZE), byteOrder); int edgeTypeId = bytesToInt32(reader.read(EDGE_TYPE_ID_SIZE), byteOrder); - int edgePropNum = bytesToInt16( + int edgePropNum = bytesToUInt16( reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); Map edgeProperties = new HashMap<>(); for (int i = 0; i < edgePropNum; i++) { @@ -1038,7 +1038,7 @@ private Object decodeCompositeValue(BytesReader reader, ColumnType type) { edgeProperties, graphSchemas); case COLUMN_TYPE_PATH: - int elementNum = bytesToInt16( + int elementNum = bytesToUInt16( reader.read(ELEMENT_NUMBER_SIZE_FOR_ANY_VALUE), byteOrder); List eleValues = new ArrayList<>(); for (int i = 0; i < elementNum; i++) { diff --git a/client/src/main/java/com/vesoft/nebula/driver/graph/net/Constants.java b/client/src/main/java/com/vesoft/nebula/driver/graph/net/Constants.java index ddff1bcc..40f0a6f8 100644 --- a/client/src/main/java/com/vesoft/nebula/driver/graph/net/Constants.java +++ b/client/src/main/java/com/vesoft/nebula/driver/graph/net/Constants.java @@ -17,7 +17,7 @@ public class Constants { static final long DEFAULT_HEALTH_CHECK_TIME_MS = 5 * 60 * 1000; static final boolean DEFAULT_TEST_ON_BORROW = true; static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = false; - static final long DEFAULT_MAX_WAIT_MS = Long.MAX_VALUE; + static final long DEFAULT_MAX_WAIT_MS = Long.MAX_VALUE / 1000; static final long DEFAULT_IDLE_EVICT_SCHEDULE_MS = -1; static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MS = 30 * 60 * 1000; static final boolean DEFAULT_STRICT_SERVER_HEALTHY = false; diff --git a/client/src/main/java/com/vesoft/nebula/driver/graph/net/NebulaPool.java b/client/src/main/java/com/vesoft/nebula/driver/graph/net/NebulaPool.java index ad4804a2..65fd8df7 100644 --- a/client/src/main/java/com/vesoft/nebula/driver/graph/net/NebulaPool.java +++ b/client/src/main/java/com/vesoft/nebula/driver/graph/net/NebulaPool.java @@ -9,6 +9,7 @@ import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_ENABLE_TLS; import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_LIFE_TIME_MS; import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_PING_TIMEOUT_MS; +import static com.vesoft.nebula.driver.graph.net.Constants.DEFAULT_MAX_WAIT_MS; import com.vesoft.nebula.driver.graph.data.HostAddress; import com.vesoft.nebula.driver.graph.exception.AuthFailedException; @@ -75,8 +76,8 @@ private NebulaPool(Builder builder) throws IOErrorException, AuthFailedException } ClientPoolFactory factory = new ClientPoolFactory( - loadBalancer, - builder); + loadBalancer, + builder); pool = new GenericObjectPool<>(factory, objConfig); hasInit.compareAndSet(false, true); } @@ -96,7 +97,7 @@ public NebulaClient getClient() throws Exception { */ public void returnClient(NebulaClient client) { if (client.isClosed() - || (System.currentTimeMillis() - client.getCreateTime()) >= maxLifeMills) { + || (System.currentTimeMillis() - client.getCreateTime()) >= maxLifeMills) { try { pool.invalidateObject(client); } catch (Exception e) { @@ -168,7 +169,7 @@ public static class Builder { // the max wait time if blockWhenExhausted is true. if value is less than 0, always wait. // unit: millisecond - protected long maxWaitMills = Constants.DEFAULT_MAX_WAIT_MS; + protected long maxWaitMills = DEFAULT_MAX_WAIT_MS; // the schedule time for test the idle session and evict it. if value is less than 0, // never evict the idle sessions. @@ -272,7 +273,7 @@ public Builder withMinClientSize(int minClientSize) { */ public Builder withConnectTimeoutMills(long connectTimeoutMills) { if (connectTimeoutMills <= 0 - || connectTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) { + || connectTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) { this.connectTimeoutMills = Constants.DEFAULT_MAX_TIMEOUT_MS; } else { this.connectTimeoutMills = connectTimeoutMills; @@ -289,7 +290,7 @@ public Builder withConnectTimeoutMills(long connectTimeoutMills) { */ public Builder withRequestTimeoutMills(long requestTimeoutMills) { if (requestTimeoutMills <= 0 - || requestTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) { + || requestTimeoutMills > Constants.DEFAULT_MAX_TIMEOUT_MS) { this.requestTimeoutMills = Constants.DEFAULT_MAX_TIMEOUT_MS; } else { this.requestTimeoutMills = requestTimeoutMills; @@ -306,7 +307,7 @@ public Builder withRequestTimeoutMills(long requestTimeoutMills) { */ public Builder withServerPingTimeoutMills(long serverPingTimeoutMills) { if (serverPingTimeoutMills < 0 - || serverPingTimeoutMills > DEFAULT_MAX_PING_TIMEOUT_MS) { + || serverPingTimeoutMills > DEFAULT_MAX_PING_TIMEOUT_MS) { this.serverPingTimeoutMills = DEFAULT_MAX_PING_TIMEOUT_MS; } else { this.serverPingTimeoutMills = serverPingTimeoutMills; @@ -357,7 +358,11 @@ public Builder withTestOnBorrow(boolean testOnBorrow) { * @return NebulaPool.Builder */ public Builder withMaxWaitMills(long maxWaitMills) { - this.maxWaitMills = maxWaitMills <= 0 ? Long.MAX_VALUE : maxWaitMills; + if (maxWaitMills <= 0 || maxWaitMills > DEFAULT_MAX_WAIT_MS) { + this.maxWaitMills = DEFAULT_MAX_WAIT_MS; + } else { + this.maxWaitMills = maxWaitMills; + } return this; }