mirror of https://github.com/milvus-io/milvus.git
Fix timetravel error msg (#19722)
Signed-off-by: yangxuan <xuan.yang@zilliz.com> Signed-off-by: yangxuan <xuan.yang@zilliz.com>pull/19728/head
parent
9aa307d851
commit
d73186b2eb
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue