1919
2020package io .milvus .v2 .service .index ;
2121
22- import com .google .gson .JsonObject ;
23- import io .milvus .grpc .*;
22+ import io .milvus .grpc .AllocTimestampRequest ;
23+ import io .milvus .grpc .AllocTimestampResponse ;
24+ import io .milvus .grpc .AlterIndexRequest ;
25+ import io .milvus .grpc .CreateIndexRequest ;
26+ import io .milvus .grpc .DescribeIndexRequest ;
27+ import io .milvus .grpc .DescribeIndexResponse ;
28+ import io .milvus .grpc .DropIndexRequest ;
29+ import io .milvus .grpc .IndexDescription ;
30+ import io .milvus .grpc .KeyValuePair ;
31+ import io .milvus .grpc .MilvusServiceGrpc ;
32+ import io .milvus .grpc .Status ;
2433import io .milvus .param .Constant ;
2534import io .milvus .param .ParamUtils ;
2635import io .milvus .v2 .common .IndexBuildState ;
2736import io .milvus .v2 .common .IndexParam ;
2837import io .milvus .v2 .exception .ErrorCode ;
2938import io .milvus .v2 .exception .MilvusClientException ;
3039import io .milvus .v2 .service .BaseService ;
31- import io .milvus .v2 .service .index .request .*;
32- import io .milvus .v2 .service .index .response .*;
40+ import io .milvus .v2 .service .index .request .AlterIndexPropertiesReq ;
41+ import io .milvus .v2 .service .index .request .CreateIndexReq ;
42+ import io .milvus .v2 .service .index .request .DescribeIndexReq ;
43+ import io .milvus .v2 .service .index .request .DropIndexPropertiesReq ;
44+ import io .milvus .v2 .service .index .request .DropIndexReq ;
45+ import io .milvus .v2 .service .index .request .ListIndexesReq ;
46+ import io .milvus .v2 .service .index .response .DescribeIndexResp ;
3347import org .apache .commons .collections4 .CollectionUtils ;
3448import org .apache .commons .lang3 .StringUtils ;
3549
@@ -46,13 +60,16 @@ public Void createIndex(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub
4660 request .getCollectionName (), indexParam .getFieldName ());
4761 CreateIndexRequest .Builder builder = CreateIndexRequest .newBuilder ();
4862 builder .setCollectionName (request .getCollectionName ())
49- .setIndexName (indexParam .getIndexName ())
5063 .setFieldName (indexParam .getFieldName ())
5164 .addExtraParams (KeyValuePair .newBuilder ()
5265 .setKey (Constant .INDEX_TYPE )
5366 .setValue (indexParam .getIndexType ().getName ())
5467 .build ());
5568
69+ if (StringUtils .isNotEmpty (indexParam .getIndexName ())) {
70+ builder .setIndexName (indexParam .getIndexName ());
71+ }
72+
5673 if (StringUtils .isNotEmpty (request .getDatabaseName ())) {
5774 builder .setDbName (request .getDatabaseName ());
5875 }
@@ -153,11 +170,6 @@ public DescribeIndexResp describeIndex(MilvusServiceGrpc.MilvusServiceBlockingSt
153170 DescribeIndexResponse response = blockingStub .describeIndex (builder .build ());
154171 rpcUtils .handleResponse (title , response .getStatus ());
155172 List <IndexDescription > indexs = response .getIndexDescriptionsList ().stream ().filter (index -> index .getIndexName ().equals (request .getIndexName ()) || index .getFieldName ().equals (request .getFieldName ())).collect (Collectors .toList ());
156- if (indexs .isEmpty ()) {
157- throw new MilvusClientException (ErrorCode .SERVER_ERROR , "Index not found" );
158- } else if (indexs .size () > 1 ) {
159- throw new MilvusClientException (ErrorCode .SERVER_ERROR , "More than one index found" );
160- }
161173 return convertUtils .convertToDescribeIndexResp (indexs );
162174 }
163175
@@ -207,28 +219,25 @@ private void WaitForIndexComplete(MilvusServiceGrpc.MilvusServiceBlockingStub bl
207219 }
208220 DescribeIndexResp response = describeIndex (blockingStub , describeIndexReq );
209221 List <DescribeIndexResp .IndexDesc > indices = response .getIndexDescriptions ();
210- DescribeIndexResp .IndexDesc desc = null ;
211- if (indices .size () == 1 ) {
212- desc = indices .get (0 );
213- } else {
214- for (DescribeIndexResp .IndexDesc index : indices ) {
215- if (fieldName .equals (index .getFieldName ())) {
216- desc = index ;
217- break ;
218- }
219- }
220- }
221-
222- if (desc == null ) {
222+ if (CollectionUtils .isEmpty (indices )) {
223223 String msg = String .format ("Failed to describe the index '%s' of field '%s' from serv side" , fieldName , indexName );
224224 throw new MilvusClientException (ErrorCode .SERVER_ERROR , msg );
225225 }
226226
227- if (desc .getIndexState () == IndexBuildState .Finished ) {
227+ boolean allIndexBuildCompleted = true ;
228+ for (DescribeIndexResp .IndexDesc index : indices ) {
229+ if (index .getIndexState () == IndexBuildState .Failed ) {
230+ String msg = "Index is failed, reason: " + index .getIndexFailedReason ();
231+ throw new MilvusClientException (ErrorCode .SERVER_ERROR , msg );
232+ }
233+
234+ if (index .getIndexState () != IndexBuildState .Finished ) {
235+ allIndexBuildCompleted = false ;
236+ }
237+ }
238+
239+ if (allIndexBuildCompleted ) {
228240 return ;
229- } else if (desc .getIndexState () == IndexBuildState .Failed ) {
230- String msg = "Index is failed, reason: " + desc .getIndexFailedReason ();
231- throw new MilvusClientException (ErrorCode .SERVER_ERROR , msg );
232241 }
233242
234243 // Check if timeout is exceeded
0 commit comments