mirror of https://github.com/milvus-io/milvus.git
Improve code readibility
Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>pull/4973/head^2
parent
8204546bcd
commit
687d48b75e
2
Makefile
2
Makefile
|
@ -123,7 +123,7 @@ singlenode: build-cpp
|
|||
@echo "Building single node ..."
|
||||
@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/singlenode $(PWD)/cmd/singlenode/main.go 1>/dev/null
|
||||
|
||||
build-go: binlog master proxyservice proxynode queryservice querynode indexservice indexnode datanode dataservice singlenode
|
||||
build-go: binlog master proxyservice proxynode queryservice querynode indexservice indexnode dataservice datanode singlenode
|
||||
|
||||
build-cpp:
|
||||
@(env bash $(PWD)/scripts/core_build.sh -f "$(CUSTOM_THIRDPARTY_PATH)")
|
||||
|
|
|
@ -76,7 +76,7 @@ func (t *EmptyTicker) Close() {
|
|||
|
||||
type Ticker struct {
|
||||
ticker *time.Ticker
|
||||
UpdateInterval time.Duration //
|
||||
UpdateInterval time.Duration
|
||||
}
|
||||
|
||||
func (t *Ticker) Init() {
|
||||
|
@ -138,7 +138,6 @@ func (ta *Allocator) mainLoop() {
|
|||
|
||||
for {
|
||||
select {
|
||||
|
||||
case first := <-ta.ForceSyncChan:
|
||||
ta.SyncReqs = append(ta.SyncReqs, first)
|
||||
pending := len(ta.ForceSyncChan)
|
||||
|
@ -174,7 +173,6 @@ func (ta *Allocator) mainLoop() {
|
|||
case <-loopCtx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ type GlobalIDAllocator struct {
|
|||
|
||||
func NewGlobalIDAllocator(key string, base kv.TxnBase) *GlobalIDAllocator {
|
||||
allocator := tso.NewGlobalTSOAllocator(key, base)
|
||||
allocator.EnableMaxLogic(false)
|
||||
allocator.SetLimitMaxLogic(false)
|
||||
return &GlobalIDAllocator{
|
||||
allocator: allocator,
|
||||
}
|
||||
|
|
|
@ -52,11 +52,10 @@ type GlobalTSOAllocator struct {
|
|||
|
||||
// NewGlobalTSOAllocator creates a new global TSO allocator.
|
||||
func NewGlobalTSOAllocator(key string, kvBase kv.TxnBase) *GlobalTSOAllocator {
|
||||
var saveInterval = 3 * time.Second
|
||||
return &GlobalTSOAllocator{
|
||||
tso: ×tampOracle{
|
||||
kvBase: kvBase,
|
||||
saveInterval: saveInterval,
|
||||
saveInterval: 3 * time.Second,
|
||||
maxResetTSGap: func() time.Duration { return 3 * time.Second },
|
||||
key: key,
|
||||
},
|
||||
|
@ -69,8 +68,8 @@ func (gta *GlobalTSOAllocator) Initialize() error {
|
|||
return gta.tso.InitTimestamp()
|
||||
}
|
||||
|
||||
func (gta *GlobalTSOAllocator) EnableMaxLogic(enable bool) {
|
||||
gta.LimitMaxLogic = enable
|
||||
func (gta *GlobalTSOAllocator) SetLimitMaxLogic(flag bool) {
|
||||
gta.LimitMaxLogic = flag
|
||||
}
|
||||
|
||||
// UpdateTSO is used to update the TSO in memory and the time window in etcd.
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestGlobalTSOAllocator_All(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
gTestTsoAllocator.EnableMaxLogic(false)
|
||||
gTestTsoAllocator.SetLimitMaxLogic(false)
|
||||
t.Run("GenerateTSO2", func(t *testing.T) {
|
||||
count := 1000
|
||||
maxL := 1 << 18
|
||||
|
@ -59,7 +59,8 @@ func TestGlobalTSOAllocator_All(t *testing.T) {
|
|||
lastPhysical = physical
|
||||
}
|
||||
})
|
||||
gTestTsoAllocator.EnableMaxLogic(true)
|
||||
|
||||
gTestTsoAllocator.SetLimitMaxLogic(true)
|
||||
t.Run("SetTSO", func(t *testing.T) {
|
||||
curTime := time.Now()
|
||||
nextTime := curTime.Add(2 * time.Second)
|
||||
|
|
|
@ -9,18 +9,18 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
physicalShiftBits = 18
|
||||
logicalBits = (1 << physicalShiftBits) - 1
|
||||
logicalBits = 18
|
||||
logicalBitsMask = (1 << logicalBits) - 1
|
||||
)
|
||||
|
||||
func ComposeTS(physical, logical int64) uint64 {
|
||||
return uint64((physical << physicalShiftBits) + logical)
|
||||
return uint64((physical << logicalBits) + logical)
|
||||
}
|
||||
|
||||
// ParseTS parses the ts to (physical,logical).
|
||||
func ParseTS(ts uint64) (time.Time, uint64) {
|
||||
logical := ts & logicalBits
|
||||
physical := ts >> physicalShiftBits
|
||||
logical := ts & logicalBitsMask
|
||||
physical := ts >> logicalBits
|
||||
physicalTime := time.Unix(int64(physical/1000), int64(physical)%1000*time.Millisecond.Nanoseconds())
|
||||
return physicalTime, logical
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue