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

Decouple the term TxnScope from the Stale Read code #31772

Closed
Tracked by #30535
JmPotato opened this issue Jan 18, 2022 · 1 comment · Fixed by #35877
Closed
Tracked by #30535

Decouple the term TxnScope from the Stale Read code #31772

JmPotato opened this issue Jan 18, 2022 · 1 comment · Fixed by #35877
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@JmPotato
Copy link
Member

Enhancement

Since the two features, Stale Read and Local Txn were developed together, the former borrows many of the concepts from the latter. TxnScope should be a term referring to the Global/Local Transaction scopes specifically. However, in the code of Stale Read, TxnScope is also used widely to indicate the TiKV locality, which brings some confusion into the code readability.

// Build builds a "kv.Request".
func (builder *RequestBuilder) Build() (*kv.Request, error) {
if builder.ReadReplicaScope == "" {
builder.ReadReplicaScope = kv.GlobalReplicaScope
}
if builder.ReplicaRead.IsClosestRead() && builder.ReadReplicaScope != kv.GlobalReplicaScope {
builder.MatchStoreLabels = []*metapb.StoreLabel{
{
Key: placement.DCLabelKey,
Value: builder.ReadReplicaScope,
},
}
}
failpoint.Inject("assertRequestBuilderReplicaOption", func(val failpoint.Value) {
assertScope := val.(string)
if builder.ReplicaRead.IsClosestRead() && assertScope != builder.ReadReplicaScope {
panic("request builder get staleness option fail")
}
})
err := builder.verifyTxnScope()
if err != nil {
builder.err = err
}
return &builder.Request, builder.err
}

We should decouple the TxnScope from the Stale Read code to make it more clear when we try to write some code that is related to the locality of the TiKV store.

@JmPotato JmPotato added the type/enhancement The issue or PR belongs to an enhancement. label Jan 18, 2022
@JmPotato
Copy link
Member Author

#30535 may fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant