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

package kv

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

Package kv provides a key-value API to an underlying cockroach datastore. Cockroach itself provides a single, monolithic, sorted key value map, distributed over multiple nodes. Each node holds a set of key ranges. Package kv translates between the monolithic, logical map which Cockroach clients experience to the physically distributed key ranges which comprise the whole.

Package kv implements the logic necessary to locate appropriate nodes based on keys being read or written. In some cases, requests may span a range of keys, in which case multiple RPCs may be sent out.

Index

Package Files

batch.go dist_sender.go dist_sender_rangefeed.go doc.go leaseholder_cache.go local_test_cluster_util.go range_cache.go range_iter.go replica_slice.go testing_knobs.go transport.go transport_regular.go txn_coord_sender.go txn_interceptor_committer.go txn_interceptor_heartbeater.go txn_interceptor_metric_recorder.go txn_interceptor_pipeliner.go txn_interceptor_seq_num_allocator.go txn_interceptor_span_refresher.go txnstate_string.go

Variables

var CanSendToFollower = func(
    clusterID uuid.UUID, st *cluster.Settings, ba roachpb.BatchRequest,
) bool {
    return false
}

CanSendToFollower is used by the DistSender to determine if it needs to look up the current lease holder for a request. It is used by the followerreadsccl code to inject logic to check if follower reads are enabled. By default, without CCL code, this function returns false.

var MaxTxnRefreshSpansBytes = settings.RegisterIntSetting(
    "kv.transaction.max_refresh_spans_bytes",
    "maximum number of bytes used to track refresh spans in serializable transactions",
    256*1000,
)

MaxTxnRefreshSpansBytes is a threshold in bytes for refresh spans stored on the coordinator during the lifetime of a transaction. Refresh spans are used for SERIALIZABLE transactions to avoid client restarts.

func InitFactoryForLocalTestCluster Uses

func InitFactoryForLocalTestCluster(
    st *cluster.Settings,
    nodeDesc *roachpb.NodeDescriptor,
    tracer opentracing.Tracer,
    clock *hlc.Clock,
    latency time.Duration,
    stores client.Sender,
    stopper *stop.Stopper,
    gossip *gossip.Gossip,
) client.TxnSenderFactory

InitFactoryForLocalTestCluster initializes a TxnCoordSenderFactory that can be used with LocalTestCluster.

type ClientTestingKnobs Uses

type ClientTestingKnobs struct {
    // The RPC dispatcher. Defaults to grpc but can be changed here for
    // testing purposes.
    TransportFactory TransportFactory

    // The maximum number of times a txn will attempt to refresh its
    // spans for a single transactional batch.
    // 0 means use a default. -1 means disable refresh.
    MaxTxnRefreshAttempts int
}

ClientTestingKnobs contains testing options that dictate the behavior of the key-value client.

func (*ClientTestingKnobs) ModuleTestingKnobs Uses

func (*ClientTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type DistSender Uses

type DistSender struct {
    log.AmbientContext
    // contains filtered or unexported fields
}

A DistSender provides methods to access Cockroach's monolithic, distributed key value store. Each method invocation triggers a lookup or lookups to find replica metadata for implicated key ranges. RPCs are sent to one or more of the replicas to satisfy the method invocation.

func NewDistSender Uses

func NewDistSender(cfg DistSenderConfig, g *gossip.Gossip) *DistSender

NewDistSender returns a batch.Sender instance which connects to the Cockroach cluster via the supplied gossip instance. Supplying a DistSenderContext or the fields within is optional. For omitted values, sane defaults will be used.

func NewDistSenderForLocalTestCluster Uses

func NewDistSenderForLocalTestCluster(
    st *cluster.Settings,
    nodeDesc *roachpb.NodeDescriptor,
    tracer opentracing.Tracer,
    clock *hlc.Clock,
    latency time.Duration,
    stores client.Sender,
    stopper *stop.Stopper,
    g *gossip.Gossip,
) *DistSender

NewDistSenderForLocalTestCluster creates a DistSender for a LocalTestCluster.

func (*DistSender) CountRanges Uses

func (ds *DistSender) CountRanges(ctx context.Context, rs roachpb.RSpan) (int64, error)

CountRanges returns the number of ranges that encompass the given key span.

func (*DistSender) DisableFirstRangeUpdates Uses

func (ds *DistSender) DisableFirstRangeUpdates()

DisableFirstRangeUpdates disables updates of the first range via gossip. Used by tests which want finer control of the contents of the range cache.

func (*DistSender) DisableParallelBatches Uses

func (ds *DistSender) DisableParallelBatches()

DisableParallelBatches instructs DistSender to never parallelize the transmission of partial batch requests across ranges.

func (*DistSender) FirstRange Uses

func (ds *DistSender) FirstRange() (*roachpb.RangeDescriptor, error)

FirstRange implements the RangeDescriptorDB interface. FirstRange returns the RangeDescriptor for the first range on the cluster, which is retrieved from the gossip protocol instead of the datastore.

func (*DistSender) LeaseHolderCache Uses

func (ds *DistSender) LeaseHolderCache() *LeaseHolderCache

LeaseHolderCache gives access to the DistSender's lease cache.

func (*DistSender) Metrics Uses

func (ds *DistSender) Metrics() DistSenderMetrics

Metrics returns a struct which contains metrics related to the distributed sender's activity.

func (*DistSender) RangeDescriptorCache Uses

func (ds *DistSender) RangeDescriptorCache() *RangeDescriptorCache

RangeDescriptorCache gives access to the DistSender's range cache.

func (*DistSender) RangeFeed Uses

func (ds *DistSender) RangeFeed(
    ctx context.Context, span roachpb.Span, ts hlc.Timestamp, eventCh chan<- *roachpb.RangeFeedEvent,
) error

RangeFeed divides a RangeFeed request on range boundaries and establishes a RangeFeed to each of the individual ranges. It streams back results on the provided channel.

Note that the timestamps in RangeFeedCheckpoint events that are streamed back may be lower than the timestamp given here.

func (*DistSender) RangeLookup Uses

func (ds *DistSender) RangeLookup(
    ctx context.Context, key roachpb.RKey, useReverseScan bool,
) ([]roachpb.RangeDescriptor, []roachpb.RangeDescriptor, error)

RangeLookup implements the RangeDescriptorDB interface. It uses LookupRange to perform a lookup scan for the provided key, using DistSender itself as the client.Sender. This means that the scan will recurse into DistSender, which will in turn use the RangeDescriptorCache again to lookup the RangeDescriptor necessary to perform the scan.

func (*DistSender) Send Uses

func (ds *DistSender) Send(
    ctx context.Context, ba roachpb.BatchRequest,
) (*roachpb.BatchResponse, *roachpb.Error)

Send implements the batch.Sender interface. It subdivides the Batch into batches admissible for sending (preventing certain illegal mixtures of requests), executes each individual part (which may span multiple ranges), and recombines the response.

When the request spans ranges, it is split by range and a partial subset of the batch request is sent to affected ranges in parallel.

Note that on error, this method will return any batch responses for successfully processed batch requests. This allows the caller to deal with potential retry situations where a batch is split so that EndTransaction is processed alone, after earlier requests in the batch succeeded. Where possible, the caller may be able to update spans encountered in the transaction and retry just the EndTransaction request to avoid client-side serializable txn retries.

type DistSenderConfig Uses

type DistSenderConfig struct {
    AmbientCtx log.AmbientContext

    Settings        *cluster.Settings
    Clock           *hlc.Clock
    RPCRetryOptions *retry.Options

    RPCContext        *rpc.Context
    RangeDescriptorDB RangeDescriptorDB

    NodeDialer *nodedialer.Dialer

    TestingKnobs ClientTestingKnobs
    // contains filtered or unexported fields
}

DistSenderConfig holds configuration and auxiliary objects that can be passed to NewDistSender.

type DistSenderMetrics Uses

type DistSenderMetrics struct {
    BatchCount              *metric.Counter
    PartialBatchCount       *metric.Counter
    AsyncSentCount          *metric.Counter
    AsyncThrottledCount     *metric.Counter
    SentCount               *metric.Counter
    LocalSentCount          *metric.Counter
    NextReplicaErrCount     *metric.Counter
    NotLeaseHolderErrCount  *metric.Counter
    InLeaseTransferBackoffs *metric.Counter
    RangeLookups            *metric.Counter
}

DistSenderMetrics is the set of metrics for a given distributed sender.

type EvictionToken Uses

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

EvictionToken holds eviction state between calls to LookupRangeDescriptor.

func (*EvictionToken) Evict Uses

func (et *EvictionToken) Evict(ctx context.Context) error

Evict instructs the EvictionToken to evict the RangeDescriptor it was created with from the rangeDescriptorCache.

func (*EvictionToken) EvictAndReplace Uses

func (et *EvictionToken) EvictAndReplace(
    ctx context.Context, newDescs ...roachpb.RangeDescriptor,
) error

EvictAndReplace instructs the EvictionToken to evict the RangeDescriptor it was created with from the rangeDescriptorCache. It also allows the user to provide new RangeDescriptors to insert into the cache, all atomically. When called without arguments, EvictAndReplace will behave the same as Evict.

type LatencyFunc Uses

type LatencyFunc func(string) (time.Duration, bool)

A LatencyFunc returns the latency from this node to a remote address and a bool indicating whether the latency is valid.

type LeaseHolderCache Uses

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

A LeaseHolderCache is a cache of replica descriptors keyed by range ID.

func NewLeaseHolderCache Uses

func NewLeaseHolderCache(size func() int64) *LeaseHolderCache

NewLeaseHolderCache creates a new leaseHolderCache of the given size. The underlying cache internally uses a hash map, so lookups are cheap.

func (*LeaseHolderCache) Lookup Uses

func (lc *LeaseHolderCache) Lookup(
    ctx context.Context, rangeID roachpb.RangeID,
) (roachpb.StoreID, bool)

Lookup returns the cached leader of the given range ID.

func (*LeaseHolderCache) Update Uses

func (lc *LeaseHolderCache) Update(
    ctx context.Context, rangeID roachpb.RangeID, storeID roachpb.StoreID,
)

Update invalidates the cached leader for the given range ID. If an empty replica descriptor is passed, the cached leader is evicted. Otherwise, the passed-in replica descriptor is cached.

type LeaseHolderCacheShard Uses

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

A LeaseHolderCacheShard is a cache of replica descriptors keyed by range ID.

type RangeDescriptorCache Uses

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

RangeDescriptorCache is used to retrieve range descriptors for arbitrary keys. Descriptors are initially queried from storage using a RangeDescriptorDB, but are cached for subsequent lookups.

func NewRangeDescriptorCache Uses

func NewRangeDescriptorCache(
    st *cluster.Settings, db RangeDescriptorDB, size func() int64,
) *RangeDescriptorCache

NewRangeDescriptorCache returns a new RangeDescriptorCache which uses the given RangeDescriptorDB as the underlying source of range descriptors.

func (*RangeDescriptorCache) Clear Uses

func (rdc *RangeDescriptorCache) Clear()

Clear clears all RangeDescriptors from the RangeDescriptorCache.

func (*RangeDescriptorCache) EvictCachedRangeDescriptor Uses

func (rdc *RangeDescriptorCache) EvictCachedRangeDescriptor(
    ctx context.Context, descKey roachpb.RKey, seenDesc *roachpb.RangeDescriptor, inverted bool,
) error

EvictCachedRangeDescriptor will evict any cached user-space and meta range descriptors for the given key. It is intended that this method be called from a consumer of rangeDescriptorCache through the EvictionToken abstraction if the returned range descriptor is discovered to be stale.

seenDesc should always be passed in if available, and is used as the basis of a pointer-based compare-and-evict strategy. This means that if the cache does not contain the provided descriptor, no descriptor will be evicted. If seenDesc is nil, eviction is unconditional.

`inverted` determines the behavior at the range boundary, similar to how it does in GetCachedRangeDescriptor.

func (*RangeDescriptorCache) GetCachedRangeDescriptor Uses

func (rdc *RangeDescriptorCache) GetCachedRangeDescriptor(
    key roachpb.RKey, inverted bool,
) (*roachpb.RangeDescriptor, error)

GetCachedRangeDescriptor retrieves the descriptor of the range which contains the given key. It returns nil if the descriptor is not found in the cache.

`inverted` determines the behavior at the range boundary: If set to true and `key` is the EndKey and StartKey of two adjacent ranges, the first range is returned instead of the second (which technically contains the given key).

func (*RangeDescriptorCache) InsertRangeDescriptors Uses

func (rdc *RangeDescriptorCache) InsertRangeDescriptors(
    ctx context.Context, rs ...roachpb.RangeDescriptor,
) error

InsertRangeDescriptors inserts the provided descriptors in the cache. This is a no-op for the descriptors that are already present in the cache.

func (*RangeDescriptorCache) LookupRangeDescriptor Uses

func (rdc *RangeDescriptorCache) LookupRangeDescriptor(
    ctx context.Context, key roachpb.RKey,
) (*roachpb.RangeDescriptor, error)

LookupRangeDescriptor presents a simpler interface for looking up a RangeDescriptor for a key without the eviction tokens or scan direction control of LookupRangeDescriptorWithEvictionToken. This method is exported to lower level clients through the kvbase.RangeDescriptorCache interface.

func (*RangeDescriptorCache) LookupRangeDescriptorWithEvictionToken Uses

func (rdc *RangeDescriptorCache) LookupRangeDescriptorWithEvictionToken(
    ctx context.Context, key roachpb.RKey, evictToken *EvictionToken, useReverseScan bool,
) (*roachpb.RangeDescriptor, *EvictionToken, error)

LookupRangeDescriptorWithEvictionToken attempts to locate a descriptor for the range containing the given Key. This is done by first trying the cache, and then querying the two-level lookup table of range descriptors which cockroach maintains. The function should be provided with an EvictionToken if one was acquired from this function on a previous lookup. If not, an empty EvictionToken can be provided.

This method first looks up the specified key in the first level of range metadata, which returns the location of the key within the second level of range metadata. This second level location is then queried to retrieve a descriptor for the range where the key's value resides. Range descriptors retrieved during each search are cached for subsequent lookups.

This method returns the RangeDescriptor for the range containing the key's data and a token to manage evicting the RangeDescriptor if it is found to be stale, or an error if any occurred.

func (*RangeDescriptorCache) String Uses

func (rdc *RangeDescriptorCache) String() string

type RangeDescriptorDB Uses

type RangeDescriptorDB interface {
    // RangeLookup takes a key to look up descriptors for. Two slices of range
    // descriptors are returned. The first of these slices holds descriptors
    // whose [startKey,endKey) spans contain the given key (possibly from
    // intents), and the second holds prefetched adjacent descriptors.
    RangeLookup(
        ctx context.Context, key roachpb.RKey, useReverseScan bool,
    ) ([]roachpb.RangeDescriptor, []roachpb.RangeDescriptor, error)

    // FirstRange returns the descriptor for the first Range. This is the
    // Range containing all meta1 entries.
    FirstRange() (*roachpb.RangeDescriptor, error)
}

RangeDescriptorDB is a type which can query range descriptors from an underlying datastore. This interface is used by rangeDescriptorCache to initially retrieve information which will be cached.

type RangeIterator Uses

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

A RangeIterator provides a mechanism for iterating over all ranges in a key span. A new RangeIterator must be positioned with Seek() to begin iteration.

RangeIterator is not thread-safe.

func NewRangeIterator Uses

func NewRangeIterator(ds *DistSender) *RangeIterator

NewRangeIterator creates a new RangeIterator.

func (*RangeIterator) Desc Uses

func (ri *RangeIterator) Desc() *roachpb.RangeDescriptor

Desc returns the descriptor of the range at which the iterator is currently positioned. The iterator must be valid.

func (*RangeIterator) Error Uses

func (ri *RangeIterator) Error() *roachpb.Error

Error returns the error the iterator encountered, if any. If the iterator has not been initialized, returns iterator error.

func (*RangeIterator) Key Uses

func (ri *RangeIterator) Key() roachpb.RKey

Key returns the current key. The iterator must be valid.

func (*RangeIterator) NeedAnother Uses

func (ri *RangeIterator) NeedAnother(rs roachpb.RSpan) bool

NeedAnother checks whether the iteration needs to continue to cover the remainder of the ranges described by the supplied key span. The iterator must be valid.

func (*RangeIterator) Next Uses

func (ri *RangeIterator) Next(ctx context.Context)

Next advances the iterator to the next range. The direction of advance is dependent on whether the iterator is reversed. The iterator must be valid.

func (*RangeIterator) Reset Uses

func (ri *RangeIterator) Reset()

Reset resets the RangeIterator to its initial state.

func (*RangeIterator) Seek Uses

func (ri *RangeIterator) Seek(ctx context.Context, key roachpb.RKey, scanDir ScanDirection)

Seek positions the iterator at the specified key.

func (*RangeIterator) Token Uses

func (ri *RangeIterator) Token() *EvictionToken

Token returns the eviction token corresponding to the range descriptor for the current iteration. The iterator must be valid.

func (*RangeIterator) Valid Uses

func (ri *RangeIterator) Valid() bool

Valid returns whether the iterator is valid. To be valid, the iterator must be have been seeked to an initial position using Seek(), and must not have encountered an error.

type ReplicaInfo Uses

type ReplicaInfo struct {
    roachpb.ReplicaDescriptor
    NodeDesc *roachpb.NodeDescriptor
}

ReplicaInfo extends the Replica structure with the associated node descriptor.

type ReplicaSlice Uses

type ReplicaSlice []ReplicaInfo

A ReplicaSlice is a slice of ReplicaInfo.

func NewReplicaSlice Uses

func NewReplicaSlice(gossip *gossip.Gossip, replicas []roachpb.ReplicaDescriptor) ReplicaSlice

NewReplicaSlice creates a ReplicaSlice from the replicas listed in the range descriptor and using gossip to lookup node descriptors. Replicas on nodes that are not gossiped are omitted from the result.

func (ReplicaSlice) FindReplica Uses

func (rs ReplicaSlice) FindReplica(storeID roachpb.StoreID) int

FindReplica returns the index of the replica which matches the specified store ID. If no replica matches, -1 is returned.

func (ReplicaSlice) Len Uses

func (rs ReplicaSlice) Len() int

Len returns the total number of replicas in the slice.

func (ReplicaSlice) MoveToFront Uses

func (rs ReplicaSlice) MoveToFront(i int)

MoveToFront moves the replica at the given index to the front of the slice, keeping the order of the remaining elements stable. The function will panic when invoked with an invalid index.

func (ReplicaSlice) OptimizeReplicaOrder Uses

func (rs ReplicaSlice) OptimizeReplicaOrder(
    nodeDesc *roachpb.NodeDescriptor, latencyFn LatencyFunc,
)

OptimizeReplicaOrder sorts the replicas in the order in which they're to be used for sending RPCs (meaning in the order in which they'll be probed for the lease). Lower latency and "closer" (matching in more attributes) replicas are ordered first. If the current node is a replica, then it'll be the first one.

nodeDesc is the descriptor of the current node. It can be nil, in which case information about the current descriptor is not used in optimizing the order.

Note that this method is not concerned with any information the node might have about who the lease holder might be. If the leaseholder is known by the caller, the caller will move it to the front if appropriate.

func (ReplicaSlice) Swap Uses

func (rs ReplicaSlice) Swap(i, j int)

Swap swaps the replicas with indexes i and j.

type ScanDirection Uses

type ScanDirection byte

ScanDirection determines the semantics of RangeIterator.Next() and RangeIterator.NeedAnother().

const (
    // Ascending means Next() will advance towards keys that compare higher.
    Ascending ScanDirection = iota
    // Descending means Next() will advance towards keys that compare lower.
    Descending
)

type SendOptions Uses

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

A SendOptions structure describes the algorithm for sending RPCs to one or more replicas, depending on error conditions and how many successful responses are required.

type Transport Uses

type Transport interface {
    // IsExhausted returns true if there are no more replicas to try.
    IsExhausted() bool

    // SendNext synchronously sends the BatchRequest rpc to the next replica.
    // May panic if the transport is exhausted.
    //
    // SendNext is also in charge of importing the remotely collected spans (if
    // any) into the local trace.
    SendNext(context.Context, roachpb.BatchRequest) (*roachpb.BatchResponse, error)

    // NextInternalClient returns the InternalClient to use for making RPC
    // calls. Returns a context.Context which should be used when making RPC
    // calls on the returned server (This context is annotated to mark this
    // request as in-process and bypass ctx.Peer checks).
    NextInternalClient(context.Context) (context.Context, roachpb.InternalClient, error)

    // NextReplica returns the replica descriptor of the replica to be tried in
    // the next call to SendNext. MoveToFront will cause the return value to
    // change. Returns a zero value if the transport is exhausted.
    NextReplica() roachpb.ReplicaDescriptor

    // MoveToFront locates the specified replica and moves it to the
    // front of the ordering of replicas to try. If the replica has
    // already been tried, it will be retried. If the specified replica
    // can't be found, this is a noop.
    MoveToFront(roachpb.ReplicaDescriptor)
}

Transport objects can send RPCs to one or more replicas of a range. All calls to Transport methods are made from a single thread, so Transports are not required to be thread-safe.

func GRPCTransportFactory Uses

func GRPCTransportFactory(
    opts SendOptions, nodeDialer *nodedialer.Dialer, replicas ReplicaSlice,
) (Transport, error)

GRPCTransportFactory is the default TransportFactory, using GRPC.

type TransportFactory Uses

type TransportFactory func(
    SendOptions, *nodedialer.Dialer, ReplicaSlice,
) (Transport, error)

TransportFactory encapsulates all interaction with the RPC subsystem, allowing it to be mocked out for testing. The factory function returns a Transport object which is used to send requests to one or more replicas in the slice.

In addition to actually sending RPCs, the transport is responsible for ordering replicas in accordance with SendOptions.Ordering and transport-specific knowledge such as connection health or latency.

TODO(bdarnell): clean up this crufty interface; it was extracted verbatim from the non-abstracted code.

func SenderTransportFactory Uses

func SenderTransportFactory(tracer opentracing.Tracer, sender client.Sender) TransportFactory

SenderTransportFactory wraps a client.Sender for use as a KV Transport. This is useful for tests that want to use DistSender without a full RPC stack.

type TxnCoordSender Uses

type TxnCoordSender struct {

    // A pointer member to the creating factory provides access to
    // immutable factory settings.
    *TxnCoordSenderFactory
    // contains filtered or unexported fields
}

A TxnCoordSender is the production implementation of client.TxnSender. It is a Sender which wraps a lower-level Sender (a DistSender) to which it sends commands. It works on behalf of the client to keep a transaction's state (e.g. intents) and to perform periodic heartbeating of the transaction required when necessary. Unlike other senders, TxnCoordSender is not a singleton - an instance is created for every transaction by the TxnCoordSenderFactory.

Among the functions it performs are: - Heartbeating of the transaction record. Note that heartbeating is done only from the root transaction coordinator, in the event that multiple coordinators are active (i.e. in a distributed SQL flow). - Accumulating intent spans. - Attaching intent spans to EndTransaction requests, for intent cleanup. - Handles retriable errors by either bumping the transaction's epoch or, in case of TransactionAbortedErrors, cleaning up the transaction (in this case, the client.Txn is expected to create a new TxnCoordSender instance transparently for the higher-level client).

Since it is stateful, the TxnCoordSender needs to understand when a transaction is "finished" and the state can be destroyed. As such there's a contract that the client.Txn needs obey. Read-only transactions don't matter - they're stateless. For the others, once a BeginTransaction is sent by the client, the TxnCoordSender considers the transactions completed in the following situations: - A batch containing an EndTransactions (commit or rollback) succeeds. - A batch containing an EndTransaction(commit=false) succeeds or fails. Only more rollback attempts can follow a rollback attempt. - A batch returns a TransactionAbortedError. As mentioned above, the client is expected to create a new TxnCoordSender for the next transaction attempt.

Note that "1PC" batches (i.e. batches containing both a Begin and an EndTransaction) are no exception from the contract - if the batch fails, the client is expected to send a rollback (or perform another transaction attempt in case of retriable errors).

func (*TxnCoordSender) AnchorOnSystemConfigRange Uses

func (tc *TxnCoordSender) AnchorOnSystemConfigRange() error

AnchorOnSystemConfigRange is part of the client.TxnSender interface.

func (*TxnCoordSender) AugmentMeta Uses

func (tc *TxnCoordSender) AugmentMeta(ctx context.Context, meta roachpb.TxnCoordMeta)

AugmentMeta is part of the client.TxnSender interface.

func (*TxnCoordSender) CommitTimestamp Uses

func (tc *TxnCoordSender) CommitTimestamp() hlc.Timestamp

CommitTimestamp is part of the client.TxnSender interface.

func (*TxnCoordSender) CommitTimestampFixed Uses

func (tc *TxnCoordSender) CommitTimestampFixed() bool

CommitTimestampFixed is part of the client.TxnSender interface.

func (*TxnCoordSender) DisablePipelining Uses

func (tc *TxnCoordSender) DisablePipelining() error

DisablePipelining is part of the client.TxnSender interface.

func (*TxnCoordSender) Epoch Uses

func (tc *TxnCoordSender) Epoch() enginepb.TxnEpoch

Epoch is part of the client.TxnSender interface.

func (*TxnCoordSender) GetMeta Uses

func (tc *TxnCoordSender) GetMeta(
    ctx context.Context, opt client.TxnStatusOpt,
) (roachpb.TxnCoordMeta, error)

GetMeta is part of the client.TxnSender interface.

func (*TxnCoordSender) IsSerializablePushAndRefreshNotPossible Uses

func (tc *TxnCoordSender) IsSerializablePushAndRefreshNotPossible() bool

IsSerializablePushAndRefreshNotPossible is part of the client.TxnSender interface.

func (*TxnCoordSender) IsTracking Uses

func (tc *TxnCoordSender) IsTracking() bool

IsTracking returns true if the heartbeat loop is running.

func (*TxnCoordSender) ManualRestart Uses

func (tc *TxnCoordSender) ManualRestart(
    ctx context.Context, pri roachpb.UserPriority, ts hlc.Timestamp,
)

ManualRestart is part of the client.TxnSender interface.

func (*TxnCoordSender) OnFinish Uses

func (tc *TxnCoordSender) OnFinish(onFinishFn func(error))

OnFinish is part of the client.TxnSender interface.

func (*TxnCoordSender) OrigTimestamp Uses

func (tc *TxnCoordSender) OrigTimestamp() hlc.Timestamp

OrigTimestamp is part of the client.TxnSender interface.

func (*TxnCoordSender) Send Uses

func (tc *TxnCoordSender) Send(
    ctx context.Context, ba roachpb.BatchRequest,
) (*roachpb.BatchResponse, *roachpb.Error)

Send is part of the client.TxnSender interface.

func (*TxnCoordSender) SerializeTxn Uses

func (tc *TxnCoordSender) SerializeTxn() *roachpb.Transaction

SerializeTxn is part of the client.TxnSender interface.

func (*TxnCoordSender) SetDebugName Uses

func (tc *TxnCoordSender) SetDebugName(name string)

SetDebugName is part of the client.TxnSender interface.

func (*TxnCoordSender) SetFixedTimestamp Uses

func (tc *TxnCoordSender) SetFixedTimestamp(ctx context.Context, ts hlc.Timestamp)

SetFixedTimestamp is part of the client.TxnSender interface.

func (*TxnCoordSender) SetUserPriority Uses

func (tc *TxnCoordSender) SetUserPriority(pri roachpb.UserPriority) error

SetUserPriority is part of the client.TxnSender interface.

func (*TxnCoordSender) TxnStatus Uses

func (tc *TxnCoordSender) TxnStatus() roachpb.TransactionStatus

TxnStatus is part of the client.TxnSender interface.

func (*TxnCoordSender) UpdateStateOnRemoteRetryableErr Uses

func (tc *TxnCoordSender) UpdateStateOnRemoteRetryableErr(
    ctx context.Context, pErr *roachpb.Error,
) *roachpb.Error

UpdateStateOnRemoteRetryableErr is part of the TxnSender interface.

type TxnCoordSenderFactory Uses

type TxnCoordSenderFactory struct {
    log.AmbientContext
    // contains filtered or unexported fields
}

TxnCoordSenderFactory implements client.TxnSenderFactory.

func NewTxnCoordSenderFactory Uses

func NewTxnCoordSenderFactory(
    cfg TxnCoordSenderFactoryConfig, wrapped client.Sender,
) *TxnCoordSenderFactory

NewTxnCoordSenderFactory creates a new TxnCoordSenderFactory. The factory creates new instances of TxnCoordSenders.

func (*TxnCoordSenderFactory) Metrics Uses

func (tcf *TxnCoordSenderFactory) Metrics() TxnMetrics

Metrics returns the factory's metrics struct.

func (*TxnCoordSenderFactory) NonTransactionalSender Uses

func (tcf *TxnCoordSenderFactory) NonTransactionalSender() client.Sender

NonTransactionalSender is part of the TxnSenderFactory interface.

func (*TxnCoordSenderFactory) TransactionalSender Uses

func (tcf *TxnCoordSenderFactory) TransactionalSender(
    typ client.TxnType, meta roachpb.TxnCoordMeta,
) client.TxnSender

TransactionalSender is part of the TxnSenderFactory interface.

type TxnCoordSenderFactoryConfig Uses

type TxnCoordSenderFactoryConfig struct {
    AmbientCtx log.AmbientContext

    Settings *cluster.Settings
    Clock    *hlc.Clock
    Stopper  *stop.Stopper

    HeartbeatInterval time.Duration
    Linearizable      bool
    Metrics           TxnMetrics

    TestingKnobs ClientTestingKnobs
}

TxnCoordSenderFactoryConfig holds configuration and auxiliary objects that can be passed to NewTxnCoordSenderFactory.

type TxnMetrics Uses

type TxnMetrics struct {
    Aborts          *metric.Counter
    Commits         *metric.Counter
    Commits1PC      *metric.Counter // Commits which finished in a single phase
    ParallelCommits *metric.Counter // Commits which entered the STAGING state
    AutoRetries     *metric.Counter // Auto retries which avoid client-side restarts
    Durations       *metric.Histogram

    // Restarts is the number of times we had to restart the transaction.
    Restarts *metric.Histogram

    // Counts of restart types.
    RestartsWriteTooOld           telemetry.CounterWithMetric
    RestartsWriteTooOldMulti      telemetry.CounterWithMetric
    RestartsSerializable          telemetry.CounterWithMetric
    RestartsPossibleReplay        telemetry.CounterWithMetric
    RestartsAsyncWriteFailure     telemetry.CounterWithMetric
    RestartsReadWithinUncertainty telemetry.CounterWithMetric
    RestartsTxnAborted            telemetry.CounterWithMetric
    RestartsTxnPush               telemetry.CounterWithMetric
    RestartsUnknown               telemetry.CounterWithMetric
}

TxnMetrics holds all metrics relating to KV transactions.

func MakeTxnMetrics Uses

func MakeTxnMetrics(histogramWindow time.Duration) TxnMetrics

MakeTxnMetrics returns a TxnMetrics struct that contains metrics whose windowed portions retain data for approximately histogramWindow.

Directories

PathSynopsis
kvbasePackage kvbase exports kv level interfaces to avoid dependency cycles.

Package kv imports 46 packages (graph) and is imported by 18 packages. Updated 2019-09-07. Refresh now. Tools for package owners.