Skip to content

Commit 4d05a05

Browse files
MyonKemintaekexium
authored andcommitted
*: Update client-go and verify all read ts (pingcap#58054)
ref pingcap#57786
1 parent 272589d commit 4d05a05

File tree

15 files changed

+74
-25
lines changed

15 files changed

+74
-25
lines changed

DEPS.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,8 +4179,8 @@ def go_deps():
41794179
name = "com_github_tikv_client_go_v2",
41804180
build_file_proto_mode = "disable_global",
41814181
importpath = "github.com/tikv/client-go/v2",
4182-
sum = "h1:E+JsLmxpa4rsT0rS9m52+FhiiRbQxZYn079T4JD12jU=",
4183-
version = "v2.0.8-0.20241204085508-80a6b021f0f6",
4182+
sum = "h1:zrgHZRnd7Veio1Q+jV9LVa/JAfBi2Y7fGx91s7Uw+fo=",
4183+
version = "v2.0.8-0.20250108151910-7b4409c11946",
41844184
)
41854185
go_repository(
41864186
name = "com_github_tikv_pd",

ddl/column_change_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/pingcap/tidb/testkit"
3636
"github.com/pingcap/tidb/testkit/external"
3737
"github.com/pingcap/tidb/types"
38-
"github.com/pingcap/tidb/util/mock"
3938
"github.com/stretchr/testify/require"
4039
)
4140

executor/set.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres
198198
newSnapshotTS := getSnapshotTSByName()
199199
newSnapshotIsSet := newSnapshotTS > 0 && newSnapshotTS != oldSnapshotTS
200200
if newSnapshotIsSet {
201-
err = sessionctx.ValidateSnapshotReadTS(ctx, e.ctx.GetStore(), newSnapshotTS)
201+
isStaleRead := name == variable.TiDBTxnReadTS
202+
err = sessionctx.ValidateSnapshotReadTS(ctx, e.ctx.GetStore(), newSnapshotTS, isStaleRead)
202203
if name != variable.TiDBTxnReadTS {
203204
// Also check gc safe point for snapshot read.
204205
// We don't check snapshot with gc safe point for read_ts

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ require (
9494
github.com/stretchr/testify v1.8.2
9595
github.com/tdakkota/asciicheck v0.2.0
9696
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
97-
github.com/tikv/client-go/v2 v2.0.8-0.20241204085508-80a6b021f0f6
97+
github.com/tikv/client-go/v2 v2.0.8-0.20250108151910-7b4409c11946
9898
github.com/tikv/pd/client v0.0.0-20240725070735-fb162bf0aa3f
9999
github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e
100100
github.com/twmb/murmur3 v1.1.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf
968968
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
969969
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
970970
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
971-
github.com/tikv/client-go/v2 v2.0.8-0.20241204085508-80a6b021f0f6 h1:E+JsLmxpa4rsT0rS9m52+FhiiRbQxZYn079T4JD12jU=
972-
github.com/tikv/client-go/v2 v2.0.8-0.20241204085508-80a6b021f0f6/go.mod h1:45NuHB8x+VAoztMIjF6hEgXvPQXhXWPfMxDg0N8CoRY=
971+
github.com/tikv/client-go/v2 v2.0.8-0.20250108151910-7b4409c11946 h1:zrgHZRnd7Veio1Q+jV9LVa/JAfBi2Y7fGx91s7Uw+fo=
972+
github.com/tikv/client-go/v2 v2.0.8-0.20250108151910-7b4409c11946/go.mod h1:45NuHB8x+VAoztMIjF6hEgXvPQXhXWPfMxDg0N8CoRY=
973973
github.com/tikv/pd/client v0.0.0-20240725070735-fb162bf0aa3f h1:Szw9YxqGGEneSniBd4ep09jgB77cKUy+AuhKOmdGPdE=
974974
github.com/tikv/pd/client v0.0.0-20240725070735-fb162bf0aa3f/go.mod h1:QCBn54O5lhfkYfxj8Tyiqaxue/mthHEMyi7AqJP/+n4=
975975
github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e h1:MV6KaVu/hzByHP0UvJ4HcMGE/8a6A4Rggc/0wx2AvJo=

planner/core/planbuilder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,7 +3568,7 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
35683568
if err != nil {
35693569
return nil, err
35703570
}
3571-
if err := sessionctx.ValidateSnapshotReadTS(ctx, b.ctx.GetStore(), startTS); err != nil {
3571+
if err := sessionctx.ValidateSnapshotReadTS(ctx, b.ctx.GetStore(), startTS, true); err != nil {
35723572
return nil, err
35733573
}
35743574
p.StaleTxnStartTS = startTS
@@ -3582,7 +3582,7 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
35823582
if err != nil {
35833583
return nil, err
35843584
}
3585-
if err := sessionctx.ValidateSnapshotReadTS(ctx, b.ctx.GetStore(), startTS); err != nil {
3585+
if err := sessionctx.ValidateSnapshotReadTS(ctx, b.ctx.GetStore(), startTS, true); err != nil {
35863586
return nil, err
35873587
}
35883588
p.StaleTxnStartTS = startTS

sessionctx/context.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,12 @@ const (
219219
LastExecuteDDL basicCtxType = 3
220220
)
221221

222-
// ValidateSnapshotReadTS strictly validates that readTS does not exceed the PD timestamp
223-
func ValidateSnapshotReadTS(ctx context.Context, store kv.Storage, readTS uint64) error {
224-
return store.GetOracle().ValidateSnapshotReadTS(ctx, readTS, &oracle.Option{TxnScope: oracle.GlobalTxnScope})
222+
// ValidateSnapshotReadTS strictly validates that readTS does not exceed the PD timestamp.
223+
// For read requests to the storage, the check can be implicitly performed when sending the RPC request. So this
224+
// function is only needed when it's not proper to delay the check to when RPC requests are being sent (e.g., `BEGIN`
225+
// statements that don't make reading operation immediately).
226+
func ValidateSnapshotReadTS(ctx context.Context, store kv.Storage, readTS uint64, isStaleRead bool) error {
227+
return store.GetOracle().ValidateReadTS(ctx, readTS, isStaleRead, &oracle.Option{TxnScope: oracle.GlobalTxnScope})
225228
}
226229

227230
// SysProcTracker is used to track background sys processes

sessiontxn/staleread/processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func parseAndValidateAsOf(ctx context.Context, sctx sessionctx.Context, asOf *as
285285
return 0, err
286286
}
287287

288-
if err = sessionctx.ValidateSnapshotReadTS(ctx, sctx.GetStore(), ts); err != nil {
288+
if err = sessionctx.ValidateSnapshotReadTS(ctx, sctx.GetStore(), ts, true); err != nil {
289289
return 0, err
290290
}
291291

sessiontxn/staleread/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func CalculateTsWithReadStaleness(ctx context.Context, sctx sessionctx.Context,
8484
// If the final calculated exceeds the min safe ts, we are not sure whether the ts is safe to read (note that
8585
// reading with a ts larger than PD's max allocated ts + 1 is unsafe and may break linearizability).
8686
// So in this case, do an extra check on it.
87-
err = sessionctx.ValidateSnapshotReadTS(ctx, sctx.GetStore(), readTS)
87+
err = sessionctx.ValidateSnapshotReadTS(ctx, sctx.GetStore(), readTS, true)
8888
if err != nil {
8989
return 0, err
9090
}

store/copr/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ go_library(
5151
"@com_github_tikv_client_go_v2//config",
5252
"@com_github_tikv_client_go_v2//error",
5353
"@com_github_tikv_client_go_v2//metrics",
54+
"@com_github_tikv_client_go_v2//oracle",
5455
"@com_github_tikv_client_go_v2//tikv",
5556
"@com_github_tikv_client_go_v2//tikvrpc",
5657
"@com_github_tikv_client_go_v2//txnkv/txnlock",

0 commit comments

Comments
 (0)