Skip to content

Commit 8c07d0f

Browse files
Merge pull request pingcap#5 from PatrickNicholas/2020-hackathon
store: BatchGet read from local follower if keys excceds threshold
2 parents 5fc0756 + 938fc4f commit 8c07d0f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

sessionctx/variable/sysvar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ var defaultSysVars = []*SysVar{
638638
{Scope: ScopeGlobal | ScopeSession, Name: TiDBMemQuotaApplyCache, Value: strconv.Itoa(DefTiDBMemQuotaApplyCache)},
639639
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackoffLockFast, Value: strconv.Itoa(kv.DefBackoffLockFast), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64},
640640
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackOffWeight, Value: strconv.Itoa(kv.DefBackOffWeight), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64},
641-
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAdaptiveFollowerReadThreshold, Value: strconv.Itoa(kv.DefAdaptiveFollowerReadCostThreshold), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64}
641+
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAdaptiveFollowerReadThreshold, Value: strconv.Itoa(kv.DefAdaptiveFollowerReadThreshold), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64},
642642
{Scope: ScopeGlobal | ScopeSession, Name: TiDBRetryLimit, Value: strconv.Itoa(DefTiDBRetryLimit), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64},
643643
{Scope: ScopeGlobal | ScopeSession, Name: TiDBDisableTxnAutoRetry, Value: BoolToOnOff(DefTiDBDisableTxnAutoRetry), Type: TypeBool},
644644
{Scope: ScopeGlobal | ScopeSession, Name: TiDBConstraintCheckInPlace, Value: BoolToOnOff(DefTiDBConstraintCheckInPlace), Type: TypeBool},

store/tikv/snapshot.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ var (
4343
)
4444

4545
const (
46-
scanBatchSize = 256
47-
batchGetSize = 5120
46+
scanBatchSize = 256
47+
batchGetSize = 5120
48+
batchKeysThreshold = 10
4849
)
4950

5051
var (
@@ -281,11 +282,14 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll
281282
pending := batch.keys
282283
for {
283284
s.mu.RLock()
284-
// TODO(patrick) set recommend local scan for this request.
285+
recommendLocalRead := false
286+
if len(batch.keys) > batchKeysThreshold {
287+
recommendLocalRead = true
288+
}
285289
req := tikvrpc.NewReplicaReadRequest(tikvrpc.CmdBatchGet, &pb.BatchGetRequest{
286290
Keys: pending,
287291
Version: s.version.Ver,
288-
}, s.mu.replicaRead, &s.replicaReadSeed, false, pb.Context{
292+
}, s.mu.replicaRead, &s.replicaReadSeed, recommendLocalRead, pb.Context{
289293
Priority: s.priority,
290294
NotFillCache: s.notFillCache,
291295
TaskId: s.mu.taskID,

0 commit comments

Comments
 (0)