Browse Source

Simplify `dropCollection`

jianghua 4 years ago
parent
commit
a9af50d9c8

+ 1 - 3
src/main/java/io/milvus/client/MilvusClient.java

@@ -321,10 +321,8 @@ public interface MilvusClient {
    * @param collectionName The collection to drop index.
    * @param fieldName Name of the field to drop index for. If this is set to empty string,
    *                  index of all fields in the collection will be dropped.
-   * @return <code>Response</code>
-   * @see Response
    */
-  Response dropIndex(String collectionName, String fieldName);
+  void dropIndex(String collectionName, String fieldName);
 
   /**
    * Shows collection information. A collection consists of one or multiple partitions (including

+ 9 - 29
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -409,35 +409,15 @@ abstract class AbstractMilvusGrpcClient implements MilvusClient {
   }
 
   @Override
-  public Response dropIndex(String collectionName, String fieldName) {
-
-    if (!maybeAvailable()) {
-      logWarning("You are not connected to Milvus server");
-      return new Response(Response.Status.CLIENT_NOT_CONNECTED);
-    }
-
-    IndexParam request =
-        IndexParam.newBuilder()
-            .setCollectionName(collectionName)
-            .setFieldName(fieldName)
-            .build();
-    Status response;
-
-    try {
-      response = blockingStub().dropIndex(request);
-
-      if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Dropped index for collection `{}` successfully!", collectionName);
-        return new Response(Response.Status.SUCCESS);
-      } else {
-        logError("Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
-        return new Response(
-            Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
-      }
-    } catch (StatusRuntimeException e) {
-      logError("dropIndex RPC failed:\n{}", e.getStatus().toString());
-      return new Response(Response.Status.RPC_ERROR, e.toString());
-    }
+  public void dropIndex(String collectionName, String fieldName) {
+    translateExceptions(() -> {
+      IndexParam request = IndexParam.newBuilder()
+          .setCollectionName(collectionName)
+          .setFieldName(fieldName)
+          .build();
+      Status response = blockingStub().dropIndex(request);
+      checkResponseStatus(response);
+    });
   }
 
   @Override

+ 2 - 4
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -437,8 +437,7 @@ class MilvusClientTest {
     client.createIndex(index);
 
     // also test drop index here
-    Response dropIndexResponse = client.dropIndex(randomCollectionName, "float_vec");
-    assertTrue(dropIndexResponse.ok());
+    client.dropIndex(randomCollectionName, "float_vec");
   }
 
   @org.junit.jupiter.api.Test
@@ -488,8 +487,7 @@ class MilvusClientTest {
     client.createIndex(index);
 
     // also test drop index here
-    Response dropIndexResponse = client.dropIndex(binaryCollectionName, "binary_vec");
-    assertTrue(dropIndexResponse.ok());
+    client.dropIndex(binaryCollectionName, "binary_vec");
 
     client.dropCollection(binaryCollectionName);
   }