Skip to content

Commit

Permalink
doamin: fix GetSnapshotInfoSchema using current TS (#10309)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and tiancaiamao committed Apr 30, 2019
1 parent 52e6744 commit e90804f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 3 additions & 6 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,10 @@ func isTooOldSchema(usedVersion, newVersion int64) bool {
// The second returned value is the delta updated table IDs.
func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64) (bool, []int64, error) {
// If there isn't any used version, or used version is too old, we do full load.
// And when users use history read feature, we will set usedVersion to initialVersion, then full load is needed.
if isTooOldSchema(usedVersion, newVersion) {
return false, nil, nil
}
if usedVersion > newVersion {
// When user use History Read feature, history schema will be loaded.
// usedVersion may be larger than newVersion, full load is needed.
return false, nil, nil
}
var diffs []*model.SchemaDiff
for usedVersion < newVersion {
usedVersion++
Expand Down Expand Up @@ -260,7 +256,8 @@ func (do *Domain) InfoSchema() infoschema.InfoSchema {
// GetSnapshotInfoSchema gets a snapshot information schema.
func (do *Domain) GetSnapshotInfoSchema(snapshotTS uint64) (infoschema.InfoSchema, error) {
snapHandle := do.infoHandle.EmptyClone()
_, _, _, err := do.loadInfoSchema(snapHandle, do.infoHandle.Get().SchemaMetaVersion(), snapshotTS)
// For the snapHandle, it's an empty Handle, so its usedSchemaVersion is initialVersion.
_, _, _, err := do.loadInfoSchema(snapHandle, initialVersion, snapshotTS)
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
dto "github.com/prometheus/client_model/go"
Expand Down Expand Up @@ -63,6 +64,7 @@ func (*testSuite) TestT(c *C) {
store = dom.Store()
ctx := mock.NewContext()
ctx.Store = store
snapTS := oracle.EncodeTSO(oracle.GetPhysical(time.Now()))
dd := dom.DDL()
c.Assert(dd, NotNil)
c.Assert(dd.GetLease(), Equals, 80*time.Millisecond)
Expand All @@ -78,6 +80,16 @@ func (*testSuite) TestT(c *C) {
// for setting lease
lease := 100 * time.Millisecond

// for GetSnapshotInfoSchema
snapIs, err := dom.GetSnapshotInfoSchema(snapTS)
c.Assert(err, IsNil)
c.Assert(snapIs, NotNil)
snapTS = oracle.EncodeTSO(oracle.GetPhysical(time.Now()))
snapIs, err = dom.GetSnapshotInfoSchema(snapTS)
c.Assert(err, IsNil)
c.Assert(snapIs, NotNil)
c.Assert(snapIs.SchemaMetaVersion(), Equals, is.SchemaMetaVersion())

// for schemaValidator
schemaVer := dom.SchemaValidator.(*schemaValidator).latestSchemaVer
ver, err := store.CurrentVersion()
Expand Down

0 comments on commit e90804f

Please sign in to comment.