|
@@ -24,10 +24,16 @@ import com.google.common.util.concurrent.Futures;
|
|
import com.google.common.util.concurrent.ListenableFuture;
|
|
import com.google.common.util.concurrent.ListenableFuture;
|
|
import com.google.common.util.concurrent.MoreExecutors;
|
|
import com.google.common.util.concurrent.MoreExecutors;
|
|
import com.google.protobuf.ByteString;
|
|
import com.google.protobuf.ByteString;
|
|
-import io.grpc.ConnectivityState;
|
|
|
|
|
|
+import io.grpc.CallOptions;
|
|
|
|
+import io.grpc.Channel;
|
|
|
|
+import io.grpc.ClientCall;
|
|
|
|
+import io.grpc.ClientInterceptor;
|
|
import io.grpc.ManagedChannel;
|
|
import io.grpc.ManagedChannel;
|
|
import io.grpc.ManagedChannelBuilder;
|
|
import io.grpc.ManagedChannelBuilder;
|
|
|
|
+import io.grpc.MethodDescriptor;
|
|
import io.grpc.StatusRuntimeException;
|
|
import io.grpc.StatusRuntimeException;
|
|
|
|
+import io.milvus.client.exception.InitializationException;
|
|
|
|
+import io.milvus.client.exception.UnsupportedServerVersion;
|
|
import io.milvus.grpc.*;
|
|
import io.milvus.grpc.*;
|
|
import java.nio.Buffer;
|
|
import java.nio.Buffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
@@ -40,106 +46,153 @@ import javax.annotation.Nonnull;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-/** Actual implementation of interface <code>MilvusClient</code> */
|
|
|
|
-public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
+public class MilvusGrpcClient extends AbstractMilvusGrpcClient {
|
|
|
|
+ private static String SUPPORTED_SERVER_VERSION = "0.10";
|
|
|
|
+ private final ManagedChannel channel;
|
|
|
|
+ private final MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub;
|
|
|
|
+ private final MilvusServiceGrpc.MilvusServiceFutureStub futureStub;
|
|
|
|
+
|
|
|
|
+ public MilvusGrpcClient(ConnectParam connectParam) {
|
|
|
|
+ channel = ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort())
|
|
|
|
+ .usePlaintext()
|
|
|
|
+ .maxInboundMessageSize(Integer.MAX_VALUE)
|
|
|
|
+ .keepAliveTime(connectParam.getKeepAliveTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
+ .keepAliveTimeout(connectParam.getKeepAliveTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
+ .keepAliveWithoutCalls(connectParam.isKeepAliveWithoutCalls())
|
|
|
|
+ .idleTimeout(connectParam.getIdleTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ blockingStub = MilvusServiceGrpc.newBlockingStub(channel);
|
|
|
|
+ futureStub = MilvusServiceGrpc.newFutureStub(channel);
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(MilvusGrpcClient.class);
|
|
|
|
- private final String extraParamKey = "params";
|
|
|
|
- private ManagedChannel channel = null;
|
|
|
|
- private MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub = null;
|
|
|
|
- private MilvusServiceGrpc.MilvusServiceFutureStub futureStub = null;
|
|
|
|
|
|
+ try {
|
|
|
|
+ Response response = getServerVersion();
|
|
|
|
+ if (response.ok()) {
|
|
|
|
+ String serverVersion = getServerVersion().getMessage();
|
|
|
|
+ if (!serverVersion.matches("^" + SUPPORTED_SERVER_VERSION + "(\\..*)?$")) {
|
|
|
|
+ throw new UnsupportedServerVersion(connectParam.getHost(), SUPPORTED_SERVER_VERSION, serverVersion);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new InitializationException(connectParam.getHost(), response.getMessage());
|
|
|
|
+ }
|
|
|
|
+ } catch (Throwable t) {
|
|
|
|
+ channel.shutdownNow();
|
|
|
|
+ throw t;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- ////////////////////// Constructor //////////////////////
|
|
|
|
- public MilvusGrpcClient() {}
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub() {
|
|
|
|
+ return blockingStub;
|
|
|
|
+ }
|
|
|
|
|
|
- /////////////////////// Client Calls///////////////////////
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected MilvusServiceGrpc.MilvusServiceFutureStub futureStub() {
|
|
|
|
+ return futureStub;
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Response connect(ConnectParam connectParam) throws ConnectFailedException {
|
|
|
|
- if (channel != null && !(channel.isShutdown() || channel.isTerminated())) {
|
|
|
|
- logWarning("Channel is not shutdown or terminated");
|
|
|
|
- throw new ConnectFailedException("Channel is not shutdown or terminated");
|
|
|
|
|
|
+ protected boolean maybeAvailable() {
|
|
|
|
+ switch (channel.getState(false)) {
|
|
|
|
+ case IDLE:
|
|
|
|
+ case CONNECTING:
|
|
|
|
+ case READY:
|
|
|
|
+ return true;
|
|
|
|
+ default:
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void close(long maxWaitSeconds) {
|
|
|
|
+ channel.shutdown();
|
|
|
|
+ long now = System.nanoTime();
|
|
|
|
+ long deadline = now + TimeUnit.SECONDS.toNanos(maxWaitSeconds);
|
|
|
|
+ boolean interrupted = false;
|
|
try {
|
|
try {
|
|
-
|
|
|
|
- channel =
|
|
|
|
- ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort())
|
|
|
|
- .usePlaintext()
|
|
|
|
- .maxInboundMessageSize(Integer.MAX_VALUE)
|
|
|
|
- .keepAliveTime(
|
|
|
|
- connectParam.getKeepAliveTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
- .keepAliveTimeout(
|
|
|
|
- connectParam.getKeepAliveTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
- .keepAliveWithoutCalls(connectParam.isKeepAliveWithoutCalls())
|
|
|
|
- .idleTimeout(connectParam.getIdleTimeout(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS)
|
|
|
|
- .build();
|
|
|
|
-
|
|
|
|
- channel.getState(true);
|
|
|
|
-
|
|
|
|
- long timeout = connectParam.getConnectTimeout(TimeUnit.MILLISECONDS);
|
|
|
|
- logInfo("Trying to connect...Timeout in {} ms", timeout);
|
|
|
|
-
|
|
|
|
- final long checkFrequency = 100; // ms
|
|
|
|
- while (channel.getState(false) != ConnectivityState.READY) {
|
|
|
|
- if (timeout <= 0) {
|
|
|
|
- logError("Connect timeout!");
|
|
|
|
- throw new ConnectFailedException("Connect timeout");
|
|
|
|
|
|
+ while (now < deadline && !channel.isTerminated()) {
|
|
|
|
+ try {
|
|
|
|
+ channel.awaitTermination(deadline - now, TimeUnit.NANOSECONDS);
|
|
|
|
+ } catch (InterruptedException ex) {
|
|
|
|
+ interrupted = true;
|
|
}
|
|
}
|
|
- TimeUnit.MILLISECONDS.sleep(checkFrequency);
|
|
|
|
- timeout -= checkFrequency;
|
|
|
|
}
|
|
}
|
|
|
|
+ if (!channel.isTerminated()) {
|
|
|
|
+ channel.shutdownNow();
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ if (interrupted) {
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- blockingStub = MilvusServiceGrpc.newBlockingStub(channel);
|
|
|
|
- futureStub = MilvusServiceGrpc.newFutureStub(channel);
|
|
|
|
|
|
+ public MilvusClient withTimeout(long timeout, TimeUnit timeoutUnit) {
|
|
|
|
+ final long timeoutMillis = timeoutUnit.toMillis(timeout);
|
|
|
|
+ final TimeoutInterceptor timeoutInterceptor = new TimeoutInterceptor(timeoutMillis);
|
|
|
|
+ final MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub =
|
|
|
|
+ this.blockingStub.withInterceptors(timeoutInterceptor);
|
|
|
|
+ final MilvusServiceGrpc.MilvusServiceFutureStub futureStub =
|
|
|
|
+ this.futureStub.withInterceptors(timeoutInterceptor);
|
|
|
|
|
|
- // check server version
|
|
|
|
- String serverVersion = getServerVersion().getMessage();
|
|
|
|
- if (!serverVersion.contains("0.10.")) {
|
|
|
|
- logError(
|
|
|
|
- "Connect failed! Server version {} does not match SDK version 0.8.4", serverVersion);
|
|
|
|
- throw new ConnectFailedException("Failed to connect to Milvus server.");
|
|
|
|
|
|
+ return new AbstractMilvusGrpcClient() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub() {
|
|
|
|
+ return blockingStub;
|
|
}
|
|
}
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- if (!(e instanceof ConnectFailedException)) {
|
|
|
|
- logError("Connect failed! {}", e.toString());
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected MilvusServiceGrpc.MilvusServiceFutureStub futureStub() {
|
|
|
|
+ return futureStub;
|
|
}
|
|
}
|
|
- throw new ConnectFailedException("Exception occurred: " + e.toString());
|
|
|
|
- }
|
|
|
|
|
|
|
|
- logInfo(
|
|
|
|
- "Connection established successfully to host={}, port={}",
|
|
|
|
- connectParam.getHost(),
|
|
|
|
- String.valueOf(connectParam.getPort()));
|
|
|
|
- return new Response(Response.Status.SUCCESS);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected boolean maybeAvailable() {
|
|
|
|
+ return MilvusGrpcClient.this.maybeAvailable();
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public Response disconnect() throws InterruptedException {
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
- logWarning("You are not connected to Milvus server");
|
|
|
|
- return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
|
|
- } else {
|
|
|
|
- try {
|
|
|
|
- if (channel.shutdown().awaitTermination(60, TimeUnit.SECONDS)) {
|
|
|
|
- logInfo("Channel terminated");
|
|
|
|
- } else {
|
|
|
|
- logError("Encountered error when terminating channel");
|
|
|
|
- return new Response(Response.Status.RPC_ERROR);
|
|
|
|
- }
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- logError("Exception thrown when terminating channel: {}", e.toString());
|
|
|
|
- throw e;
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void close(long maxWaitSeconds) {
|
|
|
|
+ MilvusGrpcClient.this.close(maxWaitSeconds);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MilvusClient withTimeout(long timeout, TimeUnit timeoutUnit) {
|
|
|
|
+ return MilvusGrpcClient.this.withTimeout(timeout, timeoutUnit);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static class TimeoutInterceptor implements ClientInterceptor {
|
|
|
|
+ private long timeoutMillis;
|
|
|
|
+
|
|
|
|
+ TimeoutInterceptor(long timeoutMillis) {
|
|
|
|
+ this.timeoutMillis = timeoutMillis;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
|
|
|
|
+ MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
|
|
|
|
+ return next.newCall(method, callOptions.withDeadlineAfter(timeoutMillis, TimeUnit.MILLISECONDS));
|
|
}
|
|
}
|
|
- return new Response(Response.Status.SUCCESS);
|
|
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+abstract class AbstractMilvusGrpcClient implements MilvusClient {
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(AbstractMilvusGrpcClient.class);
|
|
|
|
+
|
|
|
|
+ private final String extraParamKey = "params";
|
|
|
|
+
|
|
|
|
+ protected abstract MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub();
|
|
|
|
+
|
|
|
|
+ protected abstract MilvusServiceGrpc.MilvusServiceFutureStub futureStub();
|
|
|
|
+
|
|
|
|
+ protected abstract boolean maybeAvailable();
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Response createCollection(@Nonnull CollectionMapping collectionMapping) {
|
|
public Response createCollection(@Nonnull CollectionMapping collectionMapping) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -155,7 +208,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.createCollection(request);
|
|
|
|
|
|
+ response = blockingStub().createCollection(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Created collection successfully!\n{}", collectionMapping.toString());
|
|
logInfo("Created collection successfully!\n{}", collectionMapping.toString());
|
|
@@ -179,7 +232,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public HasCollectionResponse hasCollection(@Nonnull String collectionName) {
|
|
public HasCollectionResponse hasCollection(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new HasCollectionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
|
|
return new HasCollectionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
|
|
}
|
|
}
|
|
@@ -188,7 +241,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
BoolReply response;
|
|
BoolReply response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.hasCollection(request);
|
|
|
|
|
|
+ response = blockingStub().hasCollection(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("hasCollection `{}` = {}", collectionName, response.getBoolReply());
|
|
logInfo("hasCollection `{}` = {}", collectionName, response.getBoolReply());
|
|
@@ -212,7 +265,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response dropCollection(@Nonnull String collectionName) {
|
|
public Response dropCollection(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -221,7 +274,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.dropCollection(request);
|
|
|
|
|
|
+ response = blockingStub().dropCollection(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Dropped collection `{}` successfully!", collectionName);
|
|
logInfo("Dropped collection `{}` successfully!", collectionName);
|
|
@@ -240,7 +293,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response createIndex(@Nonnull Index index) {
|
|
public Response createIndex(@Nonnull Index index) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -257,7 +310,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.createIndex(request);
|
|
|
|
|
|
+ response = blockingStub().createIndex(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Created index successfully!\n{}", index.toString());
|
|
logInfo("Created index successfully!\n{}", index.toString());
|
|
@@ -276,7 +329,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListenableFuture<Response> createIndexAsync(@Nonnull Index index) {
|
|
public ListenableFuture<Response> createIndexAsync(@Nonnull Index index) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
}
|
|
}
|
|
@@ -292,7 +345,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
ListenableFuture<Status> response;
|
|
ListenableFuture<Status> response;
|
|
|
|
|
|
- response = futureStub.createIndex(request);
|
|
|
|
|
|
+ response = futureStub().createIndex(request);
|
|
|
|
|
|
Futures.addCallback(
|
|
Futures.addCallback(
|
|
response,
|
|
response,
|
|
@@ -320,7 +373,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response createPartition(String collectionName, String tag) {
|
|
public Response createPartition(String collectionName, String tag) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -331,7 +384,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.createPartition(request);
|
|
|
|
|
|
+ response = blockingStub().createPartition(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Created partition `{}` in collection `{}` successfully!", tag, collectionName);
|
|
logInfo("Created partition `{}` in collection `{}` successfully!", tag, collectionName);
|
|
@@ -354,7 +407,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public HasPartitionResponse hasPartition(String collectionName, String tag) {
|
|
public HasPartitionResponse hasPartition(String collectionName, String tag) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new HasPartitionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
|
|
return new HasPartitionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
|
|
}
|
|
}
|
|
@@ -364,7 +417,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
BoolReply response;
|
|
BoolReply response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.hasPartition(request);
|
|
|
|
|
|
+ response = blockingStub().hasPartition(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
@@ -395,7 +448,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListPartitionsResponse listPartitions(String collectionName) {
|
|
public ListPartitionsResponse listPartitions(String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new ListPartitionsResponse(
|
|
return new ListPartitionsResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
@@ -405,7 +458,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
PartitionList response;
|
|
PartitionList response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.showPartitions(request);
|
|
|
|
|
|
+ response = blockingStub().showPartitions(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
@@ -432,7 +485,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response dropPartition(String collectionName, String tag) {
|
|
public Response dropPartition(String collectionName, String tag) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -442,7 +495,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.dropPartition(request);
|
|
|
|
|
|
+ response = blockingStub().dropPartition(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Dropped partition `{}` in collection `{}` successfully!", tag, collectionName);
|
|
logInfo("Dropped partition `{}` in collection `{}` successfully!", tag, collectionName);
|
|
@@ -465,7 +518,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public InsertResponse insert(@Nonnull InsertParam insertParam) {
|
|
public InsertResponse insert(@Nonnull InsertParam insertParam) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new InsertResponse(
|
|
return new InsertResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
@@ -484,7 +537,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
VectorIds response;
|
|
VectorIds response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.insert(request);
|
|
|
|
|
|
+ response = blockingStub().insert(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
@@ -511,7 +564,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListenableFuture<InsertResponse> insertAsync(@Nonnull InsertParam insertParam) {
|
|
public ListenableFuture<InsertResponse> insertAsync(@Nonnull InsertParam insertParam) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return Futures.immediateFuture(
|
|
return Futures.immediateFuture(
|
|
new InsertResponse(
|
|
new InsertResponse(
|
|
@@ -531,7 +584,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
ListenableFuture<VectorIds> response;
|
|
ListenableFuture<VectorIds> response;
|
|
|
|
|
|
- response = futureStub.insert(request);
|
|
|
|
|
|
+ response = futureStub().insert(request);
|
|
|
|
|
|
Futures.addCallback(
|
|
Futures.addCallback(
|
|
response,
|
|
response,
|
|
@@ -575,7 +628,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public SearchResponse search(@Nonnull SearchParam searchParam) {
|
|
public SearchResponse search(@Nonnull SearchParam searchParam) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
SearchResponse searchResponse = new SearchResponse();
|
|
SearchResponse searchResponse = new SearchResponse();
|
|
searchResponse.setResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
searchResponse.setResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
@@ -603,7 +656,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
TopKQueryResult response;
|
|
TopKQueryResult response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.search(request);
|
|
|
|
|
|
+ response = blockingStub().search(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
SearchResponse searchResponse = buildSearchResponse(response);
|
|
SearchResponse searchResponse = buildSearchResponse(response);
|
|
@@ -632,7 +685,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListenableFuture<SearchResponse> searchAsync(@Nonnull SearchParam searchParam) {
|
|
public ListenableFuture<SearchResponse> searchAsync(@Nonnull SearchParam searchParam) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
SearchResponse searchResponse = new SearchResponse();
|
|
SearchResponse searchResponse = new SearchResponse();
|
|
searchResponse.setResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
searchResponse.setResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
@@ -659,7 +712,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
ListenableFuture<TopKQueryResult> response;
|
|
ListenableFuture<TopKQueryResult> response;
|
|
|
|
|
|
- response = futureStub.search(request);
|
|
|
|
|
|
+ response = futureStub().search(request);
|
|
|
|
|
|
Futures.addCallback(
|
|
Futures.addCallback(
|
|
response,
|
|
response,
|
|
@@ -704,7 +757,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public GetCollectionInfoResponse getCollectionInfo(@Nonnull String collectionName) {
|
|
public GetCollectionInfoResponse getCollectionInfo(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new GetCollectionInfoResponse(
|
|
return new GetCollectionInfoResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
@@ -714,7 +767,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
CollectionSchema response;
|
|
CollectionSchema response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.describeCollection(request);
|
|
|
|
|
|
+ response = blockingStub().describeCollection(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
CollectionMapping collectionMapping =
|
|
CollectionMapping collectionMapping =
|
|
@@ -746,7 +799,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListCollectionsResponse listCollections() {
|
|
public ListCollectionsResponse listCollections() {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new ListCollectionsResponse(
|
|
return new ListCollectionsResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
@@ -756,7 +809,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
CollectionNameList response;
|
|
CollectionNameList response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.showCollections(request);
|
|
|
|
|
|
+ response = blockingStub().showCollections(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
List<String> collectionNames = response.getCollectionNamesList();
|
|
List<String> collectionNames = response.getCollectionNamesList();
|
|
@@ -780,7 +833,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public CountEntitiesResponse countEntities(@Nonnull String collectionName) {
|
|
public CountEntitiesResponse countEntities(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new CountEntitiesResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
|
|
return new CountEntitiesResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
|
|
}
|
|
}
|
|
@@ -789,7 +842,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
CollectionRowCount response;
|
|
CollectionRowCount response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.countCollection(request);
|
|
|
|
|
|
+ response = blockingStub().countCollection(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
long collectionRowCount = response.getCollectionRowCount();
|
|
long collectionRowCount = response.getCollectionRowCount();
|
|
@@ -824,7 +877,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
public Response command(@Nonnull String command) {
|
|
public Response command(@Nonnull String command) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -833,7 +886,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
StringReply response;
|
|
StringReply response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.cmd(request);
|
|
|
|
|
|
+ response = blockingStub().cmd(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Command `{}`: {}", command, response.getStringReply());
|
|
logInfo("Command `{}`: {}", command, response.getStringReply());
|
|
@@ -853,7 +906,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response loadCollection(@Nonnull String collectionName) {
|
|
public Response loadCollection(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -862,7 +915,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.preloadCollection(request);
|
|
|
|
|
|
+ response = blockingStub().preloadCollection(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Loaded collection `{}` successfully!", collectionName);
|
|
logInfo("Loaded collection `{}` successfully!", collectionName);
|
|
@@ -881,7 +934,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public GetIndexInfoResponse getIndexInfo(@Nonnull String collectionName) {
|
|
public GetIndexInfoResponse getIndexInfo(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new GetIndexInfoResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
return new GetIndexInfoResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
|
|
}
|
|
}
|
|
@@ -890,7 +943,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
IndexParam response;
|
|
IndexParam response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.describeIndex(request);
|
|
|
|
|
|
+ response = blockingStub().describeIndex(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
String extraParam = "";
|
|
String extraParam = "";
|
|
@@ -927,7 +980,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public Response dropIndex(@Nonnull String collectionName) {
|
|
public Response dropIndex(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -936,7 +989,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.dropIndex(request);
|
|
|
|
|
|
+ response = blockingStub().dropIndex(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Dropped index for collection `{}` successfully!", collectionName);
|
|
logInfo("Dropped index for collection `{}` successfully!", collectionName);
|
|
@@ -954,7 +1007,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Response getCollectionStats(String collectionName) {
|
|
public Response getCollectionStats(String collectionName) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -963,7 +1016,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
io.milvus.grpc.CollectionInfo response;
|
|
io.milvus.grpc.CollectionInfo response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.showCollectionInfo(request);
|
|
|
|
|
|
+ response = blockingStub().showCollectionInfo(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("getCollectionStats for `{}` returned successfully!", collectionName);
|
|
logInfo("getCollectionStats for `{}` returned successfully!", collectionName);
|
|
@@ -985,7 +1038,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public GetEntityByIDResponse getEntityByID(String collectionName, List<Long> ids) {
|
|
public GetEntityByIDResponse getEntityByID(String collectionName, List<Long> ids) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new GetEntityByIDResponse(
|
|
return new GetEntityByIDResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList(), null);
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList(), null);
|
|
@@ -996,7 +1049,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
VectorsData response;
|
|
VectorsData response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.getVectorsByID(request);
|
|
|
|
|
|
+ response = blockingStub().getVectorsByID(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
|
|
|
|
@@ -1032,7 +1085,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ListIDInSegmentResponse listIDInSegment(String collectionName, String segmentName) {
|
|
public ListIDInSegmentResponse listIDInSegment(String collectionName, String segmentName) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new ListIDInSegmentResponse(
|
|
return new ListIDInSegmentResponse(
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
new Response(Response.Status.CLIENT_NOT_CONNECTED), Collections.emptyList());
|
|
@@ -1046,7 +1099,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
VectorIds response;
|
|
VectorIds response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.getVectorIDs(request);
|
|
|
|
|
|
+ response = blockingStub().getVectorIDs(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
|
|
|
|
@@ -1077,7 +1130,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Response deleteEntityByID(String collectionName, List<Long> ids) {
|
|
public Response deleteEntityByID(String collectionName, List<Long> ids) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -1087,7 +1140,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.deleteByID(request);
|
|
|
|
|
|
+ response = blockingStub().deleteByID(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("deleteEntityByID in collection `{}` completed successfully!", collectionName);
|
|
logInfo("deleteEntityByID in collection `{}` completed successfully!", collectionName);
|
|
@@ -1106,7 +1159,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Response flush(List<String> collectionNames) {
|
|
public Response flush(List<String> collectionNames) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -1115,7 +1168,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.flush(request);
|
|
|
|
|
|
+ response = blockingStub().flush(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Flushed collection {} successfully!", collectionNames);
|
|
logInfo("Flushed collection {} successfully!", collectionNames);
|
|
@@ -1134,7 +1187,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListenableFuture<Response> flushAsync(@Nonnull List<String> collectionNames) {
|
|
public ListenableFuture<Response> flushAsync(@Nonnull List<String> collectionNames) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
}
|
|
}
|
|
@@ -1143,7 +1196,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
ListenableFuture<Status> response;
|
|
ListenableFuture<Status> response;
|
|
|
|
|
|
- response = futureStub.flush(request);
|
|
|
|
|
|
+ response = futureStub().flush(request);
|
|
|
|
|
|
Futures.addCallback(
|
|
Futures.addCallback(
|
|
response,
|
|
response,
|
|
@@ -1192,7 +1245,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Response compact(String collectionName) {
|
|
public Response compact(String collectionName) {
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
return new Response(Response.Status.CLIENT_NOT_CONNECTED);
|
|
}
|
|
}
|
|
@@ -1201,7 +1254,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Status response;
|
|
Status response;
|
|
|
|
|
|
try {
|
|
try {
|
|
- response = blockingStub.compact(request);
|
|
|
|
|
|
+ response = blockingStub().compact(request);
|
|
|
|
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo("Compacted collection `{}` successfully!", collectionName);
|
|
logInfo("Compacted collection `{}` successfully!", collectionName);
|
|
@@ -1220,7 +1273,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
@Override
|
|
@Override
|
|
public ListenableFuture<Response> compactAsync(@Nonnull String collectionName) {
|
|
public ListenableFuture<Response> compactAsync(@Nonnull String collectionName) {
|
|
|
|
|
|
- if (!channelIsReadyOrIdle()) {
|
|
|
|
|
|
+ if (!maybeAvailable()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
return Futures.immediateFuture(new Response(Response.Status.CLIENT_NOT_CONNECTED));
|
|
}
|
|
}
|
|
@@ -1229,7 +1282,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
ListenableFuture<Status> response;
|
|
ListenableFuture<Status> response;
|
|
|
|
|
|
- response = futureStub.compact(request);
|
|
|
|
|
|
+ response = futureStub().compact(request);
|
|
|
|
|
|
Futures.addCallback(
|
|
Futures.addCallback(
|
|
response,
|
|
response,
|
|
@@ -1322,16 +1375,6 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
return searchResponse;
|
|
return searchResponse;
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean channelIsReadyOrIdle() {
|
|
|
|
- if (channel == null) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- ConnectivityState connectivityState = channel.getState(false);
|
|
|
|
- return connectivityState == ConnectivityState.READY
|
|
|
|
- || connectivityState
|
|
|
|
- == ConnectivityState.IDLE; // Since a new RPC would take the channel out of idle mode
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
///////////////////// Log Functions//////////////////////
|
|
///////////////////// Log Functions//////////////////////
|
|
|
|
|
|
private void logInfo(String msg, Object... params) {
|
|
private void logInfo(String msg, Object... params) {
|