|
19 | 19 |
|
20 | 20 | package io.milvus.v2.service.index; |
21 | 21 |
|
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; |
24 | 33 | import io.milvus.param.Constant; |
25 | 34 | import io.milvus.param.ParamUtils; |
26 | 35 | import io.milvus.v2.common.IndexBuildState; |
27 | 36 | import io.milvus.v2.common.IndexParam; |
28 | 37 | import io.milvus.v2.exception.ErrorCode; |
29 | 38 | import io.milvus.v2.exception.MilvusClientException; |
30 | 39 | import 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; |
33 | 47 | import org.apache.commons.collections4.CollectionUtils; |
34 | 48 | import org.apache.commons.lang3.StringUtils; |
35 | 49 |
|
@@ -152,13 +166,7 @@ public DescribeIndexResp describeIndex(MilvusServiceGrpc.MilvusServiceBlockingSt |
152 | 166 |
|
153 | 167 | DescribeIndexResponse response = blockingStub.describeIndex(builder.build()); |
154 | 168 | rpcUtils.handleResponse(title, response.getStatus()); |
155 | | - 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 | | - } |
161 | | - return convertUtils.convertToDescribeIndexResp(indexs); |
| 169 | + return convertUtils.convertToDescribeIndexResp(response.getIndexDescriptionsList()); |
162 | 170 | } |
163 | 171 |
|
164 | 172 | public List<String> listIndexes(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, ListIndexesReq request) { |
@@ -207,28 +215,25 @@ private void WaitForIndexComplete(MilvusServiceGrpc.MilvusServiceBlockingStub bl |
207 | 215 | } |
208 | 216 | DescribeIndexResp response = describeIndex(blockingStub, describeIndexReq); |
209 | 217 | 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) { |
| 218 | + if (CollectionUtils.isEmpty(indices)) { |
223 | 219 | String msg = String.format("Failed to describe the index '%s' of field '%s' from serv side", fieldName, indexName); |
224 | 220 | throw new MilvusClientException(ErrorCode.SERVER_ERROR, msg); |
225 | 221 | } |
226 | 222 |
|
227 | | - if (desc.getIndexState() == IndexBuildState.Finished) { |
| 223 | + boolean allIndexBuildCompleted = true; |
| 224 | + for (DescribeIndexResp.IndexDesc index : indices) { |
| 225 | + if (index.getIndexState() == IndexBuildState.Failed) { |
| 226 | + String msg = "Index is failed, reason: " + index.getIndexFailedReason(); |
| 227 | + throw new MilvusClientException(ErrorCode.SERVER_ERROR, msg); |
| 228 | + } |
| 229 | + |
| 230 | + if (index.getIndexState() != IndexBuildState.Finished) { |
| 231 | + allIndexBuildCompleted = false; |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + if (allIndexBuildCompleted) { |
228 | 236 | 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); |
232 | 237 | } |
233 | 238 |
|
234 | 239 | // Check if timeout is exceeded |
|
0 commit comments