Documentation ¶
Index ¶
- Constants
- Variables
- func BackOff(attempts uint) int
- func GetDuplicateErrorHandleString(handle Handle) string
- func GetInt64(ctx context.Context, r Retriever, k Key) (int64, error)
- func GetInternalSourceType(ctx context.Context) string
- func GetMinInnerTxnStartTS(now time.Time, startTSLowerLimit uint64, curMinStartTS uint64) uint64
- func IncInt64(rm RetrieverMutator, k Key, step int64) (int64, error)
- func IsErrNotFound(err error) bool
- func IsTxnRetryableError(err error) bool
- func NextUntil(it Iterator, fn FnKeyCmp) error
- func PrintLongTimeInternalTxn(now time.Time, startTS uint64, runByFunction bool)
- func RunInNewTxn(ctx context.Context, store Storage, retryable bool, ...) error
- func SetCDCWriteSource(txnSource *uint64, value uint64) error
- func SetLossyDDLReorgSource(txnSource *uint64, value uint64) error
- func SetTxnResourceGroup(txn Transaction, name string)
- func WalkMemBuffer(memBuf Retriever, f func(k Key, v []byte) error) error
- type AssertionProto
- type BatchGetter
- type CancelMPPTasksParam
- type Client
- type ClientSendOption
- type CommonHandle
- func (ch *CommonHandle) Compare(h Handle) int
- func (ch *CommonHandle) Data() ([]types.Datum, error)
- func (ch *CommonHandle) Encoded() []byte
- func (ch *CommonHandle) EncodedCol(idx int) []byte
- func (ch *CommonHandle) Equal(h Handle) bool
- func (ch *CommonHandle) ExtraMemSize() uint64
- func (*CommonHandle) IntValue() int64
- func (*CommonHandle) IsInt() bool
- func (ch *CommonHandle) Len() int
- func (ch *CommonHandle) MemUsage() uint64
- func (ch *CommonHandle) Next() Handle
- func (ch *CommonHandle) NumCols() int
- func (ch *CommonHandle) String() string
- type CoprRequestAdjuster
- type DispatchMPPTaskParam
- type Driver
- type EmptyIterator
- type EmptyRetriever
- type Entry
- type EstablishMPPConnsParam
- type EtcdBackend
- type ExchangeCompressionMode
- type FairLockingController
- type FlagsOp
- type FnKeyCmp
- type Getter
- type Handle
- type HandleMap
- type InjectedSnapshot
- type InjectedStore
- type InjectedTransaction
- type InjectionConfig
- type IntHandle
- func (ih IntHandle) Compare(h Handle) int
- func (ih IntHandle) Data() ([]types.Datum, error)
- func (ih IntHandle) Encoded() []byte
- func (IntHandle) EncodedCol(_ int) []byte
- func (ih IntHandle) Equal(h Handle) bool
- func (IntHandle) ExtraMemSize() uint64
- func (ih IntHandle) IntValue() int64
- func (IntHandle) IsInt() bool
- func (IntHandle) Len() int
- func (IntHandle) MemUsage() uint64
- func (ih IntHandle) Next() Handle
- func (IntHandle) NumCols() int
- func (ih IntHandle) String() string
- type IsoLevel
- type Iterator
- type Key
- type KeyFlags
- func (f KeyFlags) HasAssertExists() bool
- func (f KeyFlags) HasAssertNotExists() bool
- func (f KeyFlags) HasAssertUnknown() bool
- func (f KeyFlags) HasAssertionFlags() bool
- func (f KeyFlags) HasNeedConstraintCheckInPrewrite() bool
- func (f KeyFlags) HasNeedLocked() bool
- func (f KeyFlags) HasPresumeKeyNotExists() bool
- type KeyRange
- type KeyRanges
- func (rr *KeyRanges) AppendSelfTo(ranges []KeyRange) []KeyRange
- func (rr *KeyRanges) FirstPartitionRange() []KeyRange
- func (rr *KeyRanges) ForEachPartition(theFunc func([]KeyRange))
- func (rr *KeyRanges) ForEachPartitionWithErr(theFunc func([]KeyRange, []int) error) (err error)
- func (rr *KeyRanges) IsFullySorted() bool
- func (rr *KeyRanges) PartitionNum() int
- func (rr *KeyRanges) SetToNonPartitioned() error
- func (rr *KeyRanges) SortByFunc(sortFunc func(i, j KeyRange) int)
- func (rr *KeyRanges) TotalRangeNum() int
- type LockCtx
- type MPPBuildTasksRequest
- type MPPClient
- type MPPDispatchRequest
- type MPPQueryID
- type MPPTask
- type MPPTaskMeta
- type MemAwareHandleMap
- type MemBuffer
- type MemManager
- type MppCoordinator
- type MppTaskStates
- type MppVersion
- type Mutator
- type PartitionHandle
- type PartitionIDAndRanges
- type ReplicaReadType
- type ReportStatusRequest
- type Request
- type RequestSource
- type RequestTypeSupportedChecker
- type Response
- type ResultSubset
- type Retriever
- type RetrieverMutator
- type Snapshot
- type SnapshotInterceptor
- type SplittableStore
- type StagingHandle
- type Storage
- type StorageWithPD
- type StoreType
- type Transaction
- type TxnScopeVar
- type Variables
- type Version
- type VersionProvider
Constants ¶
const ( ReqTypeSelect = 101 ReqTypeIndex = 102 ReqTypeDAG = 103 ReqTypeAnalyze = 104 ReqTypeChecksum = 105 ReqSubTypeBasic = 0 ReqSubTypeDesc = 10000 ReqSubTypeGroupBy = 10001 ReqSubTypeTopN = 10002 ReqSubTypeSignature = 10003 ReqSubTypeAnalyzeIdx = 10004 ReqSubTypeAnalyzeCol = 10005 )
ReqTypes.
const ( PriorityNormal = iota PriorityLow PriorityHigh )
Priority value for transaction priority.
const ( // MppVersionV0 supports TiFlash version [~, ~] MppVersionV0 MppVersion = iota // MppVersionV1 supports TiFlash version [v6.6.x, ~] MppVersionV1 // MppVersionV2 supports TiFlash version [v7.3, ~], support ReportMPPTaskStatus service MppVersionV2 // MppVersionUnspecified means the illegal or unspecified version, it only used in TiDB. MppVersionUnspecified MppVersion = -1 // MppVersionUnspecifiedName denotes name of UNSPECIFIED mpp version MppVersionUnspecifiedName string = "UNSPECIFIED" )
const ( // BinlogInfo contains the binlog data and client. BinlogInfo int = iota + 1 // SchemaChecker is used for checking schema-validity. SchemaChecker // IsolationLevel sets isolation level for current transaction. The default level is SI. IsolationLevel // Priority marks the priority of this transaction. Priority // NotFillCache makes this request do not touch the LRU cache of the underlying storage. NotFillCache // SyncLog is not used anymore. SyncLog // KeyOnly retrieve only keys, it can be used in scan now. KeyOnly // Pessimistic is defined for pessimistic lock Pessimistic // SnapshotTS is defined to set snapshot ts. SnapshotTS // ReplicaRead Set replica read ReplicaRead // TaskID Set task ID TaskID // InfoSchema is schema version used by txn startTS. InfoSchema // CollectRuntimeStats is used to enable collect runtime stats. CollectRuntimeStats // SchemaAmender is used to amend mutations for pessimistic transactions SchemaAmender // SampleStep skips 'SampleStep - 1' number of keys after each returned key. SampleStep // CommitHook is a callback function called right after the transaction gets committed CommitHook // EnableAsyncCommit indicates whether async commit is enabled EnableAsyncCommit // Enable1PC indicates whether one-phase commit is enabled Enable1PC // GuaranteeLinearizability indicates whether to guarantee linearizability at the cost of an extra tso request before prewrite GuaranteeLinearizability // TxnScope indicates which @@txn_scope this transaction will work with. TxnScope // ReadReplicaScope ReadReplicaScope // IsStalenessReadOnly indicates whether the transaction is staleness read only transaction IsStalenessReadOnly // MatchStoreLabels indicates the labels the store should be matched MatchStoreLabels // ResourceGroupTag indicates the resource group tag of the kv request. ResourceGroupTag // ResourceGroupTagger can be used to set the ResourceGroupTag dynamically according to the request content. It will be used only when ResourceGroupTag is nil. ResourceGroupTagger // KVFilter indicates the filter to ignore key-values in the transaction's memory buffer. KVFilter // SnapInterceptor is used for setting the interceptor for snapshot SnapInterceptor // CommitTSUpperBoundCheck is used by cached table // The commitTS must be greater than all the write lock lease of the visited cached table. CommitTSUpperBoundCheck // RPCInterceptor is interceptor.RPCInterceptor on Transaction or Snapshot, used to decorate // additional logic before and after the underlying client-go RPC request. RPCInterceptor // TableToColumnMaps is a map from tableID to a series of maps. The maps are needed when checking data consistency. // Save them here to reduce redundant computations. TableToColumnMaps // AssertionLevel controls how strict the assertions on data during transactions should be. AssertionLevel // RequestSourceInternal set request source scope of transaction. RequestSourceInternal // RequestSourceType set request source type of the current statement. RequestSourceType // ExplicitRequestSourceType is a complement of RequestSourceType, it may specified by the client or users. ExplicitRequestSourceType // ReplicaReadAdjuster set the adjust function of cop requests. ReplicaReadAdjuster // ScanBatchSize set the iter scan batch size. ScanBatchSize // TxnSource set the source of this transaction. // We use an uint64 to represent the source of a transaction. // The first 8 bits are reserved for TiCDC to implement BDR synchronization, // and the next 8 bits are reserved for Lossy DDL reorg Backfill job. // The remaining 48 bits are reserved for extendability. TxnSource // ResourceGroupName set the bind resource group name. ResourceGroupName // LoadBasedReplicaReadThreshold sets the TiKV wait duration threshold of enabling replica read automatically. LoadBasedReplicaReadThreshold // TiKVClientReadTimeout sets the timeout value for readonly kv request in milliseconds TiKVClientReadTimeout )
Transaction options
const ( // InternalTxnOthers is the type of requests that consume low resources. // This reduces the size of metrics. InternalTxnOthers = util.InternalTxnOthers // InternalTxnGC is the type of GC txn. InternalTxnGC = util.InternalTxnGC // InternalTxnBootstrap is the type of TiDB bootstrap txns. InternalTxnBootstrap = InternalTxnOthers // InternalTxnMeta is the type of the miscellaneous meta usage. InternalTxnMeta = util.InternalTxnMeta // InternalTxnDDL is the type of inner txns in ddl module. InternalTxnDDL = "ddl" // InternalTxnBackfillDDLPrefix is the prefix of the types of DDL operations needs backfilling. InternalTxnBackfillDDLPrefix = "ddl_" // InternalTxnCacheTable is the type of cache table usage. InternalTxnCacheTable = InternalTxnOthers // InternalTxnStats is the type of statistics txn. InternalTxnStats = "stats" // InternalTxnBindInfo is the type of bind info txn. InternalTxnBindInfo = InternalTxnOthers // InternalTxnSysVar is the type of sys var txn. InternalTxnSysVar = InternalTxnOthers // InternalTxnTelemetry is the type of telemetry. InternalTxnTelemetry = InternalTxnOthers // InternalTxnAdmin is the type of admin operations. InternalTxnAdmin = "admin" // InternalTxnPrivilege is the type of privilege txn. InternalTxnPrivilege = InternalTxnOthers // InternalTxnTools is the type of tools usage of TiDB. // Do not classify different tools by now. InternalTxnTools = "tools" // InternalTxnBR is the type of BR usage. InternalTxnBR = "br" // InternalTxnLightning is the type of Lightning usage. InternalTxnLightning = "lightning" // InternalTxnTrace handles the trace statement. InternalTxnTrace = "Trace" // InternalTxnTTL is the type of TTL usage InternalTxnTTL = "TTL" // InternalLoadData is the type of LOAD DATA usage InternalLoadData = "LoadData" // InternalImportInto is the type of IMPORT INTO usage InternalImportInto = "ImportInto" // InternalDistTask is the type of distributed task. InternalDistTask = "DistTask" // InternalTimer is the type of internal timer InternalTimer = "Timer" )
const ( // GlobalTxnScope is synced with PD's define of global scope. // If we want to remove the dependency on store/tikv here, we need to map // the two GlobalTxnScopes in the driver layer. GlobalTxnScope = oracle.GlobalTxnScope // LocalTxnScope indicates the transaction should use local ts. LocalTxnScope = "local" )
Transaction scopes constants.
const ( // GlobalReplicaScope indicates the default replica scope for tidb to request GlobalReplicaScope = oracle.GlobalTxnScope )
const (
LossyDDLColumnReorgSource = 1
)
The bitmap: |RESERVED|LOSSY_DDL_REORG_SOURCE_BITS|CDC_WRITE_SOURCE_BITS| | 48 | 8 | 4(RESERVED) | 4 |
const ( // TimeToPrintLongTimeInternalTxn is the duration if the internal transaction lasts more than it, // TiDB prints a log message. TimeToPrintLongTimeInternalTxn = time.Minute * 5 )
const TxnRetryableMark = "[try again later]"
TxnRetryableMark is used to uniform the commit error messages which could retry the transaction. *WARNING*: changing this string will affect the backward compatibility.
const UnCommitIndexKVFlag byte = '1'
UnCommitIndexKVFlag uses to indicate the index key/value is no need to commit. This is used in the situation of the index key/value was unchanged when do update. Usage: 1. For non-unique index: normally, the index value is '0'. Change the value to '1' indicate the index key/value is no need to commit. 2. For unique index: normally, the index value is the record handle ID, 8 bytes. Append UnCommitIndexKVFlag to the value indicate the index key/value is no need to commit.
Variables ¶
var ( // ErrNotExist is used when try to get an entry with an unexist key from KV store. ErrNotExist = dbterror.ClassKV.NewStd(mysql.ErrNotExist) // ErrTxnRetryable is used when KV store occurs retryable error which SQL layer can safely retry the transaction. // When using TiKV as the storage node, the error is returned ONLY when lock not found (txnLockNotFound) in Commit, // subject to change it in the future. ErrTxnRetryable = dbterror.ClassKV.NewStdErr( mysql.ErrTxnRetryable, pmysql.Message( mysql.MySQLErrName[mysql.ErrTxnRetryable].Raw+TxnRetryableMark, mysql.MySQLErrName[mysql.ErrTxnRetryable].RedactArgPos, ), ) // ErrCannotSetNilValue is the error when sets an empty value. ErrCannotSetNilValue = dbterror.ClassKV.NewStd(mysql.ErrCannotSetNilValue) // ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction. ErrInvalidTxn = dbterror.ClassKV.NewStd(mysql.ErrInvalidTxn) // ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value. ErrTxnTooLarge = dbterror.ClassKV.NewStd(mysql.ErrTxnTooLarge) // ErrEntryTooLarge is the error when a key value entry is too large. ErrEntryTooLarge = dbterror.ClassKV.NewStd(mysql.ErrEntryTooLarge) // ErrKeyExists returns when key is already exist. ErrKeyExists = dbterror.ClassKV.NewStd(mysql.ErrDupEntry) // ErrNotImplemented returns when a function is not implemented yet. ErrNotImplemented = dbterror.ClassKV.NewStd(mysql.ErrNotImplemented) // ErrWriteConflict is the error when the commit meets an write conflict error. ErrWriteConflict = dbterror.ClassKV.NewStdErr( mysql.ErrWriteConflict, pmysql.Message( mysql.MySQLErrName[mysql.ErrWriteConflict].Raw+" "+TxnRetryableMark, mysql.MySQLErrName[mysql.ErrWriteConflict].RedactArgPos, ), ) // ErrWriteConflictInTiDB is the error when the commit meets an write conflict error when local latch is enabled. ErrWriteConflictInTiDB = dbterror.ClassKV.NewStdErr( mysql.ErrWriteConflictInTiDB, pmysql.Message( mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].Raw+" "+TxnRetryableMark, mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].RedactArgPos, ), ) // ErrLockExpire is the error when the lock is expired. ErrLockExpire = dbterror.ClassTiKV.NewStd(mysql.ErrLockExpire) // ErrAssertionFailed is the error when an assertion fails. ErrAssertionFailed = dbterror.ClassTiKV.NewStd(mysql.ErrAssertionFailed) )
var ( // TxnEntrySizeLimit is limit of single entry size (len(key) + len(value)). TxnEntrySizeLimit uint64 = config.DefTxnEntrySizeLimit // TxnTotalSizeLimit is limit of the sum of all entry size. TxnTotalSizeLimit = atomic.NewUint64(config.DefTxnTotalSizeLimit) )
Those limits is enforced to make sure the transaction can be well handled by TiKV.
var ( // MaxVersion is the maximum version, notice that it's not a valid version. MaxVersion = Version{Ver: math.MaxUint64} // MinVersion is the minimum version, it's not a valid version, too. MinVersion = Version{Ver: 0} )
var RequestSourceKey = util.RequestSourceKey
RequestSourceKey is used as the key of request source type in context.
var WithInternalSourceAndTaskType = util.WithInternalSourceAndTaskType
WithInternalSourceAndTaskType create context with internal source and task name.
var WithInternalSourceType = util.WithInternalSourceType
WithInternalSourceType create context with internal source.
Functions ¶
func BackOff ¶
BackOff Implements exponential backoff with full jitter. Returns real back off time in microsecond. See http://www.awsarchitectureblog.com/2015/03/backoff.html.
func GetDuplicateErrorHandleString ¶
GetDuplicateErrorHandleString is used to concat the handle columns data with '-'. This is consistent with MySQL.
func GetInternalSourceType ¶
GetInternalSourceType get internal source
func GetMinInnerTxnStartTS ¶
GetMinInnerTxnStartTS get the min StartTS between startTSLowerLimit and curMinStartTS in globalInnerTxnTsBox.
func IncInt64 ¶
func IncInt64(rm RetrieverMutator, k Key, step int64) (int64, error)
IncInt64 increases the value for key k in kv store by step.
func IsErrNotFound ¶
IsErrNotFound checks if err is a kind of NotFound error.
func IsTxnRetryableError ¶
IsTxnRetryableError checks if the error could safely retry the transaction.
func NextUntil ¶
NextUntil applies FnKeyCmp to each entry of the iterator until meets some condition. It will stop when fn returns true, or iterator is invalid or an error occurs.
func PrintLongTimeInternalTxn ¶
PrintLongTimeInternalTxn print the internal transaction information. runByFunction true means the transaction is run by `RunInNewTxn`,
false means the transaction is run by internal session.
func RunInNewTxn ¶
func RunInNewTxn(ctx context.Context, store Storage, retryable bool, f func(ctx context.Context, txn Transaction) error) error
RunInNewTxn will run the f in a new transaction environment, should be used by inner txn only.
func SetCDCWriteSource ¶
SetCDCWriteSource sets the TiCDC write source in the txnSource.
func SetLossyDDLReorgSource ¶
SetLossyDDLReorgSource sets the lossy DDL reorg source in the txnSource.
func SetTxnResourceGroup ¶
func SetTxnResourceGroup(txn Transaction, name string)
SetTxnResourceGroup update the resource group name of target txn.
Types ¶
type AssertionProto ¶
type AssertionProto interface { // SetAssertion sets an assertion for an operation on the key. // TODO: Use a special type instead of `FlagsOp`. Otherwise there's risk that the assertion flag is incorrectly used // in other places like `MemBuffer.SetWithFlags`. SetAssertion(key []byte, assertion ...FlagsOp) error }
AssertionProto is an interface defined for the assertion protocol.
type BatchGetter ¶
type BatchGetter interface { // BatchGet gets a batch of values. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) }
BatchGetter is the interface for BatchGet.
type CancelMPPTasksParam ¶
type CancelMPPTasksParam struct { StoreAddr map[string]bool Reqs []*MPPDispatchRequest }
CancelMPPTasksParam represents parameter for MPPClient's CancelMPPTasks
type Client ¶
type Client interface { // Send sends request to KV layer, returns a Response. Send(ctx context.Context, req *Request, vars interface{}, option *ClientSendOption) Response // IsRequestTypeSupported checks if reqType and subType is supported. IsRequestTypeSupported(reqType, subType int64) bool }
Client is used to send request to KV layer.
type ClientSendOption ¶
type ClientSendOption struct { SessionMemTracker *memory.Tracker EnabledRateLimitAction bool EventCb trxevents.EventCallback EnableCollectExecutionInfo bool TiFlashReplicaRead tiflash.ReplicaRead AppendWarning func(warn error) }
ClientSendOption wraps options during Client Send
type CommonHandle ¶
type CommonHandle struct {
// contains filtered or unexported fields
}
CommonHandle implements the Handle interface for non-int64 type handle.
func NewCommonHandle ¶
func NewCommonHandle(encoded []byte) (*CommonHandle, error)
NewCommonHandle creates a CommonHandle from a encoded bytes which is encoded by code.EncodeKey.
func (*CommonHandle) Compare ¶
func (ch *CommonHandle) Compare(h Handle) int
Compare implements the Handle interface.
func (*CommonHandle) Data ¶
func (ch *CommonHandle) Data() ([]types.Datum, error)
Data implements the Handle interface.
func (*CommonHandle) Encoded ¶
func (ch *CommonHandle) Encoded() []byte
Encoded implements the Handle interface.
func (*CommonHandle) EncodedCol ¶
func (ch *CommonHandle) EncodedCol(idx int) []byte
EncodedCol implements the Handle interface.
func (*CommonHandle) Equal ¶
func (ch *CommonHandle) Equal(h Handle) bool
Equal implements the Handle interface.
func (*CommonHandle) ExtraMemSize ¶
func (ch *CommonHandle) ExtraMemSize() uint64
ExtraMemSize implements the Handle interface.
func (*CommonHandle) IntValue ¶
func (*CommonHandle) IntValue() int64
IntValue implements the Handle interface, not supported for CommonHandle type.
func (*CommonHandle) IsInt ¶
func (*CommonHandle) IsInt() bool
IsInt implements the Handle interface.
func (*CommonHandle) MemUsage ¶
func (ch *CommonHandle) MemUsage() uint64
MemUsage implements the Handle interface.
func (*CommonHandle) Next ¶
func (ch *CommonHandle) Next() Handle
Next implements the Handle interface. Note that the returned encoded field is not guaranteed to be able to decode.
func (*CommonHandle) NumCols ¶
func (ch *CommonHandle) NumCols() int
NumCols implements the Handle interface.
func (*CommonHandle) String ¶
func (ch *CommonHandle) String() string
String implements the Handle interface.
type CoprRequestAdjuster ¶
CoprRequestAdjuster is used to check and adjust a copr request according to specific rules. return true if the request is changed.
type DispatchMPPTaskParam ¶
type DispatchMPPTaskParam struct { Ctx context.Context Req *MPPDispatchRequest EnableCollectExecutionInfo bool Bo *tikv.Backoffer }
DispatchMPPTaskParam represents parameter for MPPClient's DispatchMPPTask
type Driver ¶
type Driver interface { // Open returns a new Storage. // The path is the string for storage specific format. Open(path string) (Storage, error) }
Driver is the interface that must be implemented by a KV storage.
type EmptyIterator ¶
type EmptyIterator struct{}
EmptyIterator is an iterator without any entry
func (*EmptyIterator) Key ¶
func (*EmptyIterator) Key() Key
Key returns the current key. Always return nil for this iterator
func (*EmptyIterator) Next ¶
func (*EmptyIterator) Next() error
Next goes the next position. Always return error for this iterator
func (*EmptyIterator) Valid ¶
func (*EmptyIterator) Valid() bool
Valid returns true if the current iterator is valid.
func (*EmptyIterator) Value ¶
func (*EmptyIterator) Value() []byte
Value returns the current value. Always return nil for this iterator
type EmptyRetriever ¶
type EmptyRetriever struct{}
EmptyRetriever is a retriever without any entry
func (*EmptyRetriever) Get ¶
Get gets the value for key k from kv store. Always return nil for this retriever
func (*EmptyRetriever) Iter ¶
func (*EmptyRetriever) Iter(_ Key, _ Key) (Iterator, error)
Iter creates an Iterator. Always return EmptyIterator for this retriever
func (*EmptyRetriever) IterReverse ¶
func (*EmptyRetriever) IterReverse(_ Key, _ Key) (Iterator, error)
IterReverse creates a reversed Iterator. Always return EmptyIterator for this retriever
type EstablishMPPConnsParam ¶
type EstablishMPPConnsParam struct { Ctx context.Context Req *MPPDispatchRequest TaskMeta *mpp.TaskMeta }
EstablishMPPConnsParam represents parameter for MPPClient's EstablishMPPConns
type EtcdBackend ¶
type EtcdBackend interface { EtcdAddrs() ([]string, error) TLSConfig() *tls.Config StartGCWorker() error }
EtcdBackend is used for judging a storage is a real TiKV.
type ExchangeCompressionMode ¶
type ExchangeCompressionMode int
ExchangeCompressionMode means the compress method used in exchange operator
const ( // ExchangeCompressionModeNONE indicates no compression ExchangeCompressionModeNONE ExchangeCompressionMode = iota // ExchangeCompressionModeFast indicates fast compression/decompression speed, compression ratio is lower than HC mode ExchangeCompressionModeFast // ExchangeCompressionModeHC indicates high compression (HC) ratio mode ExchangeCompressionModeHC // ExchangeCompressionModeUnspecified indicates unspecified compress method, let TiDB choose one ExchangeCompressionModeUnspecified // RecommendedExchangeCompressionMode indicates recommended compression mode RecommendedExchangeCompressionMode ExchangeCompressionMode = ExchangeCompressionModeFast )
func ToExchangeCompressionMode ¶
func ToExchangeCompressionMode(name string) (ExchangeCompressionMode, bool)
ToExchangeCompressionMode returns the ExchangeCompressionMode from name
func (ExchangeCompressionMode) Name ¶
func (t ExchangeCompressionMode) Name() string
Name returns the name of ExchangeCompressionMode
func (ExchangeCompressionMode) ToTipbCompressionMode ¶
func (t ExchangeCompressionMode) ToTipbCompressionMode() tipb.CompressionMode
ToTipbCompressionMode returns tipb.CompressionMode from kv.ExchangeCompressionMode
type FairLockingController ¶
type FairLockingController interface { StartFairLocking() error RetryFairLocking(ctx context.Context) error CancelFairLocking(ctx context.Context) error DoneFairLocking(ctx context.Context) error IsInFairLockingMode() bool }
FairLockingController is the interface that defines fair locking related operations.
type FlagsOp ¶
type FlagsOp uint16
FlagsOp describes KeyFlags modify operation.
const ( // SetPresumeKeyNotExists marks the existence of the associated key is checked lazily. SetPresumeKeyNotExists FlagsOp = iota // SetNeedLocked marks the associated key need to be acquired lock. SetNeedLocked // SetAssertExist marks the associated key must exist. SetAssertExist // SetAssertNotExist marks the associated key must not exists. SetAssertNotExist // SetAssertUnknown marks the associated key is unknown and can not apply other assertion. SetAssertUnknown // SetAssertNone marks the associated key without any assert. SetAssertNone // SetNeedConstraintCheckInPrewrite sets the flag flagNeedConstraintCheckInPrewrite SetNeedConstraintCheckInPrewrite // SetPreviousPresumeKeyNotExists marks the PNE flag is set in previous statements, thus it cannot be unset when // retrying or rolling back a statement. SetPreviousPresumeKeyNotExists )
type Getter ¶
type Getter interface { // Get gets the value for key k from kv store. // If corresponding kv pair does not exist, it returns nil and ErrNotExist. Get(ctx context.Context, k Key) ([]byte, error) }
Getter is the interface for the Get method.
type Handle ¶
type Handle interface { // IsInt returns if the handle type is int64. IsInt() bool // IntValue returns the int64 value if IsInt is true, it panics if IsInt returns false. IntValue() int64 // Next returns the minimum handle that is greater than this handle. // The returned handle is not guaranteed to be able to decode. Next() Handle // Equal returns if the handle equals to another handle, it panics if the types are different. Equal(h Handle) bool // Compare returns the comparison result of the two handles, it panics if the types are different. Compare(h Handle) int // Encoded returns the encoded bytes. Encoded() []byte // Len returns the length of the encoded bytes. Len() int // NumCols returns the number of columns of the handle, NumCols() int // EncodedCol returns the encoded column value at the given column index. EncodedCol(idx int) []byte // Data returns the data of all columns of a handle. Data() ([]types.Datum, error) // String implements the fmt.Stringer interface. String() string // MemUsage returns the memory usage of a handle. MemUsage() uint64 // ExtraMemSize returns the memory usage of objects that are pointed to by the Handle. ExtraMemSize() uint64 }
Handle is the ID of a row.
type HandleMap ¶
type HandleMap struct {
// contains filtered or unexported fields
}
HandleMap is the map for Handle.
type InjectedSnapshot ¶
type InjectedSnapshot struct { Snapshot // contains filtered or unexported fields }
InjectedSnapshot wraps a Snapshot with injections.
type InjectedStore ¶
type InjectedStore struct { Storage // contains filtered or unexported fields }
InjectedStore wraps a Storage with injections.
func (*InjectedStore) Begin ¶
func (s *InjectedStore) Begin(opts ...tikv.TxnOption) (Transaction, error)
Begin creates an injected Transaction.
func (*InjectedStore) GetSnapshot ¶
func (s *InjectedStore) GetSnapshot(ver Version) Snapshot
GetSnapshot creates an injected Snapshot.
type InjectedTransaction ¶
type InjectedTransaction struct { Transaction // contains filtered or unexported fields }
InjectedTransaction wraps a Transaction with injections.
type InjectionConfig ¶
InjectionConfig is used for fault injections for KV components.
func (*InjectionConfig) SetCommitError ¶
func (c *InjectionConfig) SetCommitError(err error)
SetCommitError injects an error for all Transaction.Commit() methods.
func (*InjectionConfig) SetGetError ¶
func (c *InjectionConfig) SetGetError(err error)
SetGetError injects an error for all kv.Get() methods.
type IntHandle ¶
type IntHandle int64
IntHandle implement the Handle interface for int64 type handle.
func (IntHandle) EncodedCol ¶
EncodedCol implements the Handle interface., not supported for IntHandle type.
func (IntHandle) ExtraMemSize ¶
ExtraMemSize implements the Handle interface.
type Key ¶
type Key []byte
Key represents high-level Key type.
func FindKeysInStage ¶
func FindKeysInStage(m MemBuffer, h StagingHandle, predicate func(Key, KeyFlags, []byte) bool) []Key
FindKeysInStage returns all keys in the given stage that satisfies the given condition.
func (Key) Cmp ¶
Cmp returns the comparison result of two key. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func (Key) PrefixNext ¶
PrefixNext returns the next prefix key.
Assume there are keys like:
rowkey1 rowkey1_column1 rowkey1_column2 rowKey2
If we seek 'rowkey1' Next, we will get 'rowkey1_column1'. If we seek 'rowkey1' PrefixNext, we will get 'rowkey2'.
type KeyFlags ¶
type KeyFlags uint8
KeyFlags are metadata associated with key
func ApplyFlagsOps ¶
ApplyFlagsOps applys flagspos to origin.
func (KeyFlags) HasAssertExists ¶
HasAssertExists returns whether the key is asserted to already exist before the current transaction.
func (KeyFlags) HasAssertNotExists ¶
HasAssertNotExists returns whether the key is asserted not to exist before the current transaction.
func (KeyFlags) HasAssertUnknown ¶
HasAssertUnknown returns whether the key is unable to do any assertion.
func (KeyFlags) HasAssertionFlags ¶
HasAssertionFlags returns whether assertion is set on this key.
func (KeyFlags) HasNeedConstraintCheckInPrewrite ¶
HasNeedConstraintCheckInPrewrite returns whether the key needs to do constraint and conflict check in prewrite.
func (KeyFlags) HasNeedLocked ¶
HasNeedLocked returns whether the key needed to be locked
func (KeyFlags) HasPresumeKeyNotExists ¶
HasPresumeKeyNotExists returns whether the associated key use lazy check.
type KeyRange ¶
type KeyRange struct { StartKey Key EndKey Key XXXNoUnkeyedLiteral struct{} XXXunrecognized []byte XXXsizecache int32 }
KeyRange represents a range where StartKey <= key < EndKey. Hack: make the layout exactly the same with github.com/pingcap/kvproto/pkg/coprocessor.KeyRange So we can avoid allocation of converting kv.KeyRange to coprocessor.KeyRange Not defined as "type KeyRange = coprocessor.KeyRange" because their field name are different. kv.KeyRange use StartKey,EndKey while coprocessor.KeyRange use Start,End
type KeyRanges ¶
type KeyRanges struct {
// contains filtered or unexported fields
}
KeyRanges wrap the ranges for partitioned table cases. We might send ranges from different in the one request.
func NewNonParitionedKeyRanges ¶
NewNonParitionedKeyRanges constructs a new RequestRange for a non partitioned table.
func NewNonParitionedKeyRangesWithHint ¶
NewNonParitionedKeyRangesWithHint constructs a new RequestRange for a non partitioned table with rou count hint.
func NewPartitionedKeyRanges ¶
NewPartitionedKeyRanges constructs a new RequestRange for partitioned table.
func NewPartitionedKeyRangesWithHints ¶
NewPartitionedKeyRangesWithHints constructs a new RequestRange for partitioned table with row count hint.
func (*KeyRanges) AppendSelfTo ¶
AppendSelfTo appends itself to another slice.
func (*KeyRanges) FirstPartitionRange ¶
FirstPartitionRange returns the the result of first range. We may use some func to generate ranges for both partitioned table and non partitioned table. This method provides a way to fallback to non-partitioned ranges.
func (*KeyRanges) ForEachPartition ¶
ForEachPartition runs the func for each partition without error check.
func (*KeyRanges) ForEachPartitionWithErr ¶
ForEachPartitionWithErr runs the func for each partition with an error check.
func (*KeyRanges) IsFullySorted ¶
IsFullySorted checks whether the ranges are sorted inside partition and each partition is also sorated.
func (*KeyRanges) PartitionNum ¶
PartitionNum returns how many partition is involved in the ranges.
func (*KeyRanges) SetToNonPartitioned ¶
SetToNonPartitioned set the status to non-partitioned.
func (*KeyRanges) SortByFunc ¶
SortByFunc sorts each partition's ranges. Since the ranges are sorted in most cases, we check it first.
func (*KeyRanges) TotalRangeNum ¶
TotalRangeNum returns how many ranges there are.
type MPPBuildTasksRequest ¶
type MPPBuildTasksRequest struct { KeyRanges []KeyRange StartTS uint64 PartitionIDAndRanges []PartitionIDAndRanges }
MPPBuildTasksRequest request the stores allocation for a mpp plan fragment. However, the request doesn't contain the particular plan, because only key ranges take effect on the location assignment.
type MPPClient ¶
type MPPClient interface { // ConstructMPPTasks schedules task for a plan fragment. // TODO:: This interface will be refined after we support more executors. ConstructMPPTasks(context.Context, *MPPBuildTasksRequest, time.Duration, tiflashcompute.DispatchPolicy, tiflash.ReplicaRead, func(error)) ([]MPPTaskMeta, error) // DispatchMPPTask dispatch mpp task, and returns valid response when retry = false and err is nil. DispatchMPPTask(DispatchMPPTaskParam) (resp *mpp.DispatchTaskResponse, retry bool, err error) // EstablishMPPConns build a mpp connection to receive data, return valid response when err is nil. EstablishMPPConns(EstablishMPPConnsParam) (*tikvrpc.MPPStreamResponse, error) // CancelMPPTasks cancels mpp tasks. CancelMPPTasks(CancelMPPTasksParam) // CheckVisibility checks if it is safe to read using given ts. CheckVisibility(startTime uint64) error // GetMPPStoreCount returns number of TiFlash stores if there is no error, else return (0, error). GetMPPStoreCount() (int, error) }
MPPClient accepts and processes mpp requests.
type MPPDispatchRequest ¶
type MPPDispatchRequest struct { Data []byte // data encodes the dag coprocessor request. Meta MPPTaskMeta // mpp store is the location of tiflash store. IsRoot bool // root task returns data to tidb directly. Timeout uint64 // If task is assigned but doesn't receive a connect request during timeout, the task should be destroyed. // SchemaVer is for any schema-ful storage (like tiflash) to validate schema correctness if necessary. SchemaVar int64 StartTs uint64 MppQueryID MPPQueryID GatherID uint64 ID int64 // identify a single task MppVersion MppVersion CoordinatorAddress string ReportExecutionSummary bool State MppTaskStates ResourceGroupName string }
MPPDispatchRequest stands for a dispatching task.
type MPPQueryID ¶
type MPPQueryID struct { QueryTs uint64 // timestamp of query execution, used for TiFlash minTSO schedule LocalQueryID uint64 // unique mpp query id in local tidb memory. ServerID uint64 }
MPPQueryID means the global unique id of a mpp query.
type MPPTask ¶
type MPPTask struct { Meta MPPTaskMeta // on which store this task will execute ID int64 // mppTaskID StartTs uint64 GatherID uint64 MppQueryID MPPQueryID TableID int64 // physical table id MppVersion MppVersion // mpp version PartitionTableIDs []int64 TiFlashStaticPrune bool }
MPPTask means the minimum execution unit of a mpp computation job.
type MPPTaskMeta ¶
type MPPTaskMeta interface { // GetAddress indicates which node this task should execute on. GetAddress() string }
MPPTaskMeta means the meta info such as location of a mpp task.
type MemAwareHandleMap ¶
type MemAwareHandleMap[V any] struct { // contains filtered or unexported fields }
MemAwareHandleMap is similar to HandleMap, but it's aware of its memory usage and doesn't support delete. It only tracks the actual sizes. Objects that are pointed to by the key or value are not tracked. Those should be tracked by the caller.
func NewMemAwareHandleMap ¶
func NewMemAwareHandleMap[V any]() *MemAwareHandleMap[V]
NewMemAwareHandleMap creates a new map for handle.
func (*MemAwareHandleMap[V]) Get ¶
func (m *MemAwareHandleMap[V]) Get(h Handle) (v V, ok bool)
Get gets a value by a Handle.
func (*MemAwareHandleMap[V]) Range ¶
func (m *MemAwareHandleMap[V]) Range(fn func(h Handle, val V) bool)
Range iterates the MemAwareHandleMap with fn, the fn returns true to continue, returns false to stop.
func (*MemAwareHandleMap[V]) Set ¶
func (m *MemAwareHandleMap[V]) Set(h Handle, val V) int64
Set sets a value with a Handle.
type MemBuffer ¶
type MemBuffer interface { RetrieverMutator // RLock locks the MemBuffer for shared read. // In the most case, MemBuffer will only used by single goroutine, // but it will be read by multiple goroutine when combined with executor.UnionScanExec. // To avoid race introduced by executor.UnionScanExec, MemBuffer expose read lock for it. RLock() // RUnlock unlocks the MemBuffer. RUnlock() // GetFlags returns the latest flags associated with key. GetFlags(Key) (KeyFlags, error) // SetWithFlags put key-value into the last active staging buffer with the given KeyFlags. SetWithFlags(Key, []byte, ...FlagsOp) error // UpdateFlags updates the flags associated with key. UpdateFlags(Key, ...FlagsOp) // DeleteWithFlags delete key with the given KeyFlags DeleteWithFlags(Key, ...FlagsOp) error // Staging create a new staging buffer inside the MemBuffer. // Subsequent writes will be temporarily stored in this new staging buffer. // When you think all modifications looks good, you can call `Release` to public all of them to the upper level buffer. Staging() StagingHandle // Release publish all modifications in the latest staging buffer to upper level. Release(StagingHandle) // Cleanup cleanup the resources referenced by the StagingHandle. // If the changes are not published by `Release`, they will be discarded. Cleanup(StagingHandle) // InspectStage used to inspect the value updates in the given stage. InspectStage(StagingHandle, func(Key, KeyFlags, []byte)) // SnapshotGetter returns a Getter for a snapshot of MemBuffer. SnapshotGetter() Getter // SnapshotIter returns a Iterator for a snapshot of MemBuffer. SnapshotIter(k, upperbound Key) Iterator // SnapshotIterReverse returns a reverse Iterator for a snapshot of MemBuffer. SnapshotIterReverse(k, lowerBound Key) Iterator // Len returns the number of entries in the DB. Len() int // Size returns sum of keys and values length. Size() int // RemoveFromBuffer removes the entry from the buffer. It's used for testing. RemoveFromBuffer(Key) }
MemBuffer is an in-memory kv collection, can be used to buffer write operations.
type MemManager ¶
type MemManager interface { // UnionGet gets the value from cacheDB first, if it not exists, // it gets the value from the snapshot, then caches the value in cacheDB. UnionGet(ctx context.Context, tid int64, snapshot Snapshot, key Key) ([]byte, error) // Delete releases the cache by tableID. Delete(tableID int64) }
MemManager adds a cache between transaction buffer and the storage to reduce requests to the storage. Beware, it uses table ID for partition tables, because the keys are unique for partition tables. no matter the physical IDs are the same or not.
type MppCoordinator ¶
type MppCoordinator interface { // Execute generates and executes mpp tasks for mpp physical plan. Execute(ctx context.Context) (Response, []KeyRange, error) // Next returns next data Next(ctx context.Context) (ResultSubset, error) // ReportStatus report task execution info to coordinator // It shouldn't change any state outside coordinator itself, since the query which generated the coordinator may not exist ReportStatus(info ReportStatusRequest) error // Close and release the used resources. Close() error // IsClosed returns whether mpp coordinator is closed or not IsClosed() bool }
MppCoordinator describes the basic api for executing mpp physical plan.
type MppTaskStates ¶
type MppTaskStates uint8
MppTaskStates denotes the state of mpp tasks
const ( // MppTaskReady means the task is ready MppTaskReady MppTaskStates = iota // MppTaskRunning means the task is running MppTaskRunning // MppTaskCancelled means the task is cancelled MppTaskCancelled // MppTaskDone means the task is done MppTaskDone )
type MppVersion ¶
type MppVersion int64
MppVersion indicates the mpp-version used to build mpp plan
func GetNewestMppVersion ¶
func GetNewestMppVersion() MppVersion
GetNewestMppVersion returns the mpp-version can be used in mpp plan
func ToMppVersion ¶
func ToMppVersion(name string) (MppVersion, bool)
ToMppVersion transforms string to MppVersion
func (MppVersion) ToInt64 ¶
func (v MppVersion) ToInt64() int64
ToInt64 transforms MppVersion to int64
type Mutator ¶
type Mutator interface { // Set sets the value for key k as v into kv store. // v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue. Set(k Key, v []byte) error // Delete removes the entry for key k from kv store. Delete(k Key) error }
Mutator is the interface wraps the basic Set and Delete methods.
type PartitionHandle ¶
PartitionHandle combines a handle and a PartitionID, used to location a row in partitioned table.
func NewPartitionHandle ¶
func NewPartitionHandle(pid int64, h Handle) PartitionHandle
NewPartitionHandle creates a PartitionHandle from a normal handle and a pid.
func (PartitionHandle) Compare ¶
func (ph PartitionHandle) Compare(h Handle) int
Compare implements the Handle interface.
func (PartitionHandle) Equal ¶
func (ph PartitionHandle) Equal(h Handle) bool
Equal implements the Handle interface.
func (PartitionHandle) ExtraMemSize ¶
func (ph PartitionHandle) ExtraMemSize() uint64
ExtraMemSize implements the Handle interface.
func (PartitionHandle) MemUsage ¶
func (ph PartitionHandle) MemUsage() uint64
MemUsage implements the Handle interface.
type PartitionIDAndRanges ¶
PartitionIDAndRanges used by PartitionTableScan in tiflash.
type ReplicaReadType ¶
type ReplicaReadType byte
ReplicaReadType is the type of replica to read data from
const ( // ReplicaReadLeader stands for 'read from leader'. ReplicaReadLeader ReplicaReadType = iota // ReplicaReadFollower stands for 'read from follower'. ReplicaReadFollower // ReplicaReadMixed stands for 'read from leader and follower'. ReplicaReadMixed // ReplicaReadClosest stands for 'read from leader and follower which locates with the same zone' ReplicaReadClosest // ReplicaReadClosestAdaptive stands for 'read from follower which locates in the same zone if the response size exceeds certain threshold' ReplicaReadClosestAdaptive // ReplicaReadLearner stands for 'read from learner'. ReplicaReadLearner // ReplicaReadPreferLeader stands for 'read from leader and auto-turn to followers if leader is abnormal'. ReplicaReadPreferLeader )
func (ReplicaReadType) IsClosestRead ¶
func (r ReplicaReadType) IsClosestRead() bool
IsClosestRead checks whether is going to request closet store to read
func (ReplicaReadType) IsFollowerRead ¶
func (r ReplicaReadType) IsFollowerRead() bool
IsFollowerRead checks if follower is going to be used to read data.
type ReportStatusRequest ¶
type ReportStatusRequest struct {
Request *mpp.ReportTaskStatusRequest
}
ReportStatusRequest wraps mpp ReportStatusRequest
type Request ¶
type Request struct { // Tp is the request type. Tp int64 StartTs uint64 Data []byte // KeyRanges makes sure that the request is sent first by partition then by region. // When the table is small, it's possible that multiple partitions are in the same region. KeyRanges *KeyRanges // For PartitionTableScan used by tiflash. PartitionIDAndRanges []PartitionIDAndRanges // Concurrency is 1, if it only sends the request to a single storage unit when // ResponseIterator.Next is called. If concurrency is greater than 1, the request will be // sent to multiple storage units concurrently. Concurrency int // IsolationLevel is the isolation level, default is SI. IsolationLevel IsoLevel // Priority is the priority of this KV request, its value may be PriorityNormal/PriorityLow/PriorityHigh. Priority int // memTracker is used to trace and control memory usage in co-processor layer. MemTracker *memory.Tracker // KeepOrder is true, if the response should be returned in order. KeepOrder bool // Desc is true, if the request is sent in descending order. Desc bool // NotFillCache makes this request do not touch the LRU cache of the underlying storage. NotFillCache bool // ReplicaRead is used for reading data from replicas, only follower is supported at this time. ReplicaRead ReplicaReadType // StoreType represents this request is sent to the which type of store. StoreType StoreType // Cacheable is true if the request can be cached. Currently only deterministic DAG requests can be cached. Cacheable bool // SchemaVer is for any schema-ful storage to validate schema correctness if necessary. SchemaVar int64 // BatchCop indicates whether send batch coprocessor request to tiflash. BatchCop bool // TaskID is an unique ID for an execution of a statement TaskID uint64 // TiDBServerID is the specified TiDB serverID to execute request. `0` means all TiDB instances. TiDBServerID uint64 // TxnScope is the scope of the txn TxnScope string // ReadReplicaScope is the scope of the read replica. ReadReplicaScope string // IsStaleness indicates whether the request read staleness data IsStaleness bool // ClosestReplicaReadAdjuster used to adjust a copr request. ClosestReplicaReadAdjuster CoprRequestAdjuster // MatchStoreLabels indicates the labels the store should be matched MatchStoreLabels []*metapb.StoreLabel // ResourceGroupTagger indicates the kv request task group tagger. ResourceGroupTagger tikvrpc.ResourceGroupTagger // Paging indicates whether the request is a paging request. Paging struct { Enable bool // MinPagingSize is used when Paging is true. MinPagingSize uint64 // MaxPagingSize is used when Paging is true. MaxPagingSize uint64 } // RequestSource indicates whether the request is an internal request. RequestSource util.RequestSource // StoreBatchSize indicates the batch size of coprocessor in the same store. StoreBatchSize int // ResourceGroupName is the name of the bind resource group. ResourceGroupName string // LimitSize indicates whether the request is scan and limit LimitSize uint64 // StoreBusyThreshold is the threshold for the store to return ServerIsBusy StoreBusyThreshold time.Duration // TiKVClientReadTimeout is the timeout of kv read request TiKVClientReadTimeout uint64 RunawayChecker *resourcegroup.RunawayChecker // ConnID stores the session connection id. ConnID uint64 // Killed is a flag to indicate that this query is killed. Killed *uint32 }
Request represents a kv request.
type RequestSource ¶
type RequestSource = util.RequestSource
RequestSource is the scope and type of the request and it's passed by go context.
type RequestTypeSupportedChecker ¶
type RequestTypeSupportedChecker struct{}
RequestTypeSupportedChecker is used to check expression can be pushed down.
func (RequestTypeSupportedChecker) IsRequestTypeSupported ¶
func (d RequestTypeSupportedChecker) IsRequestTypeSupported(reqType, subType int64) bool
IsRequestTypeSupported checks whether reqType is supported.
type Response ¶
type Response interface { // Next returns a resultSubset from a single storage unit. // When full result set is returned, nil is returned. Next(ctx context.Context) (resultSubset ResultSubset, err error) // Close response. Close() error }
Response represents the response returned from KV layer.
type ResultSubset ¶
type ResultSubset interface { // GetData gets the data. GetData() []byte // GetStartKey gets the start key. GetStartKey() Key // MemSize returns how many bytes of memory this result use for tracing memory usage. MemSize() int64 // RespTime returns the response time for the request. RespTime() time.Duration }
ResultSubset represents a result subset from a single storage unit. TODO: Find a better interface for ResultSubset that can reuse bytes.
type Retriever ¶
type Retriever interface { Getter // Iter creates an Iterator positioned on the first entry that k <= entry's key. // If such entry is not found, it returns an invalid Iterator with no error. // It yields only keys that < upperBound. If upperBound is nil, it means the upperBound is unbounded. // The Iterator must be Closed after use. Iter(k Key, upperBound Key) (Iterator, error) // IterReverse creates a reversed Iterator positioned on the first entry which key is less than k. // The returned iterator will iterate from greater key to smaller key. // If k is nil, the returned iterator will be positioned at the last key. // It yields only keys that >= lowerBound. If lowerBound is nil, it means the lowerBound is unbounded. IterReverse(k, lowerBound Key) (Iterator, error) }
Retriever is the interface wraps the basic Get and Seek methods.
type RetrieverMutator ¶
RetrieverMutator is the interface that groups Retriever and Mutator interfaces.
type Snapshot ¶
type Snapshot interface { Retriever // BatchGet gets a batch of values from snapshot. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) // SetOption sets an option with a value, when val is nil, uses the default // value of this option. Only ReplicaRead is supported for snapshot SetOption(opt int, val interface{}) }
Snapshot defines the interface for the snapshot fetched from KV store.
type SnapshotInterceptor ¶
type SnapshotInterceptor interface { // OnGet intercepts Get operation for Snapshot OnGet(ctx context.Context, snap Snapshot, k Key) ([]byte, error) // OnBatchGet intercepts BatchGet operation for Snapshot OnBatchGet(ctx context.Context, snap Snapshot, keys []Key) (map[string][]byte, error) // OnIter intercepts Iter operation for Snapshot OnIter(snap Snapshot, k Key, upperBound Key) (Iterator, error) // OnIterReverse intercepts IterReverse operation for Snapshot OnIterReverse(snap Snapshot, k Key, lowerBound Key) (Iterator, error) }
SnapshotInterceptor is used to intercept snapshot's read operation
type SplittableStore ¶
type SplittableStore interface { SplitRegions(ctx context.Context, splitKey [][]byte, scatter bool, tableID *int64) (regionID []uint64, err error) WaitScatterRegionFinish(ctx context.Context, regionID uint64, backOff int) error CheckRegionInScattering(regionID uint64) (bool, error) }
SplittableStore is the kv store which supports split regions.
type StagingHandle ¶
type StagingHandle int
StagingHandle is the reference of a staging buffer.
var ( // InvalidStagingHandle is an invalid handler, MemBuffer will check handler to ensure safety. InvalidStagingHandle StagingHandle = 0 // LastActiveStagingHandle is an special handler which always point to the last active staging buffer. LastActiveStagingHandle StagingHandle = -1 )
type Storage ¶
type Storage interface { // Begin a global transaction Begin(opts ...tikv.TxnOption) (Transaction, error) // GetSnapshot gets a snapshot that is able to read any data which data is <= ver. // if ver is MaxVersion or > current max committed version, we will use current version for this snapshot. GetSnapshot(ver Version) Snapshot // GetClient gets a client instance. GetClient() Client // GetMPPClient gets a mpp client instance. GetMPPClient() MPPClient // Close store Close() error // UUID return a unique ID which represents a Storage. UUID() string // CurrentVersion returns current max committed version with the given txnScope (local or global). CurrentVersion(txnScope string) (Version, error) // GetOracle gets a timestamp oracle client. GetOracle() oracle.Oracle // SupportDeleteRange gets the storage support delete range or not. SupportDeleteRange() (supported bool) // Name gets the name of the storage engine Name() string // Describe returns of brief introduction of the storage Describe() string // ShowStatus returns the specified status of the storage ShowStatus(ctx context.Context, key string) (interface{}, error) // GetMemCache return memory manager of the storage. GetMemCache() MemManager // GetMinSafeTS return the minimal SafeTS of the storage with given txnScope. GetMinSafeTS(txnScope string) uint64 // GetLockWaits return all lock wait information GetLockWaits() ([]*deadlockpb.WaitForEntry, error) // GetCodec gets the codec of the storage. GetCodec() tikv.Codec }
Storage defines the interface for storage. Isolation should be at least SI(SNAPSHOT ISOLATION)
func NewInjectedStore ¶
func NewInjectedStore(store Storage, cfg *InjectionConfig) Storage
NewInjectedStore creates a InjectedStore with config.
type StorageWithPD ¶
StorageWithPD is used to get pd client.
type Transaction ¶
type Transaction interface { RetrieverMutator AssertionProto FairLockingController // Size returns sum of keys and values length. Size() int // Mem returns the memory consumption of the transaction. Mem() uint64 // SetMemoryFootprintChangeHook sets the hook that will be called when the memory footprint changes. SetMemoryFootprintChangeHook(func(uint64)) // Len returns the number of entries in the DB. Len() int // Reset reset the Transaction to initial states. Reset() // Commit commits the transaction operations to KV store. Commit(context.Context) error // Rollback undoes the transaction operations to KV store. Rollback() error // String implements fmt.Stringer interface. String() string // LockKeys tries to lock the entries with the keys in KV store. // Will block until all keys are locked successfully or an error occurs. LockKeys(ctx context.Context, lockCtx *LockCtx, keys ...Key) error // LockKeysFunc tries to lock the entries with the keys in KV store. // Will block until all keys are locked successfully or an error occurs. // fn is called before LockKeys unlocks the keys. LockKeysFunc(ctx context.Context, lockCtx *LockCtx, fn func(), keys ...Key) error // SetOption sets an option with a value, when val is nil, uses the default // value of this option. SetOption(opt int, val interface{}) // GetOption returns the option GetOption(opt int) interface{} // IsReadOnly checks if the transaction has only performed read operations. IsReadOnly() bool // StartTS returns the transaction start timestamp. StartTS() uint64 // Valid returns if the transaction is valid. // A transaction become invalid after commit or rollback. Valid() bool // GetMemBuffer return the MemBuffer binding to this transaction. GetMemBuffer() MemBuffer // GetSnapshot returns the Snapshot binding to this transaction. GetSnapshot() Snapshot // SetVars sets variables to the transaction. SetVars(vars interface{}) // GetVars gets variables from the transaction. GetVars() interface{} // BatchGet gets kv from the memory buffer of statement and transaction, and the kv storage. // Do not use len(value) == 0 or value == nil to represent non-exist. // If a key doesn't exist, there shouldn't be any corresponding entry in the result map. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) IsPessimistic() bool // CacheTableInfo caches the index name. // PresumeKeyNotExists will use this to help decode error message. CacheTableInfo(id int64, info *model.TableInfo) // GetTableInfo returns the cached index name. // If there is no such index already inserted through CacheIndexName, it will return UNKNOWN. GetTableInfo(id int64) *model.TableInfo // SetDiskFullOpt set allowed options of current operation in each TiKV disk usage level. SetDiskFullOpt(level kvrpcpb.DiskFullOpt) // ClearDiskFullOpt clear allowed flag ClearDiskFullOpt() // GetMemDBCheckpoint gets the transaction's memDB checkpoint. GetMemDBCheckpoint() *tikv.MemDBCheckpoint // RollbackMemDBToCheckpoint rollbacks the transaction's memDB to the specified checkpoint. RollbackMemDBToCheckpoint(*tikv.MemDBCheckpoint) // UpdateMemBufferFlags updates the flags of a node in the mem buffer. UpdateMemBufferFlags(key []byte, flags ...FlagsOp) }
Transaction defines the interface for operations inside a Transaction. This is not thread safe.
type TxnScopeVar ¶
type TxnScopeVar struct {
// contains filtered or unexported fields
}
TxnScopeVar indicates the used txnScope for oracle
func NewDefaultTxnScopeVar ¶
func NewDefaultTxnScopeVar() TxnScopeVar
NewDefaultTxnScopeVar creates a default TxnScopeVar according to the config. If zone label is set, we will check whether it's not the GlobalTxnScope and create a new Local TxnScopeVar. If zone label is not set, we will create a new Global TxnScopeVar.
func NewGlobalTxnScopeVar ¶
func NewGlobalTxnScopeVar() TxnScopeVar
NewGlobalTxnScopeVar creates a Global TxnScopeVar
func NewLocalTxnScopeVar ¶
func NewLocalTxnScopeVar(txnScope string) TxnScopeVar
NewLocalTxnScopeVar creates a Local TxnScopeVar with given real txnScope value.
func (TxnScopeVar) GetTxnScope ¶
func (t TxnScopeVar) GetTxnScope() string
GetTxnScope returns the value of the tidb-server holds to request tso to pd. When varValue is 'global`, directly return global here
func (TxnScopeVar) GetVarValue ¶
func (t TxnScopeVar) GetVarValue() string
GetVarValue returns the value of @@txn_scope which can only be `global` or `local`
type Variables ¶
Variables defines the variables used by KV storage. TODO:remove it when br is ready.
func NewVariables ¶
NewVariables create a new Variables instance with default values. TODO:remove it when br is ready.
type VersionProvider ¶
VersionProvider provides increasing IDs.