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 1 commit
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
Prev Previous commit
Next Next commit
add sanity check for snapshot version
Signed-off-by: you06 <you1474600@gmail.com>
  • Loading branch information
you06 committed Sep 27, 2020
commit ce984ba7ffd318ae9a5f83d0f4b4b13f1fdc3531
3 changes: 1 addition & 2 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {
}

func (s *tikvStore) GetSnapshot(ver kv.Version) (kv.Snapshot, error) {
snapshot := newTiKVSnapshot(s, ver, s.nextReplicaReadSeed())
return snapshot, nil
return newTiKVSnapshot(s, ver, s.nextReplicaReadSeed())
}

func (s *tikvStore) Close() error {
Expand Down
5 changes: 0 additions & 5 deletions store/tikv/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
"math"
)

// Scanner support tikv scan
Expand Down Expand Up @@ -160,10 +159,6 @@ func (s *Scanner) getData(bo *Backoffer) error {
zap.Stringer("nextEndKey", s.nextEndKey),
zap.Bool("reverse", s.reverse),
zap.Uint64("txnStartTS", s.startTS()))
if s.startTS() == math.MaxInt64 {
err := errors.Errorf("try to get data with invalid txnStartTS: %d", s.startTS())
return errors.Trace(err)
}
sender := NewRegionRequestSender(s.snapshot.store.regionCache, s.snapshot.store.client)
var reqEndKey, reqStartKey []byte
var loc *KeyLocation
Expand Down
10 changes: 8 additions & 2 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 @@ -82,7 +83,12 @@ type tikvSnapshot struct {
}

// newTiKVSnapshot creates a snapshot of an TiKV store.
func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) *tikvSnapshot {
func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) (*tikvSnapshot, error) {
// 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)
return nil, errors.Trace(err)
}
return &tikvSnapshot{
store: store,
version: ver,
Expand All @@ -92,7 +98,7 @@ func newTiKVSnapshot(store *tikvStore, ver kv.Version, replicaReadSeed uint32) *
minCommitTSPushed: minCommitTSPushed{
data: make(map[uint64]struct{}, 5),
},
}
}, nil
}

func (s *tikvSnapshot) setSnapshotTS(ts uint64) {
Expand Down
5 changes: 4 additions & 1 deletion store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func newTiKVTxn(store *tikvStore) (*tikvTxn, error) {
// newTikvTxnWithStartTS creates a txn with startTS.
func newTikvTxnWithStartTS(store *tikvStore, startTS uint64, replicaReadSeed uint32) (*tikvTxn, error) {
ver := kv.NewVersion(startTS)
snapshot := newTiKVSnapshot(store, ver, replicaReadSeed)
snapshot, err := newTiKVSnapshot(store, ver, replicaReadSeed)
if err != nil {
return nil, errors.Trace(err)
}
return &tikvTxn{
snapshot: snapshot,
us: kv.NewUnionStore(snapshot),
Expand Down