diff --git a/internal/proxy/util.go b/internal/proxy/util.go index 9a3c019431..d687fa797f 100644 --- a/internal/proxy/util.go +++ b/internal/proxy/util.go @@ -592,8 +592,10 @@ func ValidatePassword(password string) error { func validateTravelTimestamp(travelTs, tMax typeutil.Timestamp) error { durationSeconds := tsoutil.CalculateDuration(tMax, travelTs) / 1000 if durationSeconds > Params.CommonCfg.RetentionDuration { - duration := time.Second * time.Duration(durationSeconds) - return fmt.Errorf("only support to travel back to %s so far", duration.String()) + + durationIn := time.Second * time.Duration(durationSeconds) + durationSupport := time.Second * time.Duration(Params.CommonCfg.RetentionDuration) + return fmt.Errorf("only support to travel back to %v so far, but got %v", durationSupport, durationIn) } return nil } diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index 0fc07b84d3..36f9e09ad4 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -22,15 +22,19 @@ import ( "strconv" "strings" "testing" - - "github.com/milvus-io/milvus/internal/proto/rootcoordpb" - - "github.com/milvus-io/milvus/internal/proto/internalpb" + "time" "github.com/milvus-io/milvus/api/commonpb" "github.com/milvus-io/milvus/api/schemapb" + "github.com/milvus-io/milvus/internal/util" "github.com/milvus-io/milvus/internal/util/crypto" + "github.com/milvus-io/milvus/internal/util/tsoutil" + "github.com/milvus-io/milvus/internal/util/typeutil" + + "github.com/milvus-io/milvus/internal/proto/internalpb" + "github.com/milvus-io/milvus/internal/proto/rootcoordpb" + "github.com/stretchr/testify/assert" "google.golang.org/grpc/metadata" ) @@ -773,3 +777,35 @@ func TestPasswordVerify(t *testing.T) { assert.True(t, passwordVerify(context.TODO(), username, password, metaCache)) assert.Equal(t, 1, invokedCount) } + +func TestValidateTravelTimestamp(t *testing.T) { + Params.Init() + originalRetentionDuration := Params.CommonCfg.RetentionDuration + defer func() { + Params.CommonCfg.RetentionDuration = originalRetentionDuration + }() + + travelTs := tsoutil.GetCurrentTime() + tests := []struct { + description string + defaultRD int64 + nowTs typeutil.Timestamp + isValid bool + }{ + {"one second", 100, tsoutil.AddPhysicalDurationOnTs(travelTs, time.Second), true}, + {"retention duration", 100, tsoutil.AddPhysicalDurationOnTs(travelTs, 100*time.Second), true}, + {"retention duration+1", 100, tsoutil.AddPhysicalDurationOnTs(travelTs, 101*time.Second), false}, + } + + for _, test := range tests { + t.Run(test.description, func(t *testing.T) { + Params.CommonCfg.RetentionDuration = test.defaultRD + err := validateTravelTimestamp(travelTs, test.nowTs) + if test.isValid { + assert.NoError(t, err) + } else { + assert.Error(t, err) + } + }) + } +} diff --git a/internal/util/paramtable/component_param.go b/internal/util/paramtable/component_param.go index 1ca256fb18..d1d6901150 100644 --- a/internal/util/paramtable/component_param.go +++ b/internal/util/paramtable/component_param.go @@ -28,7 +28,7 @@ import ( ) const ( - // DefaultRetentionDuration defines the default duration for retention which is 5 days in seconds. + // DefaultRetentionDuration defines the default duration for retention which is 1 days in seconds. DefaultRetentionDuration = 3600 * 24 // DefaultIndexSliceSize defines the default slice size of index file when serializing.