txnsnapshot

package
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 26 Imported by: 20

Documentation

Index

Constants

View Source
const (
	// DefaultScanBatchSize is the default scan batch size.
	DefaultScanBatchSize = 256
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientHelper

type ClientHelper struct {
	locate.RegionRequestRuntimeStats
	// contains filtered or unexported fields
}

ClientHelper wraps LockResolver and RegionRequestSender. It's introduced to support the new lock resolving pattern in the large transaction. In the large transaction protocol, sending requests and resolving locks are context-dependent. For example, when a send request meets a secondary lock, we'll call ResolveLock, and if the lock belongs to a large transaction, we may retry the request. If there is no context information about the resolved locks, we'll meet the secondary lock again and run into a deadloop.

ClientHelper is only used for read operations because these optimizations don't apply to write operations.

func NewClientHelper

func NewClientHelper(store kvstore, resolvedLocks *util.TSSet, committedLocks *util.TSSet, resolveLite bool) *ClientHelper

NewClientHelper creates a helper instance.

func (*ClientHelper) RecordResolvingLocks added in v2.0.2

func (ch *ClientHelper) RecordResolvingLocks(locks []*txnlock.Lock, callerStartTS uint64) int

RecordResolvingLocks wraps the RecordResolvingLocks function

func (*ClientHelper) ResolveLocks

func (ch *ClientHelper) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*txnlock.Lock) (int64, error)

ResolveLocks wraps the ResolveLocks function and store the resolved result.

func (*ClientHelper) ResolveLocksDone added in v2.0.2

func (ch *ClientHelper) ResolveLocksDone(callerStartTS uint64, token int)

ResolveLocksDone wraps the ResolveLocksDone function

func (*ClientHelper) ResolveLocksWithOpts added in v2.0.2

func (ch *ClientHelper) ResolveLocksWithOpts(bo *retry.Backoffer, opts txnlock.ResolveLocksOptions) (txnlock.ResolveLockResult, error)

ResolveLocksWithOpts wraps the ResolveLocksWithOpts function and store the resolved result.

func (*ClientHelper) SendReqCtx

func (ch *ClientHelper) SendReqCtx(bo *retry.Backoffer, req *tikvrpc.Request, regionID locate.RegionVerID, timeout time.Duration, et tikvrpc.EndpointType, directStoreAddr string, opts ...locate.StoreSelectorOption) (*tikvrpc.Response, *locate.RPCContext, string, error)

SendReqCtx wraps the SendReqCtx function and use the resolved lock result in the kvrpcpb.Context.

func (*ClientHelper) UpdateResolvingLocks added in v2.0.2

func (ch *ClientHelper) UpdateResolvingLocks(locks []*txnlock.Lock, callerStartTS uint64, token int)

UpdateResolvingLocks wraps the UpdateResolvingLocks function

type ConfigProbe

type ConfigProbe struct{}

ConfigProbe exposes configurations and global variables for testing purpose.

func (ConfigProbe) GetGetMaxBackoff

func (c ConfigProbe) GetGetMaxBackoff() int

GetGetMaxBackoff returns the max sleep for get command.

func (ConfigProbe) GetScanBatchSize

func (c ConfigProbe) GetScanBatchSize() int

GetScanBatchSize returns the batch size to scan ranges.

type IsoLevel

type IsoLevel kvrpcpb.IsolationLevel

IsoLevel is the transaction's isolation level.

const (
	// SI stands for 'snapshot isolation'.
	SI IsoLevel = IsoLevel(kvrpcpb.IsolationLevel_SI)
	// RC stands for 'read committed'.
	RC IsoLevel = IsoLevel(kvrpcpb.IsolationLevel_RC)
	// RCCheckTS stands for 'read consistency' with ts check.
	RCCheckTS IsoLevel = IsoLevel(kvrpcpb.IsolationLevel_RCCheckTS)
)

func (IsoLevel) ToPB

func (l IsoLevel) ToPB() kvrpcpb.IsolationLevel

ToPB converts isolation level to wire type.

type KVSnapshot

type KVSnapshot struct {
	*util.RequestSource
	// contains filtered or unexported fields
}

KVSnapshot implements the tidbkv.Snapshot interface.

func NewTiKVSnapshot

func NewTiKVSnapshot(store kvstore, ts uint64, replicaReadSeed uint32) *KVSnapshot

NewTiKVSnapshot creates a snapshot of an TiKV store.

func (*KVSnapshot) AddRPCInterceptor

func (s *KVSnapshot) AddRPCInterceptor(it interceptor.RPCInterceptor)

AddRPCInterceptor adds an interceptor, the order of addition is the order of execution.

func (*KVSnapshot) BatchGet

func (s *KVSnapshot) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)

BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs. The map will not contain nonexistent keys. NOTE: Don't modify keys. Some codes rely on the order of keys.

func (*KVSnapshot) Get

func (s *KVSnapshot) Get(ctx context.Context, k []byte) ([]byte, error)

Get gets the value for key k from snapshot.

func (*KVSnapshot) Iter

func (s *KVSnapshot) Iter(k []byte, upperBound []byte) (unionstore.Iterator, error)

Iter return a list of key-value pair after `k`.

func (*KVSnapshot) IterReverse

func (s *KVSnapshot) IterReverse(k []byte) (unionstore.Iterator, error)

IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.

func (*KVSnapshot) SetIsStalenessReadOnly added in v2.0.2

func (s *KVSnapshot) SetIsStalenessReadOnly(b bool)

SetIsStalenessReadOnly indicates whether the transaction is staleness read only transaction

func (*KVSnapshot) SetIsolationLevel

func (s *KVSnapshot) SetIsolationLevel(level IsoLevel)

SetIsolationLevel sets the isolation level used to scan data from tikv.

func (*KVSnapshot) SetKeyOnly

func (s *KVSnapshot) SetKeyOnly(b bool)

SetKeyOnly indicates if tikv can return only keys.

func (*KVSnapshot) SetMatchStoreLabels

func (s *KVSnapshot) SetMatchStoreLabels(labels []*metapb.StoreLabel)

SetMatchStoreLabels sets up labels to filter target stores.

func (*KVSnapshot) SetNotFillCache

func (s *KVSnapshot) SetNotFillCache(b bool)

SetNotFillCache indicates whether tikv should skip filling cache when loading data.

func (*KVSnapshot) SetPriority

func (s *KVSnapshot) SetPriority(pri txnutil.Priority)

SetPriority sets the priority for tikv to execute commands.

func (*KVSnapshot) SetRPCInterceptor

func (s *KVSnapshot) SetRPCInterceptor(it interceptor.RPCInterceptor)

SetRPCInterceptor sets interceptor.RPCInterceptor for the snapshot. interceptor.RPCInterceptor will be executed before each RPC request is initiated. Note that SetRPCInterceptor will replace the previously set interceptor.

func (*KVSnapshot) SetReadReplicaScope

func (s *KVSnapshot) SetReadReplicaScope(scope string)

SetReadReplicaScope set read replica scope

func (*KVSnapshot) SetReplicaRead

func (s *KVSnapshot) SetReplicaRead(readType kv.ReplicaReadType)

SetReplicaRead sets up the replica read type.

func (*KVSnapshot) SetReplicaReadAdjuster added in v2.0.2

func (s *KVSnapshot) SetReplicaReadAdjuster(f ReplicaReadAdjuster)

SetReplicaReadAdjuster set replica read adjust function

func (*KVSnapshot) SetResourceGroupName added in v2.0.5

func (s *KVSnapshot) SetResourceGroupName(name string)

SetResourceGroupName set resource group name of the kv request.

func (*KVSnapshot) SetResourceGroupTag

func (s *KVSnapshot) SetResourceGroupTag(tag []byte)

SetResourceGroupTag sets resource group tag of the kv request.

func (*KVSnapshot) SetResourceGroupTagger

func (s *KVSnapshot) SetResourceGroupTagger(tagger tikvrpc.ResourceGroupTagger)

SetResourceGroupTagger sets resource group tagger of the kv request. Before sending the request, if resourceGroupTag is not nil, use resourceGroupTag directly, otherwise use resourceGroupTagger.

func (*KVSnapshot) SetRuntimeStats

func (s *KVSnapshot) SetRuntimeStats(stats *SnapshotRuntimeStats)

SetRuntimeStats sets the stats to collect runtime statistics. Set it to nil to clear stored stats.

func (*KVSnapshot) SetSampleStep

func (s *KVSnapshot) SetSampleStep(step uint32)

SetSampleStep skips 'step - 1' number of keys after each returned key.

func (*KVSnapshot) SetScanBatchSize

func (s *KVSnapshot) SetScanBatchSize(batchSize int)

SetScanBatchSize sets the scan batchSize used to scan data from tikv.

func (*KVSnapshot) SetSnapshotTS

func (s *KVSnapshot) SetSnapshotTS(ts uint64)

SetSnapshotTS resets the timestamp for reads.

func (*KVSnapshot) SetTaskID

func (s *KVSnapshot) SetTaskID(id uint64)

SetTaskID marks current task's unique ID to allow TiKV to schedule tasks more fairly.

func (*KVSnapshot) SetTxnScope

func (s *KVSnapshot) SetTxnScope(scope string)

SetTxnScope is same as SetReadReplicaScope, keep it in order to keep compatible for now.

func (*KVSnapshot) SetVars

func (s *KVSnapshot) SetVars(vars *kv.Variables)

SetVars sets variables to the transaction.

func (*KVSnapshot) SnapCacheHitCount

func (s *KVSnapshot) SnapCacheHitCount() int

SnapCacheHitCount gets the snapshot cache hit count. Only for test.

func (*KVSnapshot) SnapCacheSize

func (s *KVSnapshot) SnapCacheSize() int

SnapCacheSize gets the snapshot cache size. Only for test.

type ReplicaReadAdjuster added in v2.0.2

type ReplicaReadAdjuster func(int) (locate.StoreSelectorOption, kv.ReplicaReadType)

ReplicaReadAdjuster is a function that adjust the StoreSelectorOption and ReplicaReadType based on the keys count for BatchPointGet and PointGet

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner support tikv scan

func (*Scanner) Close

func (s *Scanner) Close()

Close close iterator.

func (*Scanner) Key

func (s *Scanner) Key() []byte

Key return key.

func (*Scanner) Next

func (s *Scanner) Next() error

Next return next element.

func (*Scanner) Valid

func (s *Scanner) Valid() bool

Valid return valid.

func (*Scanner) Value

func (s *Scanner) Value() []byte

Value return value.

type SnapshotProbe

type SnapshotProbe struct {
	*KVSnapshot
}

SnapshotProbe exposes some snapshot utilities for testing purpose.

func (SnapshotProbe) BatchGetSingleRegion

func (s SnapshotProbe) BatchGetSingleRegion(bo *retry.Backoffer, region locate.RegionVerID, keys [][]byte, collectF func(k, v []byte)) error

BatchGetSingleRegion gets a batch of keys from a region.

func (SnapshotProbe) FormatStats

func (s SnapshotProbe) FormatStats() string

FormatStats dumps information of stats.

func (SnapshotProbe) MergeExecDetail

func (s SnapshotProbe) MergeExecDetail(detail *kvrpcpb.ExecDetailsV2)

MergeExecDetail merges exec stats into snapshot's stats.

func (SnapshotProbe) MergeRegionRequestStats

func (s SnapshotProbe) MergeRegionRequestStats(stats map[tikvrpc.CmdType]*locate.RPCRuntimeStats)

MergeRegionRequestStats merges RPC runtime stats into snapshot's stats.

func (SnapshotProbe) NewScanner

func (s SnapshotProbe) NewScanner(start, end []byte, batchSize int, reverse bool) (*Scanner, error)

NewScanner returns a scanner to iterate given key range.

func (SnapshotProbe) RecordBackoffInfo

func (s SnapshotProbe) RecordBackoffInfo(bo *retry.Backoffer)

RecordBackoffInfo records backoff stats into snapshot's stats.

type SnapshotRuntimeStats

type SnapshotRuntimeStats struct {
	// contains filtered or unexported fields
}

SnapshotRuntimeStats records the runtime stats of snapshot.

func (*SnapshotRuntimeStats) Clone

Clone implements the RuntimeStats interface.

func (*SnapshotRuntimeStats) Merge

func (rs *SnapshotRuntimeStats) Merge(other *SnapshotRuntimeStats)

Merge implements the RuntimeStats interface.

func (*SnapshotRuntimeStats) String

func (rs *SnapshotRuntimeStats) String() string

String implements fmt.Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL