Browse Source

Modify ManualCompact interface (#241)

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 3 years ago
parent
commit
8a5c0d3dba

+ 44 - 12
examples/main/io/milvus/GeneralExample.java

@@ -23,6 +23,7 @@ import io.milvus.client.MilvusServiceClient;
 import io.milvus.grpc.*;
 import io.milvus.grpc.*;
 import io.milvus.param.*;
 import io.milvus.param.*;
 import io.milvus.param.collection.*;
 import io.milvus.param.collection.*;
+import io.milvus.param.control.ManualCompactionParam;
 import io.milvus.param.dml.*;
 import io.milvus.param.dml.*;
 import io.milvus.param.index.*;
 import io.milvus.param.index.*;
 import io.milvus.param.partition.*;
 import io.milvus.param.partition.*;
@@ -62,6 +63,12 @@ public class GeneralExample {
     private static final Integer SEARCH_K = 5;
     private static final Integer SEARCH_K = 5;
     private static final String SEARCH_PARAM = "{\"nprobe\":10}";
     private static final String SEARCH_PARAM = "{\"nprobe\":10}";
 
 
+    private void handleResponseStatus(R<?> r) {
+        if (r.getStatus() != R.Status.Success.getCode()) {
+            throw new RuntimeException(r.getMessage());
+        }
+    }
+
     private R<RpcStatus> createCollection() {
     private R<RpcStatus> createCollection() {
         System.out.println("========== createCollection() ==========");
         System.out.println("========== createCollection() ==========");
         FieldType fieldType1 = FieldType.newBuilder()
         FieldType fieldType1 = FieldType.newBuilder()
@@ -102,7 +109,7 @@ public class GeneralExample {
 //                .addFieldType(fieldType4)
 //                .addFieldType(fieldType4)
                 .build();
                 .build();
         R<RpcStatus> response = milvusClient.createCollection(createCollectionReq);
         R<RpcStatus> response = milvusClient.createCollection(createCollectionReq);
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -121,7 +128,7 @@ public class GeneralExample {
         R<Boolean> response = milvusClient.hasCollection(HasCollectionParam.newBuilder()
         R<Boolean> response = milvusClient.hasCollection(HasCollectionParam.newBuilder()
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .build());
                 .build());
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -131,6 +138,7 @@ public class GeneralExample {
         R<RpcStatus> response = milvusClient.loadCollection(LoadCollectionParam.newBuilder()
         R<RpcStatus> response = milvusClient.loadCollection(LoadCollectionParam.newBuilder()
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -140,6 +148,7 @@ public class GeneralExample {
         R<RpcStatus> response = milvusClient.releaseCollection(ReleaseCollectionParam.newBuilder()
         R<RpcStatus> response = milvusClient.releaseCollection(ReleaseCollectionParam.newBuilder()
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -149,6 +158,7 @@ public class GeneralExample {
         R<DescribeCollectionResponse> response = milvusClient.describeCollection(DescribeCollectionParam.newBuilder()
         R<DescribeCollectionResponse> response = milvusClient.describeCollection(DescribeCollectionParam.newBuilder()
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .build());
                 .build());
+        handleResponseStatus(response);
         DescCollResponseWrapper wrapper = new DescCollResponseWrapper(response.getData());
         DescCollResponseWrapper wrapper = new DescCollResponseWrapper(response.getData());
         System.out.println(wrapper.toString());
         System.out.println(wrapper.toString());
         return response;
         return response;
@@ -160,6 +170,7 @@ public class GeneralExample {
                 GetCollectionStatisticsParam.newBuilder()
                 GetCollectionStatisticsParam.newBuilder()
                         .withCollectionName(COLLECTION_NAME)
                         .withCollectionName(COLLECTION_NAME)
                         .build());
                         .build());
+        handleResponseStatus(response);
         GetCollStatResponseWrapper wrapper = new GetCollStatResponseWrapper(response.getData());
         GetCollStatResponseWrapper wrapper = new GetCollStatResponseWrapper(response.getData());
         System.out.println("Collection row count: " + wrapper.getRowCount());
         System.out.println("Collection row count: " + wrapper.getRowCount());
         return response;
         return response;
@@ -169,6 +180,7 @@ public class GeneralExample {
         System.out.println("========== showCollections() ==========");
         System.out.println("========== showCollections() ==========");
         R<ShowCollectionsResponse> response = milvusClient.showCollections(ShowCollectionsParam.newBuilder()
         R<ShowCollectionsResponse> response = milvusClient.showCollections(ShowCollectionsParam.newBuilder()
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -179,7 +191,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withPartitionName(partitionName)
                 .withPartitionName(partitionName)
                 .build());
                 .build());
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -190,7 +202,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withPartitionName(partitionName)
                 .withPartitionName(partitionName)
                 .build());
                 .build());
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -201,7 +213,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withPartitionName(partitionName)
                 .withPartitionName(partitionName)
                 .build());
                 .build());
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -212,7 +224,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .addPartitionName(partitionName)
                 .addPartitionName(partitionName)
                 .build());
                 .build());
-
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -222,6 +234,7 @@ public class GeneralExample {
         R<ShowPartitionsResponse> response = milvusClient.showPartitions(ShowPartitionsParam.newBuilder()
         R<ShowPartitionsResponse> response = milvusClient.showPartitions(ShowPartitionsParam.newBuilder()
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -236,6 +249,7 @@ public class GeneralExample {
                 .withExtraParam(INDEX_PARAM)
                 .withExtraParam(INDEX_PARAM)
                 .withSyncMode(Boolean.TRUE)
                 .withSyncMode(Boolean.TRUE)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -246,6 +260,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withFieldName(VECTOR_FIELD)
                 .withFieldName(VECTOR_FIELD)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -256,6 +271,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withFieldName(VECTOR_FIELD)
                 .withFieldName(VECTOR_FIELD)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -266,6 +282,7 @@ public class GeneralExample {
                 .withCollectionName(COLLECTION_NAME)
                 .withCollectionName(COLLECTION_NAME)
                 .withFieldName(VECTOR_FIELD)
                 .withFieldName(VECTOR_FIELD)
                 .build());
                 .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -276,6 +293,7 @@ public class GeneralExample {
                 GetIndexBuildProgressParam.newBuilder()
                 GetIndexBuildProgressParam.newBuilder()
                         .withCollectionName(COLLECTION_NAME)
                         .withCollectionName(COLLECTION_NAME)
                         .build());
                         .build());
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -288,6 +306,7 @@ public class GeneralExample {
                 .withExpr(expr)
                 .withExpr(expr)
                 .build();
                 .build();
         R<MutationResult> response = milvusClient.delete(build);
         R<MutationResult> response = milvusClient.delete(build);
+        handleResponseStatus(response);
         System.out.println(response.getData());
         System.out.println(response.getData());
         return response;
         return response;
     }
     }
@@ -309,9 +328,8 @@ public class GeneralExample {
                 .withParams(SEARCH_PARAM)
                 .withParams(SEARCH_PARAM)
                 .build();
                 .build();
 
 
-
         R<SearchResults> response = milvusClient.search(searchParam);
         R<SearchResults> response = milvusClient.search(searchParam);
-
+        handleResponseStatus(response);
         SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
         SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
         for (int i = 0; i < vectors.size(); ++i) {
         for (int i = 0; i < vectors.size(); ++i) {
             System.out.println("Search result of No." + i);
             System.out.println("Search result of No." + i);
@@ -343,7 +361,7 @@ public class GeneralExample {
 //
 //
 //
 //
 //        R<SearchResults> response = milvusClient.search(searchParam);
 //        R<SearchResults> response = milvusClient.search(searchParam);
-//
+//        handleResponseStatus(response);
 //        SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
 //        SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
 //        for (int i = 0; i < vectors.size(); ++i) {
 //        for (int i = 0; i < vectors.size(); ++i) {
 //            System.out.println("Search result of No." + i);
 //            System.out.println("Search result of No." + i);
@@ -372,6 +390,7 @@ public class GeneralExample {
                 .withMetricType(MetricType.L2)
                 .withMetricType(MetricType.L2)
                 .build();
                 .build();
         R<CalcDistanceResults> response = milvusClient.calcDistance(calcDistanceParam);
         R<CalcDistanceResults> response = milvusClient.calcDistance(calcDistanceParam);
+        handleResponseStatus(response);
         System.out.println(response);
         System.out.println(response);
         return response;
         return response;
     }
     }
@@ -385,6 +404,7 @@ public class GeneralExample {
                 .withOutFields(fields)
                 .withOutFields(fields)
                 .build();
                 .build();
         R<QueryResults> response = milvusClient.query(test);
         R<QueryResults> response = milvusClient.query(test);
+        handleResponseStatus(response);
         QueryResultsWrapper wrapper = new QueryResultsWrapper(response.getData());
         QueryResultsWrapper wrapper = new QueryResultsWrapper(response.getData());
         System.out.println(ID_FIELD + ":" + wrapper.getFieldWrapper(ID_FIELD).getFieldData().toString());
         System.out.println(ID_FIELD + ":" + wrapper.getFieldWrapper(ID_FIELD).getFieldData().toString());
         System.out.println(AGE_FIELD + ":" + wrapper.getFieldWrapper(AGE_FIELD).getFieldData().toString());
         System.out.println(AGE_FIELD + ":" + wrapper.getFieldWrapper(AGE_FIELD).getFieldData().toString());
@@ -392,6 +412,15 @@ public class GeneralExample {
         return response;
         return response;
     }
     }
 
 
+    private R<ManualCompactionResponse> compact() {
+        System.out.println("========== compact() ==========");
+        R<ManualCompactionResponse> response = milvusClient.manualCompaction(ManualCompactionParam.newBuilder()
+                .withCollectionName(COLLECTION_NAME)
+                .build());
+        handleResponseStatus(response);
+        return response;
+    }
+
     private R<MutationResult> insert(String partitionName, int count) {
     private R<MutationResult> insert(String partitionName, int count) {
         System.out.println("========== insert() ==========");
         System.out.println("========== insert() ==========");
         List<List<Float>> vectors = generateFloatVectors(count);
         List<List<Float>> vectors = generateFloatVectors(count);
@@ -414,7 +443,9 @@ public class GeneralExample {
                 .withFields(fields)
                 .withFields(fields)
                 .build();
                 .build();
 
 
-        return milvusClient.insert(insertParam);
+        R<MutationResult> response = milvusClient.insert(insertParam);
+        handleResponseStatus(response);
+        return response;
     }
     }
 
 
     private List<List<Float>> generateFloatVectors(int count) {
     private List<List<Float>> generateFloatVectors(int count) {
@@ -443,7 +474,6 @@ public class GeneralExample {
 //            vectors.add(vector);
 //            vectors.add(vector);
 //        }
 //        }
 //        return vectors;
 //        return vectors;
-//
 //    }
 //    }
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
@@ -486,8 +516,10 @@ public class GeneralExample {
 //        searchExpr = AGE_FIELD + " <= 30";
 //        searchExpr = AGE_FIELD + " <= 30";
 //        example.searchProfile(searchExpr);
 //        example.searchProfile(searchExpr);
         example.calDistance();
         example.calDistance();
+        example.compact();
+        example.getCollectionStatistics();
 
 
-        example.releasePartition(partitionName);
+//        example.releasePartition(partitionName); // releasing partitions after loading collection is not supported currently
         example.releaseCollection();
         example.releaseCollection();
         example.dropPartition(partitionName);
         example.dropPartition(partitionName);
         example.dropIndex();
         example.dropIndex();

+ 10 - 1
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -21,6 +21,7 @@ package io.milvus.client;
 
 
 import com.google.protobuf.ByteString;
 import com.google.protobuf.ByteString;
 import io.grpc.StatusRuntimeException;
 import io.grpc.StatusRuntimeException;
+import io.milvus.Response.DescCollResponseWrapper;
 import io.milvus.exception.ClientNotConnectedException;
 import io.milvus.exception.ClientNotConnectedException;
 import io.milvus.exception.IllegalResponseException;
 import io.milvus.exception.IllegalResponseException;
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
@@ -1771,8 +1772,16 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
         logInfo(requestParam.toString());
         logInfo(requestParam.toString());
 
 
         try {
         try {
+            R<DescribeCollectionResponse> descResp = describeCollection(DescribeCollectionParam.newBuilder()
+                    .withCollectionName(requestParam.getCollectionName())
+                    .build());
+            if (descResp.getStatus() != R.Status.Success.getCode()) {
+                logInfo("ManualCompactionRequest successfully!");
+                return R.failed(R.Status.valueOf(descResp.getStatus()), descResp.getMessage());
+            }
+
             ManualCompactionRequest manualCompactionRequest = ManualCompactionRequest.newBuilder()
             ManualCompactionRequest manualCompactionRequest = ManualCompactionRequest.newBuilder()
-                    .setCollectionID(requestParam.getCollectionID())
+                    .setCollectionID(descResp.getData().getCollectionID())
                     .build();
                     .build();
 
 
             ManualCompactionResponse response = blockingStub().manualCompaction(manualCompactionRequest);
             ManualCompactionResponse response = blockingStub().manualCompaction(manualCompactionRequest);

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

@@ -302,7 +302,7 @@ public interface MilvusClient {
     R<GetMetricsResponse> getMetrics(GetMetricsParam requestParam);
     R<GetMetricsResponse> getMetrics(GetMetricsParam requestParam);
 
 
     /**
     /**
-     * Gets the information of persistent segments, including row count, 
+     * Gets the information of persistent segments from data node, including row count,
      * persistence state(growing or flushed), etc.
      * persistence state(growing or flushed), etc.
      *
      *
      * @param requestParam {@link GetPersistentSegmentInfoParam}
      * @param requestParam {@link GetPersistentSegmentInfoParam}
@@ -311,7 +311,7 @@ public interface MilvusClient {
     R<GetPersistentSegmentInfoResponse> getPersistentSegmentInfo(GetPersistentSegmentInfoParam requestParam);
     R<GetPersistentSegmentInfoResponse> getPersistentSegmentInfo(GetPersistentSegmentInfoParam requestParam);
 
 
     /**
     /**
-     * Gets the query information of segments in a collection, including row count, 
+     * Gets the query information of segments in a collection from query node, including row count,
      * memory usage size, index name, etc.
      * memory usage size, index name, etc.
      *
      *
      * @param requestParam {@link GetQuerySegmentInfoParam}
      * @param requestParam {@link GetQuerySegmentInfoParam}

+ 12 - 8
src/main/java/io/milvus/param/control/ManualCompactionParam.java

@@ -1,6 +1,8 @@
 package io.milvus.param.control;
 package io.milvus.param.control;
 
 
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
+import io.milvus.param.ParamUtils;
+import io.milvus.param.collection.DropCollectionParam;
 import lombok.Getter;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.NonNull;
 
 
@@ -11,10 +13,10 @@ import lombok.NonNull;
  */
  */
 @Getter
 @Getter
 public class ManualCompactionParam {
 public class ManualCompactionParam {
-    private final Long collectionID;
+    private final String collectionName;
 
 
     private ManualCompactionParam(@NonNull Builder builder) {
     private ManualCompactionParam(@NonNull Builder builder) {
-        this.collectionID = builder.collectionID;
+        this.collectionName = builder.collectionName;
     }
     }
 
 
     public static Builder newBuilder() {
     public static Builder newBuilder() {
@@ -29,7 +31,7 @@ public class ManualCompactionParam {
     @Override
     @Override
     public String toString() {
     public String toString() {
         return "ManualCompactionParam{" +
         return "ManualCompactionParam{" +
-                "collectionID='" + collectionID + '\'' +
+                "collectionName='" + collectionName + '\'' +
                 '}';
                 '}';
     }
     }
 
 
@@ -37,19 +39,19 @@ public class ManualCompactionParam {
      * Builder for <code>ManualCompactionParam</code> class.
      * Builder for <code>ManualCompactionParam</code> class.
      */
      */
     public static final class Builder {
     public static final class Builder {
-        private Long collectionID;
+        private String collectionName;
 
 
         private Builder() {
         private Builder() {
         }
         }
 
 
         /**
         /**
-         * Compacts a collection.
+         * Sets the collection name. Collection name cannot be empty or null.
          *
          *
-         * @param collectionID target collection id
+         * @param collectionName collection name
          * @return <code>Builder</code>
          * @return <code>Builder</code>
          */
          */
-        public Builder withCollectionID(@NonNull Long collectionID) {
-            this.collectionID = collectionID;
+        public Builder withCollectionName(@NonNull String collectionName) {
+            this.collectionName = collectionName;
             return this;
             return this;
         }
         }
 
 
@@ -59,6 +61,8 @@ public class ManualCompactionParam {
          * @return <code>ManualCompactionParam</code>
          * @return <code>ManualCompactionParam</code>
          */
          */
         public ManualCompactionParam build() throws ParamException {
         public ManualCompactionParam build() throws ParamException {
+            ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
+
             return new ManualCompactionParam(this);
             return new ManualCompactionParam(this);
         }
         }
     }
     }

+ 1 - 1
src/test/java/io/milvus/client/MilvusServiceClientTest.java

@@ -1854,7 +1854,7 @@ class MilvusServiceClientTest {
     @Test
     @Test
     void manualCompaction() {
     void manualCompaction() {
         ManualCompactionParam param = ManualCompactionParam.newBuilder()
         ManualCompactionParam param = ManualCompactionParam.newBuilder()
-                .withCollectionID(1L)
+                .withCollectionName("collection1")
                 .build();
                 .build();
 
 
         testFuncByName("manualCompaction", param);
         testFuncByName("manualCompaction", param);