Improve code readibility

Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>
pull/4973/head^2
Cai Yudong 2021-04-12 14:11:06 +08:00 committed by yefu.chen
parent 8204546bcd
commit 687d48b75e
6 changed files with 14 additions and 16 deletions

View File

@ -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)")

View File

@ -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
}
}
}

View File

@ -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,
}

View File

@ -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: &timestampOracle{
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.

View File

@ -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)

View File

@ -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
}