Browse Source

xun.huang@zilliz.com 1.milvus client impl https 2.delete account password log 3.query and search add consistency level. (#325)

Signed-off-by: xun.huang@zilliz.com <xun.huang@zilliz.com>
yelusion 3 years ago
parent
commit
5725b46480

+ 0 - 1
.gitignore

@@ -26,4 +26,3 @@ hs_err_pid*
 target/
 target/
 volumes/
 volumes/
 *.iml
 *.iml
-

+ 38 - 36
examples/main/io/milvus/GeneralExample.java

@@ -46,6 +46,8 @@ public class GeneralExample {
         ConnectParam connectParam = ConnectParam.newBuilder()
         ConnectParam connectParam = ConnectParam.newBuilder()
                 .withHost("localhost")
                 .withHost("localhost")
                 .withPort(19530)
                 .withPort(19530)
+                .withAuthorization("root","Milvus")
+                .withSecure(true)
                 .build();
                 .build();
         milvusClient = new MilvusServiceClient(connectParam);
         milvusClient = new MilvusServiceClient(connectParam);
     }
     }
@@ -350,42 +352,42 @@ public class GeneralExample {
         return response;
         return response;
     }
     }
 
 
-//    private R<SearchResults> searchProfile(String expr) {
-//        System.out.println("========== searchProfile() ==========");
-//        long begin = System.currentTimeMillis();
-//
-//        List<String> outFields = Collections.singletonList(AGE_FIELD);
-//        List<ByteBuffer> vectors = generateBinaryVectors(5);
-//
-//        SearchParam searchParam = SearchParam.newBuilder()
-//                .withCollectionName(COLLECTION_NAME)
-//                .withMetricType(MetricType.HAMMING)
-//                .withOutFields(outFields)
-//                .withTopK(SEARCH_K)
-//                .withVectors(vectors)
-//                .withVectorFieldName(PROFILE_FIELD)
-//                .withExpr(expr)
-//                .withParams(SEARCH_PARAM)
-//                .build();
-//
-//
-//        R<SearchResults> response = milvusClient.search(searchParam);
-//        long end = System.currentTimeMillis();
-//        long cost = (end - begin);
-//        System.out.println("Search time cost: " + cost + "ms");
-//
-//        handleResponseStatus(response);
-//        SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
-//        for (int i = 0; i < vectors.size(); ++i) {
-//            System.out.println("Search result of No." + i);
-//            List<SearchResultsWrapper.IDScore> scores = wrapper.getIDScore(i);
-//            System.out.println(scores);
-//            System.out.println("Output field data for No." + i);
-//            System.out.println(wrapper.getFieldData(AGE_FIELD, i));
-//        }
-//
-//        return response;
-//    }
+    private R<SearchResults> searchProfile(String expr) {
+        System.out.println("========== searchProfile() ==========");
+        long begin = System.currentTimeMillis();
+
+        List<String> outFields = Collections.singletonList(AGE_FIELD);
+        List<ByteBuffer> vectors = generateBinaryVectors(5);
+
+        SearchParam searchParam = SearchParam.newBuilder()
+                .withCollectionName(COLLECTION_NAME)
+                .withMetricType(MetricType.HAMMING)
+                .withOutFields(outFields)
+                .withTopK(SEARCH_K)
+                .withVectors(vectors)
+                .withVectorFieldName(PROFILE_FIELD)
+                .withExpr(expr)
+                .withParams(SEARCH_PARAM)
+                .build();
+
+
+        R<SearchResults> response = milvusClient.search(searchParam);
+        long end = System.currentTimeMillis();
+        long cost = (end - begin);
+        System.out.println("Search time cost: " + cost + "ms");
+
+        handleResponseStatus(response);
+        SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
+        for (int i = 0; i < vectors.size(); ++i) {
+            System.out.println("Search result of No." + i);
+            List<SearchResultsWrapper.IDScore> scores = wrapper.getIDScore(i);
+            System.out.println(scores);
+            System.out.println("Output field data for No." + i);
+            System.out.println(wrapper.getFieldData(AGE_FIELD, i));
+        }
+
+        return response;
+    }
 
 
     private R<CalcDistanceResults> calDistance() {
     private R<CalcDistanceResults> calDistance() {
         System.out.println("========== calDistance() ==========");
         System.out.println("========== calDistance() ==========");

+ 2 - 2
examples/pom.xml

@@ -25,7 +25,7 @@
 
 
     <groupId>io.milvus</groupId>
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java-examples</artifactId>
     <artifactId>milvus-sdk-java-examples</artifactId>
-    <version>2.0.4</version>
+    <version>2.1.0-beta1</version>
     <build>
     <build>
         <plugins>
         <plugins>
             <plugin>
             <plugin>
@@ -63,7 +63,7 @@
         <dependency>
         <dependency>
             <groupId>io.milvus</groupId>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>2.0.4</version>
+            <version>2.1.0-beta1</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
             <groupId>com.google.code.gson</groupId>

+ 17 - 17
pom.xml

@@ -25,7 +25,7 @@
 
 
     <groupId>io.milvus</groupId>
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>2.0.5</version>
+    <version>2.1.0-beta1</version>
     <packaging>jar</packaging>
     <packaging>jar</packaging>
 
 
     <name>io.milvus:milvus-sdk-java</name>
     <name>io.milvus:milvus-sdk-java</name>
@@ -85,11 +85,6 @@
     </dependencyManagement>
     </dependencyManagement>
 
 
     <dependencies>
     <dependencies>
-        <dependency>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-gpg-plugin</artifactId>
-            <version>1.6</version>
-        </dependency>
         <dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-netty-shaded</artifactId>
             <artifactId>grpc-netty-shaded</artifactId>
@@ -170,6 +165,11 @@
             <artifactId>okhttp</artifactId>
             <artifactId>okhttp</artifactId>
             <version>3.14.9</version>
             <version>3.14.9</version>
         </dependency>
         </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+            <version>3.0.20</version>
+        </dependency>
     </dependencies>
     </dependencies>
 
 
     <profiles>
     <profiles>
@@ -240,17 +240,17 @@
             </extension>
             </extension>
         </extensions>
         </extensions>
         <plugins>
         <plugins>
-            <plugin>
-                <groupId>org.sonatype.plugins</groupId>
-                <artifactId>nexus-staging-maven-plugin</artifactId>
-                <version>1.6.8</version>
-                <extensions>true</extensions>
-                <configuration>
-                    <serverId>ossrh</serverId>
-                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
-                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
-                </configuration>
-            </plugin>
+                        <plugin>
+                            <groupId>org.sonatype.plugins</groupId>
+                            <artifactId>nexus-staging-maven-plugin</artifactId>
+                            <version>1.6.8</version>
+                            <extensions>true</extensions>
+                            <configuration>
+                                <serverId>ossrh</serverId>
+                                <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+                                <autoReleaseAfterClose>true</autoReleaseAfterClose>
+                            </configuration>
+                        </plugin>
             <plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-release-plugin</artifactId>
                 <artifactId>maven-release-plugin</artifactId>

+ 11 - 12
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -1928,16 +1928,16 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
                 return failedStatus("CreateCredential", response);
                 return failedStatus("CreateCredential", response);
             }
             }
 
 
-            logInfo("CreateCredential successfully! Username:{}, password:{}",
-                    requestParam.getUsername(), requestParam.getPassword());
+            logInfo("CreateCredential successfully! Username:{}",
+                    requestParam.getUsername());
             return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG));
             return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG));
         } catch (StatusRuntimeException e) {
         } catch (StatusRuntimeException e) {
-            logError("CreateCredential RPC failed! Username:{}, password:{}\n{}",
-                    requestParam.getUsername(), requestParam.getPassword(), e.getStatus().toString());
+            logError("CreateCredential RPC failed! Username:{}\n{}",
+                    requestParam.getUsername(), e.getStatus().toString());
             return R.failed(e);
             return R.failed(e);
         } catch (Exception e) {
         } catch (Exception e) {
-            logError("CreateCredential failed! Username:{}, password:{}\n{}",
-                    requestParam.getUsername(), requestParam.getPassword(), e.getMessage());
+            logError("CreateCredential failed! Username:{},\n{}",
+                    requestParam.getUsername(), e.getMessage());
             return R.failed(e);
             return R.failed(e);
         }
         }
     }
     }
@@ -1962,16 +1962,15 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
                 return failedStatus("UpdateCredential", response);
                 return failedStatus("UpdateCredential", response);
             }
             }
 
 
-            logInfo("UpdateCredential successfully! Username:{}, oldPassword:{}, newPassword:{}",
-                    requestParam.getUsername(), requestParam.getOldPassword(), requestParam.getNewPassword());
+            logInfo("UpdateCredential successfully! Username:{}", requestParam.getUsername());
             return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG));
             return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG));
         } catch (StatusRuntimeException e) {
         } catch (StatusRuntimeException e) {
-            logError("UpdateCredential RPC failed! Username:{}, oldPassword:{}, newPassword:{}\n{}",
-                    requestParam.getUsername(), requestParam.getOldPassword(), requestParam.getNewPassword(), e.getStatus().toString());
+            logError("UpdateCredential RPC failed! Username:{}\n{}",
+                    requestParam.getUsername(), e.getStatus().toString());
             return R.failed(e);
             return R.failed(e);
         } catch (Exception e) {
         } catch (Exception e) {
-            logError("UpdateCredential failed! Username:{}, oldPassword:{}, newPassword:{}\n{}",
-                    requestParam.getUsername(), requestParam.getOldPassword(), requestParam.getNewPassword(), e.getMessage());
+            logError("UpdateCredential failed! Username:{}\n{}",
+                    requestParam.getUsername(), e.getMessage());
             return R.failed(e);
             return R.failed(e);
         }
         }
     }
     }

+ 2 - 0
src/main/java/io/milvus/client/MilvusMultiServiceClient.java

@@ -75,6 +75,7 @@ public class MilvusMultiServiceClient implements MilvusClient {
         long keepAliveTimeMs = multiConnectParam.getKeepAliveTimeMs();
         long keepAliveTimeMs = multiConnectParam.getKeepAliveTimeMs();
         long keepAliveTimeoutMs = multiConnectParam.getKeepAliveTimeoutMs();
         long keepAliveTimeoutMs = multiConnectParam.getKeepAliveTimeoutMs();
         boolean keepAliveWithoutCalls = multiConnectParam.isKeepAliveWithoutCalls();
         boolean keepAliveWithoutCalls = multiConnectParam.isKeepAliveWithoutCalls();
+        boolean secure = multiConnectParam.isSecure();
         long idleTimeoutMs = multiConnectParam.getIdleTimeoutMs();
         long idleTimeoutMs = multiConnectParam.getIdleTimeoutMs();
 
 
         ConnectParam clusterConnectParam = ConnectParam.newBuilder()
         ConnectParam clusterConnectParam = ConnectParam.newBuilder()
@@ -84,6 +85,7 @@ public class MilvusMultiServiceClient implements MilvusClient {
                 .withKeepAliveTime(keepAliveTimeMs, TimeUnit.MILLISECONDS)
                 .withKeepAliveTime(keepAliveTimeMs, TimeUnit.MILLISECONDS)
                 .withKeepAliveTimeout(keepAliveTimeoutMs, TimeUnit.MILLISECONDS)
                 .withKeepAliveTimeout(keepAliveTimeoutMs, TimeUnit.MILLISECONDS)
                 .keepAliveWithoutCalls(keepAliveWithoutCalls)
                 .keepAliveWithoutCalls(keepAliveWithoutCalls)
+                .secure(secure)
                 .withIdleTimeout(idleTimeoutMs, TimeUnit.MILLISECONDS)
                 .withIdleTimeout(idleTimeoutMs, TimeUnit.MILLISECONDS)
                 .withAuthorization(multiConnectParam.getAuthorization())
                 .withAuthorization(multiConnectParam.getAuthorization())
                 .build();
                 .build();

+ 8 - 3
src/main/java/io/milvus/client/MilvusServiceClient.java

@@ -37,15 +37,20 @@ public class MilvusServiceClient extends AbstractMilvusGrpcClient {
         Metadata metadata = new Metadata();
         Metadata metadata = new Metadata();
         metadata.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), connectParam.getAuthorization());
         metadata.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), connectParam.getAuthorization());
 
 
-        channel = ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort())
+        ManagedChannelBuilder builder = ManagedChannelBuilder.forAddress(connectParam.getHost(), connectParam.getPort())
                 .usePlaintext()
                 .usePlaintext()
                 .maxInboundMessageSize(Integer.MAX_VALUE)
                 .maxInboundMessageSize(Integer.MAX_VALUE)
                 .keepAliveTime(connectParam.getKeepAliveTimeMs(), TimeUnit.MILLISECONDS)
                 .keepAliveTime(connectParam.getKeepAliveTimeMs(), TimeUnit.MILLISECONDS)
                 .keepAliveTimeout(connectParam.getKeepAliveTimeoutMs(), TimeUnit.MILLISECONDS)
                 .keepAliveTimeout(connectParam.getKeepAliveTimeoutMs(), TimeUnit.MILLISECONDS)
                 .keepAliveWithoutCalls(connectParam.isKeepAliveWithoutCalls())
                 .keepAliveWithoutCalls(connectParam.isKeepAliveWithoutCalls())
                 .idleTimeout(connectParam.getIdleTimeoutMs(), TimeUnit.MILLISECONDS)
                 .idleTimeout(connectParam.getIdleTimeoutMs(), TimeUnit.MILLISECONDS)
-                .intercept(MetadataUtils.newAttachHeadersInterceptor(metadata))
-                .build();
+                .intercept(MetadataUtils.newAttachHeadersInterceptor(metadata));
+
+        if(connectParam.isSecure()){
+            builder.useTransportSecurity();
+        }
+        channel = builder.build();
+
         blockingStub = MilvusServiceGrpc.newBlockingStub(channel);
         blockingStub = MilvusServiceGrpc.newBlockingStub(channel);
         futureStub = MilvusServiceGrpc.newFutureStub(channel);
         futureStub = MilvusServiceGrpc.newFutureStub(channel);
     }
     }

+ 34 - 0
src/main/java/io/milvus/common/clientenum/ConsistencyLevelEnum.java

@@ -0,0 +1,34 @@
+package io.milvus.common.clientenum;
+
+import lombok.Getter;
+
+public enum ConsistencyLevelEnum {
+
+    STRONG("Strong", 0),
+//    SESSION("Session", 1),
+    BOUNDED("Bounded", 2),
+    EVENTUALLY("Eventually",3),
+    ;
+
+    @Getter
+    private final String name;
+
+    @Getter
+    private final int code;
+
+    ConsistencyLevelEnum(String name, int code){
+        this.name = name;
+        this.code = code;
+    }
+
+    private static final ConsistencyLevelEnum[] CONSISTENCY_LEVELS = new ConsistencyLevelEnum[values().length];
+
+    private static ConsistencyLevelEnum getNameByCode(int code) {
+        if (code >= 0 && code < CONSISTENCY_LEVELS.length) {
+            return CONSISTENCY_LEVELS[code];
+        }
+        return null;
+    }
+
+
+}

+ 29 - 1
src/main/java/io/milvus/param/ConnectParam.java

@@ -36,6 +36,7 @@ public class ConnectParam {
     private final long keepAliveTimeMs;
     private final long keepAliveTimeMs;
     private final long keepAliveTimeoutMs;
     private final long keepAliveTimeoutMs;
     private final boolean keepAliveWithoutCalls;
     private final boolean keepAliveWithoutCalls;
+    private final boolean secure;
     private final long idleTimeoutMs;
     private final long idleTimeoutMs;
     private final String authorization;
     private final String authorization;
 
 
@@ -47,6 +48,7 @@ public class ConnectParam {
         this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs;
         this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs;
         this.keepAliveWithoutCalls = builder.keepAliveWithoutCalls;
         this.keepAliveWithoutCalls = builder.keepAliveWithoutCalls;
         this.idleTimeoutMs = builder.idleTimeoutMs;
         this.idleTimeoutMs = builder.idleTimeoutMs;
+        this.secure = builder.secure;
         this.authorization = builder.authorization;
         this.authorization = builder.authorization;
     }
     }
 
 
@@ -74,6 +76,10 @@ public class ConnectParam {
         return keepAliveWithoutCalls;
         return keepAliveWithoutCalls;
     }
     }
 
 
+    public boolean isSecure() {
+        return secure;
+    }
+
     public long getIdleTimeoutMs() {
     public long getIdleTimeoutMs() {
         return idleTimeoutMs;
         return idleTimeoutMs;
     }
     }
@@ -96,6 +102,7 @@ public class ConnectParam {
         private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive
         private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive
         private long keepAliveTimeoutMs = 20000;
         private long keepAliveTimeoutMs = 20000;
         private boolean keepAliveWithoutCalls = false;
         private boolean keepAliveWithoutCalls = false;
+        private boolean secure = false;
         private long idleTimeoutMs = TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
         private long idleTimeoutMs = TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
         private String authorization = "";
         private String authorization = "";
 
 
@@ -171,6 +178,17 @@ public class ConnectParam {
             return this;
             return this;
         }
         }
 
 
+        /**
+         * Enables the secure for client channel.
+         *
+         * @param enable true keep-alive
+         * @return <code>Builder</code>
+         */
+        public Builder secure(boolean enable) {
+            secure = enable;
+            return this;
+        }
+
         /**
         /**
          * Sets the idle timeout value of client channel. The timeout value must be larger than zero.
          * Sets the idle timeout value of client channel. The timeout value must be larger than zero.
          *
          *
@@ -195,7 +213,17 @@ public class ConnectParam {
         }
         }
 
 
         /**
         /**
-         * Sets the authorization for this connection
+         * Sets secure the authorization for this connection
+         * @param secure boolean
+         * @return <code>Builder</code>
+         */
+        public Builder withSecure(boolean secure) {
+            this.secure = secure;
+            return this;
+        }
+
+        /**
+         * Sets the secure for this connection
          * @param authorization the authorization info that has included the encoded username and password info
          * @param authorization the authorization info that has included the encoded username and password info
          * @return <code>Builder</code>
          * @return <code>Builder</code>
          */
          */

+ 28 - 0
src/main/java/io/milvus/param/MultiConnectParam.java

@@ -19,6 +19,7 @@ public class MultiConnectParam {
     private final long keepAliveTimeMs;
     private final long keepAliveTimeMs;
     private final long keepAliveTimeoutMs;
     private final long keepAliveTimeoutMs;
     private final boolean keepAliveWithoutCalls;
     private final boolean keepAliveWithoutCalls;
+    private final boolean secure;
     private final long idleTimeoutMs;
     private final long idleTimeoutMs;
     private final String authorization;
     private final String authorization;
 
 
@@ -29,6 +30,7 @@ public class MultiConnectParam {
         this.keepAliveTimeMs = builder.keepAliveTimeMs;
         this.keepAliveTimeMs = builder.keepAliveTimeMs;
         this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs;
         this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs;
         this.keepAliveWithoutCalls = builder.keepAliveWithoutCalls;
         this.keepAliveWithoutCalls = builder.keepAliveWithoutCalls;
+        this.secure = builder.secure;
         this.idleTimeoutMs = builder.idleTimeoutMs;
         this.idleTimeoutMs = builder.idleTimeoutMs;
         this.authorization = builder.authorization;
         this.authorization = builder.authorization;
     }
     }
@@ -57,6 +59,10 @@ public class MultiConnectParam {
         return keepAliveWithoutCalls;
         return keepAliveWithoutCalls;
     }
     }
 
 
+    public boolean isSecure() {
+        return secure;
+    }
+
     public long getIdleTimeoutMs() {
     public long getIdleTimeoutMs() {
         return idleTimeoutMs;
         return idleTimeoutMs;
     }
     }
@@ -79,6 +85,7 @@ public class MultiConnectParam {
         private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive
         private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive
         private long keepAliveTimeoutMs = 20000;
         private long keepAliveTimeoutMs = 20000;
         private boolean keepAliveWithoutCalls = false;
         private boolean keepAliveWithoutCalls = false;
+        private boolean secure = false;
         private long idleTimeoutMs = TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
         private long idleTimeoutMs = TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
         private String authorization = "";
         private String authorization = "";
 
 
@@ -154,6 +161,27 @@ public class MultiConnectParam {
             return this;
             return this;
         }
         }
 
 
+        /**
+         * Enables the secure for client channel.
+         *
+         * @param enable true keep-alive
+         * @return <code>Builder</code>
+         */
+        public Builder secure(boolean enable) {
+            secure = enable;
+            return this;
+        }
+
+        /**
+         * Sets secure the authorization for this connection
+         * @param secure boolean
+         * @return <code>Builder</code>
+         */
+        public Builder withSecure(boolean secure) {
+            this.secure = secure;
+            return this;
+        }
+
         /**
         /**
          * Sets the idle timeout value of client channel. The timeout value must be larger than zero.
          * Sets the idle timeout value of client channel. The timeout value must be larger than zero.
          *
          *

+ 26 - 2
src/main/java/io/milvus/param/ParamUtils.java

@@ -1,6 +1,7 @@
 package io.milvus.param;
 package io.milvus.param;
 
 
 import com.google.protobuf.ByteString;
 import com.google.protobuf.ByteString;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
 import io.milvus.grpc.*;
 import io.milvus.grpc.*;
 import io.milvus.param.collection.FieldType;
 import io.milvus.param.collection.FieldType;
@@ -180,8 +181,10 @@ public class ParamUtils {
             builder.setDsl(requestParam.getExpr());
             builder.setDsl(requestParam.getExpr());
         }
         }
 
 
+        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel(),
+                requestParam.getGuaranteeTimestamp(), requestParam.getGracefulTime());
         builder.setTravelTimestamp(requestParam.getTravelTimestamp());
         builder.setTravelTimestamp(requestParam.getTravelTimestamp());
-        builder.setGuaranteeTimestamp(requestParam.getGuaranteeTimestamp());
+        builder.setGuaranteeTimestamp(guaranteeTimestamp);
 
 
         return builder.build();
         return builder.build();
     }
     }
@@ -192,16 +195,37 @@ public class ParamUtils {
      * @return a <code>QueryRequest</code> object
      * @return a <code>QueryRequest</code> object
      */
      */
     public static QueryRequest ConvertQueryParam(@NonNull QueryParam requestParam) {
     public static QueryRequest ConvertQueryParam(@NonNull QueryParam requestParam) {
+        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel(),
+                requestParam.getGuaranteeTimestamp(), requestParam.getGracefulTime());
         return QueryRequest.newBuilder()
         return QueryRequest.newBuilder()
                 .setCollectionName(requestParam.getCollectionName())
                 .setCollectionName(requestParam.getCollectionName())
                 .addAllPartitionNames(requestParam.getPartitionNames())
                 .addAllPartitionNames(requestParam.getPartitionNames())
                 .addAllOutputFields(requestParam.getOutFields())
                 .addAllOutputFields(requestParam.getOutFields())
                 .setExpr(requestParam.getExpr())
                 .setExpr(requestParam.getExpr())
                 .setTravelTimestamp(requestParam.getTravelTimestamp())
                 .setTravelTimestamp(requestParam.getTravelTimestamp())
-                .setGuaranteeTimestamp(requestParam.getGuaranteeTimestamp())
+                .setGuaranteeTimestamp(guaranteeTimestamp)
                 .build();
                 .build();
     }
     }
 
 
+    private static long getGuaranteeTimestamp(ConsistencyLevelEnum consistencyLevel,
+                                              long guaranteeTimestamp, Long gracefulTime){
+        if(consistencyLevel == null){
+            return guaranteeTimestamp;
+        }
+        switch (consistencyLevel){
+            case STRONG:
+                guaranteeTimestamp = 0L;
+                break;
+            case BOUNDED:
+                guaranteeTimestamp = (new Date()).getTime() - gracefulTime;
+                break;
+            case EVENTUALLY:
+                guaranteeTimestamp = 1L;
+                break;
+        }
+        return guaranteeTimestamp;
+    }
+
 
 
     private static final Set<DataType> vectorDataType = new HashSet<DataType>() {{
     private static final Set<DataType> vectorDataType = new HashSet<DataType>() {{
         add(DataType.FloatVector);
         add(DataType.FloatVector);

+ 2 - 2
src/main/java/io/milvus/param/credential/CreateCredentialParam.java

@@ -8,6 +8,7 @@ import lombok.NonNull;
 @Getter
 @Getter
 public class CreateCredentialParam {
 public class CreateCredentialParam {
     private final String username;
     private final String username;
+
     private final String password;
     private final String password;
 
 
     private CreateCredentialParam(@NonNull CreateCredentialParam.Builder builder) {
     private CreateCredentialParam(@NonNull CreateCredentialParam.Builder builder) {
@@ -72,8 +73,7 @@ public class CreateCredentialParam {
     @Override
     @Override
     public String toString() {
     public String toString() {
         return "CreateCredentialParam{" +
         return "CreateCredentialParam{" +
-                "username='" + username + '\'' +
-                ", password='" + password + '\'' +
+                "username='" + username +
                 '}';
                 '}';
     }
     }
 }
 }

+ 1 - 3
src/main/java/io/milvus/param/credential/UpdateCredentialParam.java

@@ -87,9 +87,7 @@ public class UpdateCredentialParam {
     @Override
     @Override
     public String toString() {
     public String toString() {
         return "UpdateCredentialParam{" +
         return "UpdateCredentialParam{" +
-                "username='" + username + '\'' +
-                ", oldPassword='" + oldPassword + '\'' +
-                ", newPassword='" + newPassword + '\'' +
+                "username='" + username +
                 '}';
                 '}';
     }
     }
 }
 }

+ 30 - 0
src/main/java/io/milvus/param/dml/QueryParam.java

@@ -20,6 +20,7 @@
 package io.milvus.param.dml;
 package io.milvus.param.dml;
 
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
 import io.milvus.param.Constant;
 import io.milvus.param.Constant;
 import io.milvus.param.ParamUtils;
 import io.milvus.param.ParamUtils;
@@ -40,6 +41,8 @@ public class QueryParam {
     private final String expr;
     private final String expr;
     private final long travelTimestamp;
     private final long travelTimestamp;
     private final long guaranteeTimestamp;
     private final long guaranteeTimestamp;
+    private final Long gracefulTime;
+    private final ConsistencyLevelEnum consistencyLevel;
 
 
     private QueryParam(@NonNull Builder builder) {
     private QueryParam(@NonNull Builder builder) {
         this.collectionName = builder.collectionName;
         this.collectionName = builder.collectionName;
@@ -48,6 +51,8 @@ public class QueryParam {
         this.expr = builder.expr;
         this.expr = builder.expr;
         this.travelTimestamp = builder.travelTimestamp;
         this.travelTimestamp = builder.travelTimestamp;
         this.guaranteeTimestamp = builder.guaranteeTimestamp;
         this.guaranteeTimestamp = builder.guaranteeTimestamp;
+        this.consistencyLevel = builder.consistencyLevel;
+        this.gracefulTime = builder.gracefulTime;
     }
     }
 
 
     public static Builder newBuilder() {
     public static Builder newBuilder() {
@@ -63,7 +68,9 @@ public class QueryParam {
         private final List<String> outFields = new ArrayList<>();
         private final List<String> outFields = new ArrayList<>();
         private String expr = "";
         private String expr = "";
         private Long travelTimestamp = 0L;
         private Long travelTimestamp = 0L;
+        private Long gracefulTime = 5000L;
         private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
         private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
+        private ConsistencyLevelEnum consistencyLevel;
 
 
         private Builder() {
         private Builder() {
         }
         }
@@ -79,6 +86,17 @@ public class QueryParam {
             return this;
             return this;
         }
         }
 
 
+        /**
+         * ConsistencyLevel of consistency level.
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
         /**
         /**
          * Sets partition names list to specify query scope (Optional).
          * Sets partition names list to specify query scope (Optional).
          *
          *
@@ -90,6 +108,17 @@ public class QueryParam {
             return this;
             return this;
         }
         }
 
 
+        /**
+         *  Graceful time for BOUNDED Consistency Level
+         *
+         * @param gracefulTime graceful time
+         * @return <code>Builder</code>
+         */
+        public Builder withGracefulTime(Long gracefulTime) {
+            this.gracefulTime = gracefulTime;
+            return this;
+        }
+
         /**
         /**
          * Adds a partition to specify query scope (Optional).
          * Adds a partition to specify query scope (Optional).
          *
          *
@@ -202,6 +231,7 @@ public class QueryParam {
                 "collectionName='" + collectionName + '\'' +
                 "collectionName='" + collectionName + '\'' +
                 ", partitionNames='" + partitionNames.toString() + '\'' +
                 ", partitionNames='" + partitionNames.toString() + '\'' +
                 ", expr='" + expr + '\'' +
                 ", expr='" + expr + '\'' +
+                ", consistencyLevel='" + consistencyLevel + '\'' +
                 '}';
                 '}';
     }
     }
 }
 }

+ 29 - 0
src/main/java/io/milvus/param/dml/SearchParam.java

@@ -20,6 +20,7 @@
 package io.milvus.param.dml;
 package io.milvus.param.dml;
 
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.exception.ParamException;
 import io.milvus.param.Constant;
 import io.milvus.param.Constant;
 import io.milvus.param.MetricType;
 import io.milvus.param.MetricType;
@@ -47,6 +48,8 @@ public class SearchParam {
     private final String params;
     private final String params;
     private final long travelTimestamp;
     private final long travelTimestamp;
     private final long guaranteeTimestamp;
     private final long guaranteeTimestamp;
+    private final Long gracefulTime;
+    private final ConsistencyLevelEnum consistencyLevel;
 
 
     private SearchParam(@NonNull Builder builder) {
     private SearchParam(@NonNull Builder builder) {
         this.collectionName = builder.collectionName;
         this.collectionName = builder.collectionName;
@@ -61,6 +64,8 @@ public class SearchParam {
         this.params = builder.params;
         this.params = builder.params;
         this.travelTimestamp = builder.travelTimestamp;
         this.travelTimestamp = builder.travelTimestamp;
         this.guaranteeTimestamp = builder.guaranteeTimestamp;
         this.guaranteeTimestamp = builder.guaranteeTimestamp;
+        this.gracefulTime = builder.gracefulTime;
+        this.consistencyLevel = builder.consistencyLevel;
     }
     }
 
 
     public static Builder newBuilder() {
     public static Builder newBuilder() {
@@ -83,6 +88,8 @@ public class SearchParam {
         private String params = "{}";
         private String params = "{}";
         private Long travelTimestamp = 0L;
         private Long travelTimestamp = 0L;
         private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
         private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
+        private Long gracefulTime = 5000L;
+        private ConsistencyLevelEnum consistencyLevel;
 
 
        Builder() {
        Builder() {
         }
         }
@@ -109,6 +116,28 @@ public class SearchParam {
             return this;
             return this;
         }
         }
 
 
+        /**
+         * ConsistencyLevel of consistency level.
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
+        /**
+         *  Graceful time for BOUNDED Consistency Level
+         *
+         * @param gracefulTime graceful time
+         * @return <code>Builder</code>
+         */
+        public Builder withGracefulTime(Long gracefulTime) {
+            this.gracefulTime = gracefulTime;
+            return this;
+        }
+
         /**
         /**
          * Adds a partition to specify search scope (Optional).
          * Adds a partition to specify search scope (Optional).
          *
          *

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

@@ -35,8 +35,8 @@ import io.milvus.response.*;
 import org.apache.commons.text.RandomStringGenerator;
 import org.apache.commons.text.RandomStringGenerator;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.Logger;
-import org.codehaus.plexus.util.FileUtils;
 
 
+import org.codehaus.plexus.util.FileUtils;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;