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: add sanity check for snapshot version and forUpdateTS #20159

Merged
merged 7 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions store/tikv/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func (actionCommit) handleSingleBatch(c *twoPhaseCommitter, bo *Backoffer, batch
zap.Uint64("txnStartTS", c.startTS),
zap.Stringer("info", logutil.Hex(rejected)))

// Do not retry for a txn which has a too large MinCommitTs
// 3600000 << 18 = 943718400000
jackysp marked this conversation as resolved.
Show resolved Hide resolved
if rejected.MinCommitTs-rejected.AttemptedCommitTs > 943718400000 {
err := errors.Errorf("2PC MinCommitTS is too large, we got MinCommitTS: %d, and AttemptedCommitTS: %d",
rejected.MinCommitTs, rejected.AttemptedCommitTs)
return errors.Trace(err)
}

// Update commit ts and retry.
commitTS, err := c.store.getTimestampWithRetry(bo)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -83,6 +84,11 @@ type tikvSnapshot struct {

// newTiKVSnapshot creates a snapshot of an TiKV store.
func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) *tikvSnapshot {
// Sanity check for snapshot version.
if ver.Ver >= math.MaxInt64 && ver.Ver != math.MaxUint64 {
err := errors.Errorf("try to get snapshot with a large ts %d", ver.Ver)
panic(err)
}
return &tikvSnapshot{
store: store,
version: ver,
Expand All @@ -96,6 +102,11 @@ func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) *
}

func (s *tikvSnapshot) setSnapshotTS(ts uint64) {
// Sanity check for snapshot version.
if ts >= math.MaxInt64 && ts != math.MaxUint64 {
err := errors.Errorf("try to get snapshot with a large ts %d", ts)
panic(err)
}
// Invalidate cache if the snapshotTS change!
s.version.Ver = ts
s.mu.Lock()
Expand Down