浏览代码

Merge pull request #10 from youny626/branch-0.5.0

fix connected() & add port range check &  add @nonnull annotation & set maxInboundMessageSize
Jin Hai 5 年之前
父节点
当前提交
959328754f

+ 17 - 0
CHANGELOG.md

@@ -0,0 +1,17 @@
+### Bug
+---
+    
+### Improvement
+---
+- \#3: Force channel to request connection in connect()  and some code cleanup
+- \#6: Update pom & fix deleteByRange error message & update unittest
+- \#8: change default timeout to 24 hour
+- \#9: Add more getters in SearchResponse & add normalize method in unittest
+- \#10: fix connected() & add port range check & add @nonnull annotation & set maxInboundMessageSize    
+    
+### New Feature
+---
+
+### Task
+---
+- \#1: First implementation

+ 1 - 1
src/main/java/io/milvus/client/CommandParam.java

@@ -13,7 +13,7 @@ public class CommandParam {
         // Optional parameters - initialized to default values
         private long timeout = 86400;
 
-        public Builder(String command) {
+        public Builder(@Nonnull String command) {
             this.command = command;
         }
 

+ 2 - 2
src/main/java/io/milvus/client/ConnectParam.java

@@ -11,12 +11,12 @@ public class ConnectParam {
         private String host = "127.0.0.1";
         private String port = "19530";
 
-        public Builder withHost(String host) {
+        public Builder withHost(@Nonnull String host) {
             this.host = host;
             return this;
         }
 
-        public Builder withPort(String port) {
+        public Builder withPort(@Nonnull String port) {
             this.port = port;
             return this;
         }

+ 4 - 3
src/main/java/io/milvus/client/DateRange.java

@@ -1,21 +1,22 @@
 package io.milvus.client;
 
+import javax.annotation.Nonnull;
 import java.util.Date;
 
 public class DateRange {
     private Date startDate;
     private Date endDate;
 
-    public DateRange(Date startDate, Date endDate) {
+    public DateRange(@Nonnull Date startDate, @Nonnull Date endDate) {
         this.startDate = startDate;
         this.endDate = endDate;
     }
 
-    public void setStartDate(Date startDate) {
+    public void setStartDate(@Nonnull Date startDate) {
         this.startDate = startDate;
     }
 
-    public void setEndDate(Date endDate) {
+    public void setEndDate(@Nonnull Date endDate) {
         this.endDate = endDate;
     }
 

+ 1 - 1
src/main/java/io/milvus/client/DeleteByRangeParam.java

@@ -15,7 +15,7 @@ public class DeleteByRangeParam {
         // Optional parameters - initialized to default values
         private long timeout = 86400;
 
-        public Builder(DateRange dateRange, String tableName) {
+        public Builder(@Nonnull DateRange dateRange, @Nonnull String tableName) {
             this.dateRange = dateRange;
             this.tableName = tableName;
         }

+ 1 - 1
src/main/java/io/milvus/client/Index.java

@@ -11,7 +11,7 @@ public class Index {
         private IndexType indexType = IndexType.FLAT;
         private int nList = 16384;
 
-        public Builder withIndexType(IndexType indexType) {
+        public Builder withIndexType(@Nonnull IndexType indexType) {
             this.indexType = indexType;
             return this;
         }

+ 1 - 1
src/main/java/io/milvus/client/IndexParam.java

@@ -16,7 +16,7 @@ public class IndexParam {
         private Index index;
         private long timeout = 86400;
 
-        public Builder(String tableName) {
+        public Builder(@Nonnull String tableName) {
             this.tableName = tableName;
         }
 

+ 2 - 2
src/main/java/io/milvus/client/InsertParam.java

@@ -19,12 +19,12 @@ public class InsertParam {
         private List<Long> vectorIds = new ArrayList<>();
         private long timeout = 86400;
 
-        public Builder(String tableName, List<List<Float>> vectors) {
+        public Builder(@Nonnull String tableName, @Nonnull List<List<Float>> vectors) {
             this.tableName = tableName;
             this.vectors = vectors;
         }
 
-        public Builder withVectorIds(List<Long> vectorIds) {
+        public Builder withVectorIds(@Nonnull List<Long> vectorIds) {
             this.vectorIds = vectorIds;
             return this;
         }

+ 14 - 3
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -26,9 +26,16 @@ public class MilvusGrpcClient implements MilvusClient {
         }
 
         try {
+            int port = Integer.parseInt(connectParam.getPort());
+            if (port < 0 || port > 0xFFFF) {
+                logSevere("Connect failed! Port {0} out of range", connectParam.getPort());
+                return new Response(Response.Status.CONNECT_FAILED);
+            }
+
             channel = ManagedChannelBuilder
-                    .forAddress(connectParam.getHost(), Integer.parseInt(connectParam.getPort()))
+                    .forAddress(connectParam.getHost(), port)
                     .usePlaintext()
+                    .maxInboundMessageSize(Integer.MAX_VALUE)
                     .build();
 
             ConnectivityState connectivityState;
@@ -46,7 +53,7 @@ public class MilvusGrpcClient implements MilvusClient {
             blockingStub = io.milvus.client.grpc.MilvusServiceGrpc.newBlockingStub(channel);
 
         } catch (Exception e) {
-            logSevere("Connect failed!", e.toString());
+            logSevere("Connect failed! {0}\n{1}", connectParam.toString(), e.toString());
             return new Response(Response.Status.CONNECT_FAILED);
         }
 
@@ -56,7 +63,11 @@ public class MilvusGrpcClient implements MilvusClient {
 
     @Override
     public boolean connected() {
-        return channel != null && !channel.isShutdown() && !channel.isTerminated();
+        if (channel == null) {
+            return false;
+        }
+        ConnectivityState connectivityState = channel.getState(false);
+        return connectivityState == ConnectivityState.READY;
     }
 
     @Override

+ 2 - 2
src/main/java/io/milvus/client/SearchParam.java

@@ -24,12 +24,12 @@ public class SearchParam {
         private long nProbe = 10;
         private long timeout = 86400;
 
-        public Builder(String tableName, List<List<Float>> queryVectors) {
+        public Builder(@Nonnull String tableName, @Nonnull List<List<Float>> queryVectors) {
             this.tableName = tableName;
             this.queryVectors = queryVectors;
         }
 
-        public Builder withDateRanges(List<DateRange> queryRanges) {
+        public Builder withDateRanges(@Nonnull List<DateRange> queryRanges) {
             this.queryRanges = queryRanges;
             return this;
         }

+ 1 - 1
src/main/java/io/milvus/client/TableParam.java

@@ -13,7 +13,7 @@ public class TableParam {
         // Optional parameters - initialized to default values
         private long timeout = 86400;
 
-        public Builder(String tableName) {
+        public Builder(@Nonnull String tableName) {
             this.tableName = tableName;
         }
 

+ 2 - 2
src/main/java/io/milvus/client/TableSchema.java

@@ -18,7 +18,7 @@ public class TableSchema {
         private long indexFileSize = 1024;
         private MetricType metricType = MetricType.L2;
 
-        public Builder(String tableName, long dimension) {
+        public Builder(@Nonnull String tableName, long dimension) {
             this.tableName = tableName;
             this.dimension = dimension;
         }
@@ -27,7 +27,7 @@ public class TableSchema {
             this.indexFileSize = indexFileSize;
             return this;
         }
-        public Builder withMetricType(MetricType metricType) {
+        public Builder withMetricType(@Nonnull MetricType metricType) {
             this.metricType = metricType;
             return this;
         }

+ 1 - 1
src/main/java/io/milvus/client/TableSchemaParam.java

@@ -13,7 +13,7 @@ public class TableSchemaParam {
         // Optional parameters - initialized to default values
         private long timeout = 86400;
 
-        public Builder(TableSchema tableSchema) {
+        public Builder(@Nonnull TableSchema tableSchema) {
             this.tableSchema = tableSchema;
         }