Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add follower read support to TiDB #11347

Merged
merged 24 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
11f6f5e
Initial effort to add follower read to TiDB
sunxiaoguang Jul 20, 2019
ef3a32b
Add tests for replica read
sunxiaoguang Jul 23, 2019
8beffef
Merge branch 'master' into replica_read
sunxiaoguang Jul 23, 2019
013e0ca
Updated kvproto dependency and fixed a test
sunxiaoguang Jul 23, 2019
7277838
Add more tests
sunxiaoguang Jul 23, 2019
31f1333
Merge branch 'master' of https://github.com/pingcap/tidb into replica…
sunxiaoguang Jul 24, 2019
c43f94b
Merge branch 'master' into replica_read
sunxiaoguang Jul 25, 2019
315aa95
Update kvproto
sunxiaoguang Jul 31, 2019
7bb7d76
Run go mod tidy
sunxiaoguang Aug 1, 2019
3c3f2e0
Merge branch 'master' into replica_read
sunxiaoguang Aug 1, 2019
f4d59d6
Merge branch 'master' into replica_read
sunxiaoguang Aug 2, 2019
237005e
Refactor interface between SQL and KV layers
sunxiaoguang Aug 2, 2019
136d760
Do not store index of followers in region cache
sunxiaoguang Aug 5, 2019
93c88d4
Use session scope coprocessor client
sunxiaoguang Aug 5, 2019
03c9576
Merge branch 'master' into replica_read
sunxiaoguang Aug 5, 2019
3968c6b
Try next follower if selected follower had failed
sunxiaoguang Aug 6, 2019
3bcd5c8
Handle failed follower when reading from it
sunxiaoguang Aug 10, 2019
1775d42
Merge branch 'master' into replica_read
sunxiaoguang Aug 11, 2019
13065e8
Merge branch 'master' into replica_read
sunxiaoguang Aug 11, 2019
39c9add
Merge branch 'master' into replica_read
coocood Aug 12, 2019
d3b64ce
Merge branch 'master' of https://github.com/pingcap/tidb into replica…
sunxiaoguang Aug 13, 2019
b03c2d9
Merge branch 'master' into replica_read
sunxiaoguang Aug 14, 2019
682333a
Assign different replica read seeds to snapshots
sunxiaoguang Aug 15, 2019
b0bf2a3
Merge branch 'master' into replica_read
sre-bot Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (s *tikvStore) Begin() (kv.Transaction, error) {

// BeginWithStartTS begins a transaction with startTS.
func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {
txn, err := newTikvTxnWithStartTS(s, startTS)
txn, err := newTikvTxnWithStartTS(s, startTS, s.nextReplicaReadSeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will make ReadSeed be changed for each txn in same session, it seem conflict to #11347 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it seems to be complicated to make it consistent over txn and coprocessor. And the whole discussion would be more efficient over instant messaging, therefore we had some discussion on WeChat group and agreed that we can use different policy for coprocessor and txn. Sorry for not giving out the context and clue about it here.

if err != nil {
return nil, errors.Trace(err)
}
Expand All @@ -277,7 +277,7 @@ func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {
}

func (s *tikvStore) GetSnapshot(ver kv.Version) (kv.Snapshot, error) {
snapshot := newTiKVSnapshot(s, ver)
snapshot := newTiKVSnapshot(s, ver, s.nextReplicaReadSeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

metrics.TiKVSnapshotCounter.Inc()
return snapshot, nil
}
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *testLockSuite) TestScanLockResolveWithBatchGet(c *C) {

ver, err := s.store.CurrentVersion()
c.Assert(err, IsNil)
snapshot := newTiKVSnapshot(s.store, ver)
snapshot := newTiKVSnapshot(s.store, ver, 0)
m, err := snapshot.BatchGet(context.Background(), keys)
c.Assert(err, IsNil)
c.Assert(len(m), Equals, int('z'-'a'+1))
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/safepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) {

s.waitUntilErrorPlugIn(txn4.startTS)

snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn4.StartTS()})
snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn4.StartTS()}, 0)
_, batchgeterr := snapshot.BatchGet(context.Background(), keys)
c.Assert(batchgeterr, NotNil)
isFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrGCTooEarly)
Expand Down
4 changes: 2 additions & 2 deletions store/tikv/scan_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *testScanMockSuite) TestScanMultipleRegions(c *C) {

txn, err = store.Begin()
c.Assert(err, IsNil)
snapshot := newTiKVSnapshot(store, kv.Version{Ver: txn.StartTS()})
snapshot := newTiKVSnapshot(store, kv.Version{Ver: txn.StartTS()}, 0)
scanner, err := newScanner(snapshot, []byte("a"), nil, 10, false)
c.Assert(err, IsNil)
for ch := byte('a'); ch <= byte('z'); ch++ {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *testScanMockSuite) TestReverseScan(c *C) {

txn, err = store.Begin()
c.Assert(err, IsNil)
snapshot := newTiKVSnapshot(store, kv.Version{Ver: txn.StartTS()})
snapshot := newTiKVSnapshot(store, kv.Version{Ver: txn.StartTS()}, 0)
scanner, err := newScanner(snapshot, nil, []byte("z"), 10, true)
c.Assert(err, IsNil)
for ch := byte('y'); ch >= byte('a'); ch-- {
Expand Down
11 changes: 6 additions & 5 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ type tikvSnapshot struct {
}

// newTiKVSnapshot creates a snapshot of an TiKV store.
func newTiKVSnapshot(store *tikvStore, ver kv.Version) *tikvSnapshot {
func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) *tikvSnapshot {
return &tikvSnapshot{
store: store,
version: ver,
priority: pb.CommandPri_Normal,
vars: kv.DefaultVars,
store: store,
version: ver,
priority: pb.CommandPri_Normal,
vars: kv.DefaultVars,
replicaReadSeed: replicaReadSeed,
}
}

Expand Down
2 changes: 1 addition & 1 deletion store/tikv/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *testSnapshotSuite) beginTxn(c *C) *tikvTxn {

func (s *testSnapshotSuite) checkAll(keys []kv.Key, c *C) {
txn := s.beginTxn(c)
snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn.StartTS()})
snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn.StartTS()}, 0)
m, err := snapshot.BatchGet(context.Background(), keys)
c.Assert(err, IsNil)

Expand Down
2 changes: 1 addition & 1 deletion store/tikv/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *testSplitSuite) TestSplitBatchGet(c *C) {
c.Assert(err, IsNil)

txn := s.begin(c)
snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn.StartTS()})
snapshot := newTiKVSnapshot(s.store, kv.Version{Ver: txn.StartTS()}, 0)

keys := [][]byte{{'a'}, {'b'}, {'c'}}
_, region, err := s.store.regionCache.GroupKeysByRegion(s.bo, keys)
Expand Down
6 changes: 3 additions & 3 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ func newTiKVTxn(store *tikvStore) (*tikvTxn, error) {
if err != nil {
return nil, errors.Trace(err)
}
return newTikvTxnWithStartTS(store, startTS)
return newTikvTxnWithStartTS(store, startTS, store.nextReplicaReadSeed())
}

// newTikvTxnWithStartTS creates a txn with startTS.
func newTikvTxnWithStartTS(store *tikvStore, startTS uint64) (*tikvTxn, error) {
func newTikvTxnWithStartTS(store *tikvStore, startTS uint64, replicaReadSeed uint32) (*tikvTxn, error) {
ver := kv.NewVersion(startTS)
snapshot := newTiKVSnapshot(store, ver)
snapshot := newTiKVSnapshot(store, ver, replicaReadSeed)
return &tikvTxn{
snapshot: snapshot,
us: kv.NewUnionStore(snapshot),
Expand Down