func (w *GCWorker) getOracleTime() (time.Time, error) { currentVer, err := w.store.CurrentVersion() if err != nil { return time.Time{}, errors.Trace(err) } physical := oracle.ExtractPhysical(currentVer.Ver) sec, nsec := physical/1e3, (physical%1e3)*1e6 return time.Unix(sec, nsec), nil }
func (o *mockOracle) GetTimestamp() (uint64, error) { o.Lock() defer o.Unlock() if o.stop { return 0, errors.Trace(errStopped) } physical := oracle.GetPhysical(time.Now().Add(o.offset)) ts := oracle.ComposeTS(physical, 0) if oracle.ExtractPhysical(o.lastTS) == physical { ts = o.lastTS + 1 } o.lastTS = ts return ts, nil }
// IsExpired returns whether lockTS+TTL is expired, both are ms. It uses `lastTS` // to compare, may return false negative result temporarily. func (o *pdOracle) IsExpired(lockTS, TTL uint64) bool { o.mu.RLock() defer o.mu.RUnlock() return oracle.ExtractPhysical(o.mu.lastTS) >= oracle.ExtractPhysical(lockTS)+int64(TTL) }
func (l *localOracle) IsExpired(lockTS uint64, TTL uint64) bool { return oracle.GetPhysical(time.Now()) >= oracle.ExtractPhysical(lockTS)+int64(TTL) }
func (o *mockOracle) IsExpired(lockTimestamp uint64, TTL uint64) bool { o.RLock() defer o.RUnlock() return oracle.GetPhysical(time.Now().Add(o.offset)) >= oracle.ExtractPhysical(lockTimestamp)+int64(TTL) }