Skip to content

Commit e90804f

Browse files
zimulalatiancaiamao
authored andcommitted
doamin: fix GetSnapshotInfoSchema using current TS (#10309)
1 parent 52e6744 commit e90804f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

domain/domain.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,10 @@ func isTooOldSchema(usedVersion, newVersion int64) bool {
218218
// The second returned value is the delta updated table IDs.
219219
func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64) (bool, []int64, error) {
220220
// If there isn't any used version, or used version is too old, we do full load.
221+
// And when users use history read feature, we will set usedVersion to initialVersion, then full load is needed.
221222
if isTooOldSchema(usedVersion, newVersion) {
222223
return false, nil, nil
223224
}
224-
if usedVersion > newVersion {
225-
// When user use History Read feature, history schema will be loaded.
226-
// usedVersion may be larger than newVersion, full load is needed.
227-
return false, nil, nil
228-
}
229225
var diffs []*model.SchemaDiff
230226
for usedVersion < newVersion {
231227
usedVersion++
@@ -260,7 +256,8 @@ func (do *Domain) InfoSchema() infoschema.InfoSchema {
260256
// GetSnapshotInfoSchema gets a snapshot information schema.
261257
func (do *Domain) GetSnapshotInfoSchema(snapshotTS uint64) (infoschema.InfoSchema, error) {
262258
snapHandle := do.infoHandle.EmptyClone()
263-
_, _, _, err := do.loadInfoSchema(snapHandle, do.infoHandle.Get().SchemaMetaVersion(), snapshotTS)
259+
// For the snapHandle, it's an empty Handle, so its usedSchemaVersion is initialVersion.
260+
_, _, _, err := do.loadInfoSchema(snapHandle, initialVersion, snapshotTS)
264261
if err != nil {
265262
return nil, err
266263
}

domain/domain_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/pingcap/parser/mysql"
2727
"github.com/pingcap/tidb/metrics"
2828
"github.com/pingcap/tidb/store/mockstore"
29+
"github.com/pingcap/tidb/store/tikv/oracle"
2930
"github.com/pingcap/tidb/util/mock"
3031
"github.com/pingcap/tidb/util/testleak"
3132
dto "github.com/prometheus/client_model/go"
@@ -63,6 +64,7 @@ func (*testSuite) TestT(c *C) {
6364
store = dom.Store()
6465
ctx := mock.NewContext()
6566
ctx.Store = store
67+
snapTS := oracle.EncodeTSO(oracle.GetPhysical(time.Now()))
6668
dd := dom.DDL()
6769
c.Assert(dd, NotNil)
6870
c.Assert(dd.GetLease(), Equals, 80*time.Millisecond)
@@ -78,6 +80,16 @@ func (*testSuite) TestT(c *C) {
7880
// for setting lease
7981
lease := 100 * time.Millisecond
8082

83+
// for GetSnapshotInfoSchema
84+
snapIs, err := dom.GetSnapshotInfoSchema(snapTS)
85+
c.Assert(err, IsNil)
86+
c.Assert(snapIs, NotNil)
87+
snapTS = oracle.EncodeTSO(oracle.GetPhysical(time.Now()))
88+
snapIs, err = dom.GetSnapshotInfoSchema(snapTS)
89+
c.Assert(err, IsNil)
90+
c.Assert(snapIs, NotNil)
91+
c.Assert(snapIs.SchemaMetaVersion(), Equals, is.SchemaMetaVersion())
92+
8193
// for schemaValidator
8294
schemaVer := dom.SchemaValidator.(*schemaValidator).latestSchemaVer
8395
ver, err := store.CurrentVersion()

0 commit comments

Comments
 (0)