Browse Source

Refine consistency level logic (#372)

Signed-off-by: yhmo <yihua.mo@zilliz.com>

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 2 years ago
parent
commit
b19e27f940

+ 6 - 2
.github/mergify.yml

@@ -1,7 +1,9 @@
 pull_request_rules:
   - name: Test passed for code changed
     conditions:
-      - base=master
+      - or:
+        - base=master
+        - base~=2\.\d
       - "status-success=Build and test"
     actions:
       label:
@@ -10,7 +12,9 @@ pull_request_rules:
 
   - name: Remove ci-passed when code check failed
     conditions:
-      - base=master
+      - or:
+        - base=master
+        - base~=2\.\d
       - "check-failure=Build and test"
     actions:
       label:

+ 6 - 2
.github/workflows/maven.yml

@@ -5,9 +5,13 @@ name: Java CI with Maven
 
 on:
   push:
-    branches: [ master ]
+    branches:
+      - base=master
+      - base~=2\.\d
   pull_request:
-    branches: [ master ]
+    branches:
+      - base=master
+      - base~=2\.\d
 
 jobs:
   build:

+ 2 - 1
src/main/java/io/milvus/connection/QueryNodeListener.java

@@ -1,5 +1,6 @@
 package io.milvus.connection;
 
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.grpc.SearchResults;
 import io.milvus.param.QueryNodeSingleSearch;
 import io.milvus.param.R;
@@ -32,7 +33,7 @@ public class QueryNodeListener implements Listener {
                 .withMetricType(singleSearch.getMetricType())
                 .withTopK(5)
                 .withRoundDecimal(-1)
-                .withGuaranteeTimestamp(1L)
+                .withConsistencyLevel(ConsistencyLevelEnum.EVENTUALLY)
                 .build();
     }
 

+ 7 - 9
src/main/java/io/milvus/param/ParamUtils.java

@@ -308,8 +308,7 @@ public class ParamUtils {
             builder.setDsl(requestParam.getExpr());
         }
 
-        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel(),
-                requestParam.getGuaranteeTimestamp(), requestParam.getGracefulTime());
+        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel());
         builder.setTravelTimestamp(requestParam.getTravelTimestamp());
         builder.setGuaranteeTimestamp(guaranteeTimestamp);
 
@@ -317,8 +316,7 @@ public class ParamUtils {
     }
 
     public static QueryRequest convertQueryParam(@NonNull QueryParam requestParam) {
-        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel(),
-                requestParam.getGuaranteeTimestamp(), requestParam.getGracefulTime());
+        long guaranteeTimestamp = getGuaranteeTimestamp(requestParam.getConsistencyLevel());
         return QueryRequest.newBuilder()
                 .setCollectionName(requestParam.getCollectionName())
                 .addAllPartitionNames(requestParam.getPartitionNames())
@@ -329,8 +327,8 @@ public class ParamUtils {
                 .build();
     }
 
-    private static long getGuaranteeTimestamp(ConsistencyLevelEnum consistencyLevel,
-                                              long guaranteeTimestamp, Long gracefulTime){
+    private static long getGuaranteeTimestamp(ConsistencyLevelEnum consistencyLevel){
+        long guaranteeTimestamp = 2L;
         if(consistencyLevel == null){
             return guaranteeTimestamp;
         }
@@ -338,12 +336,12 @@ public class ParamUtils {
             case STRONG:
                 guaranteeTimestamp = 0L;
                 break;
-            case BOUNDED:
-                guaranteeTimestamp = (new Date()).getTime() - gracefulTime;
-                break;
             case EVENTUALLY:
                 guaranteeTimestamp = 1L;
                 break;
+            case BOUNDED:
+                guaranteeTimestamp = 2L;
+                break;
         }
         return guaranteeTimestamp;
     }

+ 3 - 41
src/main/java/io/milvus/param/dml/QueryParam.java

@@ -40,8 +40,6 @@ public class QueryParam {
     private final List<String> outFields;
     private final String expr;
     private final long travelTimestamp;
-    private final long guaranteeTimestamp;
-    private final Long gracefulTime;
     private final ConsistencyLevelEnum consistencyLevel;
 
     private QueryParam(@NonNull Builder builder) {
@@ -50,9 +48,7 @@ public class QueryParam {
         this.outFields = builder.outFields;
         this.expr = builder.expr;
         this.travelTimestamp = builder.travelTimestamp;
-        this.guaranteeTimestamp = builder.guaranteeTimestamp;
         this.consistencyLevel = builder.consistencyLevel;
-        this.gracefulTime = builder.gracefulTime;
     }
 
     public static Builder newBuilder() {
@@ -68,9 +64,7 @@ public class QueryParam {
         private final List<String> outFields = new ArrayList<>();
         private String expr = "";
         private Long travelTimestamp = 0L;
-        private Long gracefulTime = 5000L;
-        private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
-        private ConsistencyLevelEnum consistencyLevel;
+        private ConsistencyLevelEnum consistencyLevel = ConsistencyLevelEnum.BOUNDED;
 
         private Builder() {
         }
@@ -88,6 +82,7 @@ public class QueryParam {
 
         /**
          * ConsistencyLevel of consistency level.
+         * Default value is ConsistencyLevelEnum.BOUNDED.
          *
          * @param consistencyLevel consistency level
          * @return <code>Builder</code>
@@ -108,17 +103,6 @@ public class QueryParam {
             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).
          *
@@ -180,25 +164,6 @@ public class QueryParam {
             return this;
         }
 
-        /**
-         * Instructs server to see insert/delete operations performed before a provided timestamp.
-         * If no such timestamp is specified, the server will wait for the latest operation to finish and query.
-         *
-         * Note: The timestamp is not an absolute timestamp, it is a hybrid value combined by UTC time and internal flags.
-         *  We call it TSO, for more information please refer to: https://github.com/milvus-io/milvus/blob/master/docs/design_docs/milvus_hybrid_ts_en.md
-         *  You can get a TSO from insert/delete operations, see the <code>MutationResultWrapper</code> class.
-         *  Use an operation's TSO to set this parameter, the server will execute query after this operation is finished.
-         *
-         * Default value is GUARANTEE_EVENTUALLY_TS, query executes query immediately.
-         *
-         * @param ts a timestamp value
-         * @return <code>Builder</code>
-         */
-        public Builder withGuaranteeTimestamp(@NonNull Long ts) {
-            this.guaranteeTimestamp = ts;
-            return this;
-        }
-
         /**
          * Verifies parameters and creates a new {@link QueryParam} instance.
          *
@@ -212,10 +177,6 @@ public class QueryParam {
                 throw new ParamException("The travel timestamp must be greater than 0");
             }
 
-            if (guaranteeTimestamp < 0) {
-                throw new ParamException("The guarantee timestamp must be greater than 0");
-            }
-
             return new QueryParam(this);
         }
     }
@@ -230,6 +191,7 @@ public class QueryParam {
         return "QueryParam{" +
                 "collectionName='" + collectionName + '\'' +
                 ", partitionNames='" + partitionNames.toString() + '\'' +
+                ", outFields='" + outFields.toString() + '\'' +
                 ", expr='" + expr + '\'' +
                 ", consistencyLevel='" + consistencyLevel + '\'' +
                 '}';

+ 3 - 41
src/main/java/io/milvus/param/dml/SearchParam.java

@@ -47,8 +47,6 @@ public class SearchParam {
     private final int roundDecimal;
     private final String params;
     private final long travelTimestamp;
-    private final long guaranteeTimestamp;
-    private final Long gracefulTime;
     private final ConsistencyLevelEnum consistencyLevel;
 
     private SearchParam(@NonNull Builder builder) {
@@ -63,8 +61,6 @@ public class SearchParam {
         this.roundDecimal = builder.roundDecimal;
         this.params = builder.params;
         this.travelTimestamp = builder.travelTimestamp;
-        this.guaranteeTimestamp = builder.guaranteeTimestamp;
-        this.gracefulTime = builder.gracefulTime;
         this.consistencyLevel = builder.consistencyLevel;
     }
 
@@ -87,9 +83,7 @@ public class SearchParam {
         private Integer roundDecimal = -1;
         private String params = "{}";
         private Long travelTimestamp = 0L;
-        private Long guaranteeTimestamp = Constant.GUARANTEE_EVENTUALLY_TS;
-        private Long gracefulTime = 5000L;
-        private ConsistencyLevelEnum consistencyLevel;
+        private ConsistencyLevelEnum consistencyLevel = ConsistencyLevelEnum.BOUNDED;
 
        Builder() {
         }
@@ -118,6 +112,7 @@ public class SearchParam {
 
         /**
          * ConsistencyLevel of consistency level.
+         * Default value is ConsistencyLevelEnum.BOUNDED.
          *
          * @param consistencyLevel consistency level
          * @return <code>Builder</code>
@@ -127,17 +122,6 @@ public class SearchParam {
             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).
          *
@@ -270,25 +254,6 @@ public class SearchParam {
             return this;
         }
 
-        /**
-         * Instructs server to see insert/delete operations performed before a provided timestamp.
-         * If no such timestamp is specified, the server will wait for the latest operation to finish and search.
-         *
-         * Note: The timestamp is not an absolute timestamp, it is a hybrid value combined by UTC time and internal flags.
-         *  We call it TSO, for more information please refer to: https://github.com/milvus-io/milvus/blob/master/docs/design_docs/milvus_hybrid_ts_en.md
-         *  You can get a TSO from insert/delete operations, see the <code>MutationResultWrapper</code> class.
-         *  Use an operation's TSO to set this parameter, the server will execute search after this operation is finished.
-         *
-         * Default value is GUARANTEE_EVENTUALLY_TS, server executes search immediately.
-         *
-         * @param ts a timestamp value
-         * @return <code>Builder</code>
-         */
-        public Builder withGuaranteeTimestamp(@NonNull Long ts) {
-            this.guaranteeTimestamp = ts;
-            return this;
-        }
-
         /**
          * Verifies parameters and creates a new {@link SearchParam} instance.
          *
@@ -306,10 +271,6 @@ public class SearchParam {
                 throw new ParamException("The travel timestamp must be greater than 0");
             }
 
-            if (guaranteeTimestamp < 0) {
-                throw new ParamException("The guarantee timestamp must be greater than 0");
-            }
-
             if (metricType == MetricType.INVALID) {
                 throw new ParamException("Metric type is invalid");
             }
@@ -376,6 +337,7 @@ public class SearchParam {
                 ", topK=" + topK +
                 ", expr='" + expr + '\'' +
                 ", params='" + params + '\'' +
+                ", consistencyLevel='" + consistencyLevel + '\'' +
                 '}';
     }
 }

+ 3 - 27
src/test/java/io/milvus/client/MilvusServiceClientTest.java

@@ -21,6 +21,7 @@ package io.milvus.client;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.protobuf.ByteString;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.IllegalResponseException;
 import io.milvus.exception.ParamException;
 import io.milvus.grpc.*;
@@ -1788,22 +1789,6 @@ class MilvusServiceClientTest {
                 .build()
         );
 
-        // guarantee timestamp must be greater than 0
-        assertThrows(ParamException.class, () -> SearchParam.newBuilder()
-                .withCollectionName("collection1")
-                .withPartitionNames(partitions)
-                .addPartitionName("p2")
-                .withParams("dummy")
-                .withOutFields(outputFields)
-                .withVectorFieldName("field1")
-                .withMetricType(MetricType.IP)
-                .withTopK(5)
-                .withVectors(vectors)
-                .withExpr("dummy")
-                .withGuaranteeTimestamp(-1L)
-                .build()
-        );
-
         // collection name is empty
         List<Float> vector1 = Collections.singletonList(0.1F);
         vectors.add(vector1);
@@ -2008,7 +1993,7 @@ class MilvusServiceClientTest {
                 .withExpr("dummy")
                 .withRoundDecimal(5)
                 .withTravelTimestamp(1L)
-                .withGuaranteeTimestamp(1L)
+                .withConsistencyLevel(ConsistencyLevelEnum.EVENTUALLY)
                 .build();
         testFuncByName("search", param);
 
@@ -2064,15 +2049,6 @@ class MilvusServiceClientTest {
                 .withTravelTimestamp(-1L)
                 .build()
         );
-
-        assertThrows(ParamException.class, () -> QueryParam.newBuilder()
-                .withCollectionName("collection1")
-                .withPartitionNames(partitions)
-                .withOutFields(outputFields)
-                .withExpr("dummy")
-                .withGuaranteeTimestamp(-1L)
-                .build()
-        );
     }
 
     @Test
@@ -2086,7 +2062,7 @@ class MilvusServiceClientTest {
                 .addOutField("d1")
                 .withExpr("dummy")
                 .withTravelTimestamp(0L)
-                .withGuaranteeTimestamp(1L)
+                .withConsistencyLevel(ConsistencyLevelEnum.EVENTUALLY)
                 .build();
 
         testFuncByName("query", param);