-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: implement non-block reading for Get and BatchGet under the large transaction protocol #13599
Changes from 4 commits
5747c2d
c6f05e8
f34438b
ed0ae66
2eee19b
384843f
42b4e04
f3fe410
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -61,6 +61,7 @@ type tikvSnapshot struct { | |||
vars *kv.Variables | ||||
replicaRead kv.ReplicaReadType | ||||
replicaReadSeed uint32 | ||||
minCommitTSPushed | ||||
|
||||
// Cache the result of BatchGet. | ||||
// The invariance is that calling BatchGet multiple times using the same start ts, | ||||
|
@@ -80,13 +81,18 @@ func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) * | |||
priority: pb.CommandPri_Normal, | ||||
vars: kv.DefaultVars, | ||||
replicaReadSeed: replicaReadSeed, | ||||
minCommitTSPushed: minCommitTSPushed{ | ||||
data: make(map[uint64]struct{}, 5), | ||||
}, | ||||
} | ||||
} | ||||
|
||||
func (s *tikvSnapshot) setSnapshotTS(ts uint64) { | ||||
// Invalidate cache if the snapshotTS change! | ||||
s.version.Ver = ts | ||||
s.cached = nil | ||||
// And also the minCommitTS pushed information. | ||||
s.minCommitTSPushed.data = make(map[uint64]struct{}, 5) | ||||
} | ||||
|
||||
// BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs. | ||||
|
@@ -191,7 +197,12 @@ func (s *tikvSnapshot) batchGetKeysByRegions(bo *Backoffer, keys [][]byte, colle | |||
} | ||||
|
||||
func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, collectF func(k, v []byte)) error { | ||||
sender := NewRegionRequestSender(s.store.regionCache, s.store.client) | ||||
cli := clientHelper{ | ||||
LockResolver: s.store.lockResolver, | ||||
RegionCache: s.store.regionCache, | ||||
minCommitTSPushed: &s.minCommitTSPushed, | ||||
Client: s.store.client, | ||||
} | ||||
|
||||
pending := batch.keys | ||||
for { | ||||
|
@@ -202,7 +213,9 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll | |||
Priority: s.priority, | ||||
NotFillCache: s.notFillCache, | ||||
}) | ||||
resp, err := sender.SendReq(bo, req, batch.region, ReadTimeoutMedium) | ||||
|
||||
resp, _, _, err := cli.SendReqCtx(bo, req, batch.region, ReadTimeoutMedium, kv.TiKV) | ||||
|
||||
if err != nil { | ||||
return errors.Trace(err) | ||||
} | ||||
|
@@ -240,7 +253,7 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll | |||
locks = append(locks, lock) | ||||
} | ||||
if len(lockedKeys) > 0 { | ||||
msBeforeExpired, _, err := s.store.lockResolver.ResolveLocks(bo, s.version.Ver, locks) | ||||
msBeforeExpired, err := cli.ResolveLocks(bo, s.version.Ver, locks) | ||||
if err != nil { | ||||
return errors.Trace(err) | ||||
} | ||||
|
@@ -285,10 +298,17 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) { | |||
} | ||||
|
||||
failpoint.Inject("snapshot-get-cache-fail", func(_ failpoint.Value) { | ||||
panic("cache miss") | ||||
if bo.ctx.Value("TestSnapshotCache") != nil { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe using exp like Line 601 in 2aa571b
failpoint.Value == true at here is more gofail idiom~
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the concurrent test environment, that mock panic may affect other tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we can pass a TS and panic on equal TS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||||
panic("cache miss") | ||||
} | ||||
}) | ||||
|
||||
sender := NewRegionRequestSender(s.store.regionCache, s.store.client) | ||||
cli := clientHelper{ | ||||
LockResolver: s.store.lockResolver, | ||||
RegionCache: s.store.regionCache, | ||||
minCommitTSPushed: &s.minCommitTSPushed, | ||||
Client: s.store.client, | ||||
} | ||||
|
||||
req := tikvrpc.NewReplicaReadRequest(tikvrpc.CmdGet, | ||||
&pb.GetRequest{ | ||||
|
@@ -303,7 +323,7 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) { | |||
if err != nil { | ||||
return nil, errors.Trace(err) | ||||
} | ||||
resp, err := sender.SendReq(bo, req, loc.Region, readTimeoutShort) | ||||
resp, _, _, err := cli.SendReqCtx(bo, req, loc.Region, readTimeoutShort, kv.TiKV) | ||||
if err != nil { | ||||
return nil, errors.Trace(err) | ||||
} | ||||
|
@@ -328,7 +348,7 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) { | |||
if err != nil { | ||||
return nil, errors.Trace(err) | ||||
} | ||||
msBeforeExpired, _, err := s.store.lockResolver.ResolveLocks(bo, s.version.Ver, []*Lock{lock}) | ||||
msBeforeExpired, err := cli.ResolveLocks(bo, s.version.Ver, []*Lock{lock}) | ||||
if err != nil { | ||||
return nil, errors.Trace(err) | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this query use MaxTS?
Then we need also to cover PointGet with real TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done