Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Sep 11, 2018
1 parent aa77cac commit b95c69d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions domain/schema_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sync"
"time"

"github.com/pingcap/tidb/store/tikv/oracle"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -107,7 +108,7 @@ func (s *schemaValidator) Update(leaseGrantTS uint64, oldVer, currVer int64, cha

// Renew the lease.
s.latestSchemaVer = currVer
leaseGrantTime := extractPhysicalTime(leaseGrantTS)
leaseGrantTime := oracle.GetTimeFromTS(leaseGrantTS)
leaseExpire := leaseGrantTime.Add(s.lease - time.Millisecond)
s.latestSchemaExpire = leaseExpire

Expand Down Expand Up @@ -187,18 +188,13 @@ func (s *schemaValidator) Check(txnTS uint64, schemaVer int64, relatedTableIDs [
}

// Schema unchanged, maybe success or the schema validator is unavailable.
t := extractPhysicalTime(txnTS)
t := oracle.GetTimeFromTS(txnTS)
if t.After(s.latestSchemaExpire) {
return ResultUnknown
}
return ResultSucc
}

func extractPhysicalTime(ts uint64) time.Time {
t := int64(ts >> 18) // 18 is for the logical time.
return time.Unix(t/1e3, (t%1e3)*1e6)
}

func (s *schemaValidator) enqueue(schemaVersion int64, relatedTableIDs []int64) {
s.deltaSchemaInfos = append(s.deltaSchemaInfos, deltaSchemaInfo{schemaVersion, relatedTableIDs})
if len(s.deltaSchemaInfos) > maxNumberOfDiffsToLoad {
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func EncodeTSO(ts int64) uint64 {
// GetTimeFromTS extracts time.Time from a timestamp.
func GetTimeFromTS(ts uint64) time.Time {
ms := ExtractPhysical(ts)
return time.Unix(ms/1000, (ms%1000)*1e6)
return time.Unix(ms/1e3, (ms%1e3)*1e6)
}

0 comments on commit b95c69d

Please sign in to comment.