mirror of https://github.com/milvus-io/milvus.git
parent
3721cbfea1
commit
bd3056fcbe
|
@ -12,6 +12,7 @@
|
||||||
package tso
|
package tso
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -87,8 +88,58 @@ func TestGlobalTSOAllocator_All(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Alloc", func(t *testing.T) {
|
||||||
|
_, err := gTestTsoAllocator.Alloc(100)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("AllocOne", func(t *testing.T) {
|
||||||
|
_, err := gTestTsoAllocator.AllocOne()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Reset", func(t *testing.T) {
|
||||||
|
gTestTsoAllocator.Reset()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGlobalTSOAllocator_Fail(t *testing.T) {
|
||||||
|
endpoints := os.Getenv("ETCD_ENDPOINTS")
|
||||||
|
if endpoints == "" {
|
||||||
|
endpoints = "localhost:2379"
|
||||||
|
}
|
||||||
|
etcdEndpoints := strings.Split(endpoints, ",")
|
||||||
|
etcdKV, err := tsoutil.NewTSOKVBase(etcdEndpoints, "/test/root/kv", "tsoTest")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
gTestTsoAllocator = NewGlobalTSOAllocator("timestamp", etcdKV)
|
||||||
|
t.Run("Initialize", func(t *testing.T) {
|
||||||
|
err := gTestTsoAllocator.Initialize()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GenerateTSO_invalid", func(t *testing.T) {
|
||||||
|
_, err := gTestTsoAllocator.GenerateTSO(0)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
gTestTsoAllocator.SetLimitMaxLogic(true)
|
||||||
|
t.Run("SetTSO_invalid", func(t *testing.T) {
|
||||||
|
err := gTestTsoAllocator.SetTSO(0)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
|
err = gTestTsoAllocator.SetTSO(math.MaxUint64)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Alloc_invalid", func(t *testing.T) {
|
||||||
|
_, err := gTestTsoAllocator.Alloc(0)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
|
_, err = gTestTsoAllocator.Alloc(math.MaxUint32)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Reset", func(t *testing.T) {
|
t.Run("Reset", func(t *testing.T) {
|
||||||
gTestTsoAllocator.Reset()
|
gTestTsoAllocator.Reset()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,19 +68,19 @@ type timestampOracle struct {
|
||||||
lastSavedTime atomic.Value
|
lastSavedTime atomic.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampOracle) loadTimestamp() (time.Time, error) {
|
//func (t *timestampOracle) loadTimestamp() (time.Time, error) {
|
||||||
strData, err := t.txnKV.Load(t.key)
|
// strData, err := t.txnKV.Load(t.key)
|
||||||
|
//
|
||||||
var binData []byte = []byte(strData)
|
// var binData []byte = []byte(strData)
|
||||||
|
//
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return typeutil.ZeroTime, err
|
// return typeutil.ZeroTime, err
|
||||||
}
|
// }
|
||||||
if len(binData) == 0 {
|
// if len(binData) == 0 {
|
||||||
return typeutil.ZeroTime, nil
|
// return typeutil.ZeroTime, nil
|
||||||
}
|
// }
|
||||||
return typeutil.ParseTimestamp(binData)
|
// return typeutil.ParseTimestamp(binData)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// save timestamp, if lastTs is 0, we think the timestamp doesn't exist, so create it,
|
// save timestamp, if lastTs is 0, we think the timestamp doesn't exist, so create it,
|
||||||
// otherwise, update it.
|
// otherwise, update it.
|
||||||
|
@ -95,12 +95,10 @@ func (t *timestampOracle) saveTimestamp(ts time.Time) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampOracle) InitTimestamp() error {
|
func (t *timestampOracle) InitTimestamp() error {
|
||||||
|
|
||||||
//last, err := t.loadTimestamp()
|
//last, err := t.loadTimestamp()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
next := time.Now()
|
next := time.Now()
|
||||||
|
|
||||||
// If the current system time minus the saved etcd timestamp is less than `updateTimestampGuard`,
|
// If the current system time minus the saved etcd timestamp is less than `updateTimestampGuard`,
|
||||||
|
|
Loading…
Reference in New Issue