Skip to content

Commit

Permalink
localstore: check valid timestamp if time is reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Nov 30, 2015
1 parent 151e8b1 commit d93fda2
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions store/localstore/local_version_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"
"time"

"github.com/ngaut/log"
"github.com/pingcap/tidb/kv"
)

Expand All @@ -31,18 +32,26 @@ func (l *LocalVersionProvider) CurrentVersion() (kv.Version, error) {
l.mu.Lock()
defer l.mu.Unlock()

var ts uint64
ts = uint64((time.Now().UnixNano() / int64(time.Millisecond)) << timePrecisionOffset)
if l.lastTimestamp == uint64(ts) {
l.logical++
if l.logical >= 1<<timePrecisionOffset {
return kv.Version{}, ErrOverflow
for {
var ts uint64
ts = uint64((time.Now().UnixNano() / int64(time.Millisecond)) << timePrecisionOffset)

if l.lastTimestamp > ts {
log.Warn("invalid physical time stamp")
continue
}

if l.lastTimestamp == uint64(ts) {
l.logical++
if l.logical >= 1<<timePrecisionOffset {
return kv.Version{}, ErrOverflow
}
return kv.Version{Ver: ts + l.logical}, nil
}
return kv.Version{Ver: ts + l.logical}, nil
l.lastTimestamp = ts
l.logical = 0
return kv.Version{Ver: ts}, nil
}
l.lastTimestamp = ts
l.logical = 0
return kv.Version{Ver: ts}, nil
}

func localVersionToTimestamp(ver kv.Version) uint64 {
Expand Down

0 comments on commit d93fda2

Please sign in to comment.