cockroach: github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval Index | Files | Directories

package batcheval

import "github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval"

Index

Package Files

cmd_add_sstable.go cmd_clear_range.go cmd_compute_checksum.go cmd_conditional_put.go cmd_delete.go cmd_delete_range.go cmd_end_transaction.go cmd_gc.go cmd_get.go cmd_heartbeat_txn.go cmd_increment.go cmd_init_put.go cmd_lease.go cmd_lease_info.go cmd_lease_request.go cmd_lease_transfer.go cmd_merge.go cmd_push_txn.go cmd_put.go cmd_query_intent.go cmd_query_txn.go cmd_range_stats.go cmd_recompute_stats.go cmd_recover_txn.go cmd_refresh.go cmd_refresh_range.go cmd_resolve_intent.go cmd_resolve_intent_range.go cmd_reverse_scan.go cmd_revert_range.go cmd_scan.go cmd_subsume.go cmd_truncate_log.go command.go declare.go eval_context.go intent.go split_stats_helper.go stateloader.go transaction.go

Constants

const (
    ReplicaChecksumVersion    = 4
    ReplicaChecksumGCInterval = time.Hour
)

Version numbers for Replica checksum computation. Requests silently no-op unless the versions are compatible.

const ClearRangeBytesThreshold = 512 << 10 // 512KiB

ClearRangeBytesThreshold is the threshold over which the ClearRange command will use engine.ClearRange to efficiently perform a range deletion. Otherwise, will revert to iterating through the values and clearing them individually with engine.Clear.

Variables

var ErrTransactionUnsupported = errors.New("not supported within a transaction")

ErrTransactionUnsupported is returned when a non-transactional command is evaluated in the context of a transaction.

func CanCreateTxnRecord Uses

func CanCreateTxnRecord(ctx context.Context, rec EvalContext, txn *roachpb.Transaction) error

CanCreateTxnRecord determines whether a transaction record can be created for the provided transaction. If not, the function will return an error. If so, the function may modify the provided transaction.

func CanForwardCommitTimestampWithoutRefresh Uses

func CanForwardCommitTimestampWithoutRefresh(
    txn *roachpb.Transaction, args *roachpb.EndTxnRequest,
) bool

CanForwardCommitTimestampWithoutRefresh returns whether a txn can be safely committed with a timestamp above its read timestamp without requiring a read refresh (see txnSpanRefresher). This requires that the transaction's timestamp has not leaked and that the transaction has encountered no spans which require refreshing at the forwarded timestamp. If either of those conditions are true, a client-side retry is required.

Note that when deciding whether a transaction can be bumped to a particular timestamp, the transaction's deadling must also be taken into account.

func CanPushWithPriority Uses

func CanPushWithPriority(pusher, pushee *roachpb.Transaction) bool

CanPushWithPriority returns true if the given pusher can push the pushee based on its priority.

func ClearRange Uses

func ClearRange(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ClearRange wipes all MVCC versions of keys covered by the specified span, adjusting the MVCC stats accordingly.

Note that "correct" use of this command is only possible for key spans consisting of user data that we know is not being written to or queried any more, such as after a DROP or TRUNCATE table, or DROP index.

func CollectIntentRows Uses

func CollectIntentRows(
    ctx context.Context, reader storage.Reader, usePrefixIter bool, intents []roachpb.Intent,
) ([]roachpb.KeyValue, error)

CollectIntentRows collects the provisional key-value pairs for each intent provided.

The method accepts a reader and flag indicating whether a prefix iterator should be used when creating an iterator from the reader. This flexibility works around a limitation of the Engine.NewReadOnly interface where prefix iterators and non-prefix iterators pulled from the same read-only engine are not guaranteed to provide a consistent snapshot of the underlying engine. This function expects to be able to retrieve the corresponding provisional value for each of the provided intents. As such, it is critical that it observes the engine in the same state that it was in when the intent keys were originally collected. Because of this, callers are tasked with indicating whether the intents were originally collected using a prefix iterator or not.

TODO(nvanbenschoten): remove the usePrefixIter complexity when we're fully on Pebble and can guarantee that all iterators created from a read-only engine are consistent.

TODO(nvanbenschoten): mvccGetInternal should return the intent values directly when reading at the READ_UNCOMMITTED consistency level. Since this is only currently used for range lookups and when watching for a merge (both of which are off the hot path), this is ok for now.

func ComputeChecksum Uses

func ComputeChecksum(
    _ context.Context, _ storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ComputeChecksum starts the process of computing a checksum on the replica at a particular snapshot. The checksum is later verified through a CollectChecksumRequest.

func ConditionalPut Uses

func ConditionalPut(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ConditionalPut sets the value for a specified key only if the expected value matches. If not, the return value contains the actual value.

func DeclareKeysForBatch Uses

func DeclareKeysForBatch(
    desc *roachpb.RangeDescriptor, header roachpb.Header, latchSpans *spanset.SpanSet,
)

DeclareKeysForBatch adds all keys that the batch with the provided header touches to the given SpanSet. This does not include keys touched during the processing of the batch's individual commands.

func DefaultDeclareIsolatedKeys Uses

func DefaultDeclareIsolatedKeys(
    _ *roachpb.RangeDescriptor,
    header roachpb.Header,
    req roachpb.Request,
    latchSpans, lockSpans *spanset.SpanSet,
)

DefaultDeclareIsolatedKeys is similar to DefaultDeclareKeys, but it declares both lock spans in addition to latch spans. When used, commands will wait on locks and wait-queues owned by other transactions before evaluating. This ensures that the commands are fully isolated from conflicting transactions when it evaluated.

func DefaultDeclareKeys Uses

func DefaultDeclareKeys(
    _ *roachpb.RangeDescriptor,
    header roachpb.Header,
    req roachpb.Request,
    latchSpans, _ *spanset.SpanSet,
)

DefaultDeclareKeys is the default implementation of Command.DeclareKeys.

func Delete Uses

func Delete(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Delete deletes the key and value specified by key.

func DeleteRange Uses

func DeleteRange(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

DeleteRange deletes the range of key/value pairs specified by start and end keys.

func EndTxn Uses

func EndTxn(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

EndTxn either commits or aborts (rolls back) an extant transaction according to the args.Commit parameter. Rolling back an already rolled-back txn is ok. TODO(nvanbenschoten): rename this file to cmd_end_txn.go once some of andrei's recent PRs have landed.

func EvalAddSSTable Uses

func EvalAddSSTable(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, _ roachpb.Response,
) (result.Result, error)

EvalAddSSTable evaluates an AddSSTable command.

func GC Uses

func GC(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

GC iterates through the list of keys to garbage collect specified in the arguments. MVCCGarbageCollect is invoked on each listed key along with the expiration timestamp. The GC metadata specified in the args is persisted after GC.

func Get Uses

func Get(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Get returns the value for a specified key.

func HeartbeatTxn Uses

func HeartbeatTxn(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

HeartbeatTxn updates the transaction status and heartbeat timestamp after receiving transaction heartbeat messages from coordinator. Returns the updated transaction.

func Increment Uses

func Increment(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Increment increments the value (interpreted as varint64 encoded) and returns the newly incremented value (encoded as varint64). If no value exists for the key, zero is incremented.

func InitPut Uses

func InitPut(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

InitPut sets the value for a specified key only if it doesn't exist. It returns a ConditionFailedError if the key exists with an existing value that is different from the value provided. If FailOnTombstone is set to true, tombstones count as mismatched values and will cause a ConditionFailedError.

func IsEndTxnExceedingDeadline Uses

func IsEndTxnExceedingDeadline(t hlc.Timestamp, args *roachpb.EndTxnRequest) bool

IsEndTxnExceedingDeadline returns true if the transaction exceeded its deadline.

func IsEndTxnTriggeringRetryError Uses

func IsEndTxnTriggeringRetryError(
    txn *roachpb.Transaction, args *roachpb.EndTxnRequest,
) (retry bool, reason roachpb.TransactionRetryReason, extraMsg string)

IsEndTxnTriggeringRetryError returns true if the EndTxnRequest cannot be committed and needs to return a TransactionRetryError. It also returns the reason and possibly an extra message to be used for the error.

func LeaseInfo Uses

func LeaseInfo(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

LeaseInfo returns information about the lease holder for the range.

func MakeStateLoader Uses

func MakeStateLoader(rec EvalContext) stateloader.StateLoader

MakeStateLoader creates a StateLoader for the EvalContext.

func Merge Uses

func Merge(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Merge is used to merge a value into an existing key. Merge is an efficient accumulation operation which is exposed by RocksDB, used by CockroachDB for the efficient accumulation of certain values. Due to the difficulty of making these operations transactional, merges are not currently exposed directly to clients. Merged values are explicitly not MVCC data.

func PushTxn Uses

func PushTxn(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

PushTxn resolves conflicts between concurrent txns (or between a non-transactional reader or writer and a txn) in several ways, depending on the statuses and priorities of the conflicting transactions. The PushTxn operation is invoked by a "pusher" (args.PusherTxn -- the writer trying to abort a conflicting txn or the reader trying to push a conflicting txn's commit timestamp forward), who attempts to resolve a conflict with a "pushee" (args.PusheeTxn -- the pushee txn whose intent(s) caused the conflict). A pusher is either transactional, in which case PusherTxn is completely initialized, or not, in which case the PusherTxn has only the priority set.

The request arrives and immediately tries to determine the current disposition of the pushee transaction by reading its transaction record. If it finds one, it continues with the push. If not, it uses knowledge from the existence of the conflicting intent to determine the current state of the pushee. It's possible that the transaction record is missing either because it hasn't been written yet or because it has already been GCed after being finalized. Once the request determines which case its in, it decides whether to continue with the push. There are a number of different outcomes that a push can result in, based on the state that the pushee's transaction record is found in:

Txn already committed/aborted: If the pushee txn is committed or aborted return success.

Txn record expired: If the pushee txn is pending, its last heartbeat timestamp is observed to determine the latest client activity. This heartbeat is forwarded by the conflicting intent's timestamp because that timestamp also indicates definitive client activity. This time of "last activity" is compared against the current time to determine whether the transaction has expired. If so, it is aborted. NOTE: the intent timestamp used is not updated on intent pushes. This is important because it allows us to use its timestamp as an indication of recent activity. If this is ever changed, we don't run the risk of any correctness violations, but we do make it possible for intent pushes to look like client activity and extend the waiting period until a transaction is considered expired. This waiting period is a "courtesy" - if we simply aborted txns right away then we would see worse performance under contention, but everything would still be correct.

Txn record not expired: If the pushee txn is not expired, its priority is compared against the pusher's (see CanPushWithPriority).

Push cannot proceed: a TransactionPushError is returned.

Push can proceed but txn record staging: if the transaction record is STAGING then it can't be changed by a pusher without going through the transaction recovery process. An IndeterminateCommitError is returned to kick off recovery.

Push can proceed: the pushee's transaction record is modified and rewritten, based on the value of args.PushType. If args.PushType is PUSH_ABORT, txn.Status is set to ABORTED. If args.PushType is PUSH_TIMESTAMP, txn.Timestamp is set to just after args.PushTo.

If the pushee is aborted, its timestamp will be forwarded to match its last client activity timestamp (i.e. last heartbeat), if available. This is done so that the updated timestamp populates the AbortSpan when the pusher proceeds to resolve intents, allowing the GC queue to purge records for which the transaction coordinator must have found out via its heartbeats that the transaction has failed.

func Put Uses

func Put(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Put sets the value for a specified key.

func QueryIntent Uses

func QueryIntent(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

QueryIntent checks if an intent exists for the specified transaction at the given key. If the intent is missing, the request prevents the intent from ever being written at the specified timestamp (but the actual prevention happens during the timestamp cache update).

QueryIntent returns an error if the intent is missing and its ErrorIfMissing field is set to true. This error is typically an IntentMissingError, but the request is special-cased to return a SERIALIZABLE retry error if a transaction queries its own intent and finds it has been pushed.

func QueryTxn Uses

func QueryTxn(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

QueryTxn fetches the current state of a transaction. This method is used to continually update the state of a txn which is blocked waiting to resolve a conflicting intent. It fetches the complete transaction record to determine whether priority or status has changed and also fetches a list of other txns which are waiting on this transaction in order to find dependency cycles.

func RangeStats Uses

func RangeStats(
    ctx context.Context, _ storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RangeStats returns the MVCC statistics for a range.

func RecomputeStats Uses

func RecomputeStats(
    ctx context.Context, _ storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RecomputeStats recomputes the MVCCStats stored for this range and adjust them accordingly, returning the MVCCStats delta obtained in the process.

func RecoverTxn Uses

func RecoverTxn(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RecoverTxn attempts to recover the specified transaction from an indeterminate commit state. Transactions enter this state when abandoned after updating their transaction record with a STAGING status. The RecoverTxn operation is invoked by a caller who encounters a transaction in this state after they have already queried all of the STAGING transaction's declared in-flight writes. The caller specifies whether all of these in-flight writes were found to have succeeded or whether at least one of them was prevented from ever succeeding. This is used by RecoverTxn to determine whether the result of the recovery should be committing the abandoned transaction or aborting it.

func Refresh Uses

func Refresh(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Refresh checks whether the key has any values written in the interval [args.RefreshFrom, header.Timestamp].

func RefreshRange Uses

func RefreshRange(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RefreshRange checks whether the key range specified has any values written in the interval [args.RefreshFrom, header.Timestamp].

func RegisterReadOnlyCommand Uses

func RegisterReadOnlyCommand(
    method roachpb.Method,
    declare declareKeysFunc,
    impl func(context.Context, storage.Reader, CommandArgs, roachpb.Response) (result.Result, error),
)

RegisterReadOnlyCommand makes a read-only command available for execution. It must only be called before any evaluation takes place.

func RegisterReadWriteCommand Uses

func RegisterReadWriteCommand(
    method roachpb.Method,
    declare declareKeysFunc,
    impl func(context.Context, storage.ReadWriter, CommandArgs, roachpb.Response) (result.Result, error),
)

RegisterReadWriteCommand makes a read-write command available for execution. It must only be called before any evaluation takes place.

func RequestLease Uses

func RequestLease(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RequestLease sets the range lease for this range. The command fails only if the desired start timestamp collides with a previous lease. Otherwise, the start timestamp is wound back to right after the expiration of the previous lease (or zero). If this range replica is already the lease holder, the expiration will be extended or shortened as indicated. For a new lease, all duties required of the range lease holder are commenced, including releasing all latches and clearing the timestamp cache.

func ResolveIntent Uses

func ResolveIntent(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ResolveIntent resolves a write intent from the specified key according to the status of the transaction which created it.

func ResolveIntentRange Uses

func ResolveIntentRange(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ResolveIntentRange resolves write intents in the specified key range according to the status of the transaction which created it.

func ReverseScan Uses

func ReverseScan(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

ReverseScan scans the key range specified by start key through end key in descending order up to some maximum number of results. maxKeys stores the number of scan results remaining for this batch (MaxInt64 for no limit).

func RevertRange Uses

func RevertRange(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

RevertRange wipes all MVCC versions more recent than TargetTime (up to the command timestamp) of the keys covered by the specified span, adjusting the MVCC stats accordingly.

Note: this should only be used when there is no user traffic writing to the target span at or above the target time.

func RunCommitTrigger Uses

func RunCommitTrigger(
    ctx context.Context,
    rec EvalContext,
    batch storage.Batch,
    ms *enginepb.MVCCStats,
    args *roachpb.EndTxnRequest,
    txn *roachpb.Transaction,
) (result.Result, error)

RunCommitTrigger runs the commit trigger from an end transaction request.

func Scan Uses

func Scan(
    ctx context.Context, reader storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Scan scans the key range specified by start key through end key in ascending order up to some maximum number of results. maxKeys stores the number of scan results remaining for this batch (MaxInt64 for no limit).

func Subsume Uses

func Subsume(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

Subsume freezes a range for merging with its left-hand neighbor. When called correctly, it provides important guarantees that ensure there is no moment in time where the ranges involved in the merge could both process commands for the same keys.

Specifically, the receiving replica guarantees that:

1. it is the leaseholder at the time the request executes,
2. when it responds, there are no commands in flight with a timestamp
   greater than the FreezeStart timestamp provided in the response,
3. the MVCC statistics in the response reflect the latest writes,
4. it, and all future leaseholders for the range, will not process another
   command until they refresh their range descriptor with a consistent read
   from meta2, and
5. if it or any future leaseholder for the range finds that its range
   descriptor has been deleted, it self destructs.

To achieve guarantees four and five, when issuing a Subsume request, the caller must have a merge transaction open that has already placed deletion intents on both the local and meta2 copy of the right-hand range descriptor. The intent on the meta2 allows the leaseholder to block until the merge transaction completes by performing a consistent read for its meta2 descriptor. The intent on the local descriptor allows future leaseholders to efficiently check whether a merge is in progress by performing a read of its local descriptor after acquiring the lease.

The period of time after intents have been placed but before the merge transaction is complete is called the merge's "critical phase".

func SynthesizeTxnFromMeta Uses

func SynthesizeTxnFromMeta(rec EvalContext, txn enginepb.TxnMeta) roachpb.Transaction

SynthesizeTxnFromMeta creates a synthetic transaction object from the provided transaction metadata. The synthetic transaction is not meant to be persisted, but can serve as a representation of the transaction for outside observation. The function also checks whether it is possible for the transaction to ever create a transaction record in the future. If not, the returned transaction will be marked as ABORTED and it is safe to assume that the transaction record will never be written in the future.

Note that the Transaction object returned by this function is inadequate to perform further KV reads or to perform intent resolution on its behalf, even if its state is PENDING. This is because the original Transaction object may have been partially rolled back and marked some of its intents as "ignored" (txn.IgnoredSeqNums != nil), but this state is not stored in TxnMeta. Proceeding to KV reads or intent resolution without this information would cause a partial rollback, if any, to be reverted and yield inconsistent data.

func TestingSetTxnAutoGC Uses

func TestingSetTxnAutoGC(to bool) func()

TestingSetTxnAutoGC is used in tests to temporarily enable/disable txnAutoGC.

func TransferLease Uses

func TransferLease(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

TransferLease sets the lease holder for the range. Unlike with RequestLease(), the new lease is allowed to overlap the old one, the contract being that the transfer must have been initiated by the (soon ex-) lease holder which must have dropped all of its lease holder powers before proposing.

func TruncateLog Uses

func TruncateLog(
    ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error)

TruncateLog discards a prefix of the raft log. Truncating part of a log that has already been truncated has no effect. If this range is not the one specified within the request body, the request will also be ignored.

func UnregisterCommand Uses

func UnregisterCommand(method roachpb.Method)

UnregisterCommand is provided for testing and allows removing a command. It is a no-op if the command is not registered.

func UpdateAbortSpan Uses

func UpdateAbortSpan(
    ctx context.Context,
    rec EvalContext,
    readWriter storage.ReadWriter,
    ms *enginepb.MVCCStats,
    txn enginepb.TxnMeta,
    poison bool,
) error

UpdateAbortSpan clears any AbortSpan entry if poison is false. Otherwise, if poison is true, it creates an entry for this transaction in the AbortSpan to prevent future reads or writes from spuriously succeeding on this range.

func VerifyTransaction Uses

func VerifyTransaction(
    h roachpb.Header, args roachpb.Request, permittedStatuses ...roachpb.TransactionStatus,
) error

VerifyTransaction runs sanity checks verifying that the transaction in the header and the request are compatible.

func WriteAbortSpanOnResolve Uses

func WriteAbortSpanOnResolve(status roachpb.TransactionStatus, poison, removedIntents bool) bool

WriteAbortSpanOnResolve returns true if the abort span must be written when the transaction with the given status is resolved. It avoids instructing the caller to write to the abort span if the caller didn't actually remove any intents but intends to poison.

type Command Uses

type Command struct {
    // DeclareKeys adds all keys this command touches, and when (if applicable),
    // to the given SpanSet.
    //
    // TODO(nvanbenschoten): rationalize this RangeDescriptor. Can it change
    // between key declaration and cmd evaluation? Really, do it.
    DeclareKeys declareKeysFunc

    // Eval{RW,RO} evaluates a read-{write,only} command respectively on the
    // given engine.{ReadWriter,Reader}. This is typically derived from
    // engine.NewBatch or engine.NewReadOnly (which is more performant than
    // engine.Batch for read-only commands).
    // It should populate the supplied response (always a non-nil pointer to the
    // correct type) and return special side effects (if any) in the Result. If
    // it writes to the engine it should also update *CommandArgs.Stats. It
    // should treat the provided request as immutable.
    //
    // Only one of these is ever set at a time.
    EvalRW func(context.Context, storage.ReadWriter, CommandArgs, roachpb.Response) (result.Result, error)
    EvalRO func(context.Context, storage.Reader, CommandArgs, roachpb.Response) (result.Result, error)
}

A Command is the implementation of a single request within a BatchRequest.

func LookupCommand Uses

func LookupCommand(method roachpb.Method) (Command, bool)

LookupCommand returns the command for the given method, with the boolean indicating success or failure.

type CommandArgs Uses

type CommandArgs struct {
    EvalCtx EvalContext
    Header  roachpb.Header
    Args    roachpb.Request
    // *Stats should be mutated to reflect any writes made by the command.
    Stats *enginepb.MVCCStats
}

CommandArgs contains all the arguments to a command. TODO(bdarnell): consider merging with kvserverbase.FilterArgs (which would probably require removing the EvalCtx field due to import order constraints).

type EvalContext Uses

type EvalContext interface {
    fmt.Stringer
    ClusterSettings() *cluster.Settings
    EvalKnobs() kvserverbase.BatchEvalTestingKnobs

    Engine() storage.Engine
    Clock() *hlc.Clock
    DB() *kv.DB
    AbortSpan() *abortspan.AbortSpan
    GetConcurrencyManager() concurrency.Manager
    GetLimiters() *Limiters

    NodeID() roachpb.NodeID
    StoreID() roachpb.StoreID
    GetRangeID() roachpb.RangeID
    GetNodeLocality() roachpb.Locality

    IsFirstRange() bool
    GetFirstIndex() (uint64, error)
    GetTerm(uint64) (uint64, error)
    GetLeaseAppliedIndex() uint64
    GetTracker() closedts.TrackerI

    Desc() *roachpb.RangeDescriptor
    ContainsKey(key roachpb.Key) bool

    // CanCreateTxnRecord determines whether a transaction record can be created
    // for the provided transaction information. See Replica.CanCreateTxnRecord
    // for details about its arguments, return values, and preconditions.
    CanCreateTxnRecord(
        txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp,
    ) (ok bool, minCommitTS hlc.Timestamp, reason roachpb.TransactionAbortedReason)

    // GetMVCCStats returns a snapshot of the MVCC stats for the range.
    // If called from a command that declares a read/write span on the
    // entire range, the stats will be consistent with the data that is
    // visible to the batch. Otherwise, it may return inconsistent
    // results due to concurrent writes.
    GetMVCCStats() enginepb.MVCCStats

    // GetSplitQPS returns the queries/s request rate for this range.
    //
    // NOTE: This should not be used when the load based splitting cluster
    // setting is disabled.
    GetSplitQPS() float64

    GetGCThreshold() hlc.Timestamp
    GetLastReplicaGCTimestamp(context.Context) (hlc.Timestamp, error)
    GetLease() (roachpb.Lease, roachpb.Lease)
    GetDescAndLease(context.Context) (roachpb.RangeDescriptor, roachpb.Lease)

    GetExternalStorage(ctx context.Context, dest roachpb.ExternalStorage) (cloud.ExternalStorage, error)
    GetExternalStorageFromURI(ctx context.Context, uri string, user string) (cloud.ExternalStorage,
        error)
}

EvalContext is the interface through which command evaluation accesses the underlying state.

type Limiters Uses

type Limiters struct {
    BulkIOWriteRate              *rate.Limiter
    ConcurrentImportRequests     limit.ConcurrentRequestLimiter
    ConcurrentExportRequests     limit.ConcurrentRequestLimiter
    ConcurrentAddSSTableRequests limit.ConcurrentRequestLimiter
    // concurrentRangefeedIters is a semaphore used to limit the number of
    // rangefeeds in the "catch-up" state across the store. The "catch-up" state
    // is a temporary state at the beginning of a rangefeed which is expensive
    // because it uses an engine iterator.
    ConcurrentRangefeedIters limit.ConcurrentRequestLimiter
}

Limiters is the collection of per-store limits used during cmd evaluation.

type MockEvalCtx Uses

type MockEvalCtx struct {
    ClusterSettings  *cluster.Settings
    Desc             *roachpb.RangeDescriptor
    StoreID          roachpb.StoreID
    Clock            *hlc.Clock
    Stats            enginepb.MVCCStats
    QPS              float64
    AbortSpan        *abortspan.AbortSpan
    GCThreshold      hlc.Timestamp
    Term, FirstIndex uint64
    CanCreateTxn     func() (bool, hlc.Timestamp, roachpb.TransactionAbortedReason)
    Lease            roachpb.Lease
}

MockEvalCtx is a dummy implementation of EvalContext for testing purposes. For technical reasons, the interface is implemented by a wrapper .EvalContext().

func (*MockEvalCtx) EvalContext Uses

func (m *MockEvalCtx) EvalContext() EvalContext

EvalContext returns the MockEvalCtx as an EvalContext. It will reflect future modifications to the underlying MockEvalContext.

Directories

PathSynopsis
result

Package batcheval imports 36 packages (graph) and is imported by 5 packages. Updated 2020-08-12. Refresh now. Tools for package owners.