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

store/tikv: remove use of ReplicaRead transaction option in store/tikv #24409

Merged
merged 9 commits into from
May 12, 2021
2 changes: 2 additions & 0 deletions store/driver/txn/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (s *tikvSnapshot) SetOption(opt int, val interface{}) {
s.KVSnapshot.SetNotFillCache(val.(bool))
case tikvstore.SnapshotTS:
s.KVSnapshot.SetSnapshotTS(val.(uint64))
case tikvstore.ReplicaRead:
s.KVSnapshot.SetReplicaRead(val.(tikvstore.ReplicaReadType))
Copy link
Member

Choose a reason for hiding this comment

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

may we meet a bug that the opt is ReplicaRead but the val is another type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true. What I've done so far is just make sure to avoid type conversions in client go. To tweak the whole TiDB code would involve extending the kv.Transaction interface, which has too much impact.

case tikvstore.TaskID:
s.KVSnapshot.SetTaskID(val.(uint64))
default:
Expand Down
2 changes: 2 additions & 0 deletions store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) {
txn.SetPessimistic(val.(bool))
case tikvstore.SnapshotTS:
txn.KVTxn.GetSnapshot().SetSnapshotTS(val.(uint64))
case tikvstore.ReplicaRead:
txn.KVTxn.GetSnapshot().SetReplicaRead(val.(tikvstore.ReplicaReadType))
case tikvstore.TaskID:
txn.KVTxn.GetSnapshot().SetTaskID(val.(uint64))
case tikvstore.InfoSchema:
Expand Down
15 changes: 7 additions & 8 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,6 @@ func (s *KVSnapshot) IterReverse(k []byte) (unionstore.Iterator, error) {
// value of this option. Only ReplicaRead is supported for snapshot
func (s *KVSnapshot) SetOption(opt int, val interface{}) {
switch opt {
case kv.ReplicaRead:
s.mu.Lock()
s.mu.replicaRead = val.(kv.ReplicaReadType)
s.mu.Unlock()
case kv.CollectRuntimeStats:
s.mu.Lock()
s.mu.stats = val.(*SnapshotRuntimeStats)
Expand All @@ -589,10 +585,6 @@ func (s *KVSnapshot) SetOption(opt int, val interface{}) {
// DelOption deletes an option.
func (s *KVSnapshot) DelOption(opt int) {
switch opt {
case kv.ReplicaRead:
s.mu.Lock()
s.mu.replicaRead = kv.ReplicaReadLeader
s.mu.Unlock()
case kv.CollectRuntimeStats:
s.mu.Lock()
s.mu.stats = nil
Expand All @@ -611,6 +603,13 @@ func (s *KVSnapshot) SetKeyOnly(b bool) {
s.keyOnly = b
}

// SetReplicaRead sets up the replica read type.
func (s *KVSnapshot) SetReplicaRead(readType kv.ReplicaReadType) {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.replicaRead = readType
}

// SetIsolationLevel sets the isolation level used to scan data from tikv.
func (s *KVSnapshot) SetIsolationLevel(level IsoLevel) {
s.isolationLevel = level
Expand Down