예제 #1
0
파일: pd.go 프로젝트: jmptrader/tidb
func (o *pdOracle) getTimestamp() (uint64, error) {
	now := time.Now()
	physical, logical, err := o.c.GetTS()
	if err != nil {
		return 0, errors.Trace(err)
	}
	dist := time.Since(now)
	if dist > slowDist {
		log.Warnf("get timestamp too slow: %s", dist)
	}
	return oracle.ComposeTS(physical, logical), nil
}
예제 #2
0
파일: local.go 프로젝트: jmptrader/tidb
func (l *localOracle) GetTimestamp() (uint64, error) {
	l.Lock()
	defer l.Unlock()
	physical := oracle.GetPhysical(time.Now())
	ts := oracle.ComposeTS(physical, 0)
	if l.lastTimeStampTS == ts {
		l.n++
		return uint64(ts + l.n), nil
	}
	l.lastTimeStampTS = ts
	l.n = 0
	return uint64(ts), nil
}
예제 #3
0
파일: store_test.go 프로젝트: pingcap/tidb
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
}
예제 #4
0
파일: gc_worker.go 프로젝트: pingcap/tidb
// prepare checks required conditions for starting a GC job. It returns a bool
// that indicates whether the GC job should start and the new safePoint.
func (w *GCWorker) prepare() (bool, uint64, error) {
	now, err := w.getOracleTime()
	if err != nil {
		return false, 0, errors.Trace(err)
	}
	ok, err := w.checkGCInterval(now)
	if err != nil || !ok {
		return false, 0, errors.Trace(err)
	}
	newSafePoint, err := w.calculateNewSafePoint(now)
	if err != nil || newSafePoint == nil {
		return false, 0, errors.Trace(err)
	}
	err = w.saveTime(gcLastRunTimeKey, now)
	if err != nil {
		return false, 0, errors.Trace(err)
	}
	err = w.saveTime(gcSafePointKey, *newSafePoint)
	if err != nil {
		return false, 0, errors.Trace(err)
	}
	return true, oracle.ComposeTS(oracle.GetPhysical(*newSafePoint), 0), nil
}