cockroach: Index | Files

package gc

import ""

Package gc contains the logic to run scan a range for garbage and issue GC requests to remove that garbage.

The Run function is the primary entry point and is called underneath the gcQueue in the storage package. It can also be run for debugging.


Package Files

gc.go gc_iterator.go


const (
    // IntentAgeThreshold is the threshold after which an extant intent
    // will be resolved.
    IntentAgeThreshold = 2 * time.Hour // 2 hour

    // KeyVersionChunkBytes is the threshold size for splitting
    // GCRequests into multiple batches. The goal is that the evaluated
    // Raft command for each GCRequest does not significantly exceed
    // this threshold.
    KeyVersionChunkBytes = base.ChunkRaftCommandThresholdBytes

func CalculateThreshold Uses

func CalculateThreshold(now hlc.Timestamp, policy zonepb.GCPolicy) (threshold hlc.Timestamp)

CalculateThreshold calculates the GC threshold given the policy and the current view of time.

func TimestampForThreshold Uses

func TimestampForThreshold(threshold hlc.Timestamp, policy zonepb.GCPolicy) (ts hlc.Timestamp)

TimestampForThreshold inverts CalculateThreshold. It returns the timestamp which should be used for now to arrive at the passed threshold.

type CleanupIntentsFunc Uses

type CleanupIntentsFunc func(context.Context, []roachpb.Intent) error

CleanupIntentsFunc synchronously resolves the supplied intents (which may be PENDING, in which case they are first pushed) while taking care of proper batching.

type CleanupTxnIntentsAsyncFunc Uses

type CleanupTxnIntentsAsyncFunc func(context.Context, *roachpb.Transaction, []roachpb.LockUpdate) error

CleanupTxnIntentsAsyncFunc asynchronously cleans up intents from a transaction record, pushing the transaction first if it is PENDING. Once all intents are resolved successfully, removes the transaction record.

type GCer Uses

type GCer interface {

A GCer is an abstraction used by the GC queue to carry out chunked deletions.

type Info Uses

type Info struct {
    // Now is the timestamp used for age computations.
    Now hlc.Timestamp
    // Policy is the policy used for this garbage collection cycle.
    Policy zonepb.GCPolicy
    // Stats about the userspace key-values considered, namely the number of
    // keys with GC'able data, the number of "old" intents and the number of
    // associated distinct transactions.
    NumKeysAffected, IntentsConsidered, IntentTxns int
    // TransactionSpanTotal is the total number of entries in the transaction span.
    TransactionSpanTotal int
    // Summary of transactions which were found GCable (assuming that
    // potentially necessary intent resolutions did not fail).
    TransactionSpanGCAborted, TransactionSpanGCCommitted int
    TransactionSpanGCStaging, TransactionSpanGCPending   int
    // AbortSpanTotal is the total number of transactions present in the AbortSpan.
    AbortSpanTotal int
    // AbortSpanConsidered is the number of AbortSpan entries old enough to be
    // considered for removal. An "entry" corresponds to one transaction;
    // more than one key-value pair may be associated with it.
    AbortSpanConsidered int
    // AbortSpanGCNum is the number of AbortSpan entries fit for removal (due
    // to their transactions having terminated).
    AbortSpanGCNum int
    // PushTxn is the total number of pushes attempted in this cycle.
    PushTxn int
    // ResolveTotal is the total number of attempted intent resolutions in
    // this cycle.
    ResolveTotal int
    // Threshold is the computed expiration timestamp. Equal to `Now - Policy`.
    Threshold hlc.Timestamp
    // AffectedVersionsKeyBytes is the number of (fully encoded) bytes deleted from keys in the storage engine.
    // Note that this does not account for compression that the storage engine uses to store data on disk. Real
    // space savings tends to be smaller due to this compression, and space may be released only at a later point
    // in time.
    AffectedVersionsKeyBytes int64
    // AffectedVersionsValBytes is the number of (fully encoded) bytes deleted from values in the storage engine.
    // See AffectedVersionsKeyBytes for caveats.
    AffectedVersionsValBytes int64

Info contains statistics and insights from a GC run.

func Run Uses

func Run(
    ctx context.Context,
    desc *roachpb.RangeDescriptor,
    snap storage.Reader,
    now, newThreshold hlc.Timestamp,
    policy zonepb.GCPolicy,
    gcer GCer,
    cleanupIntentsFn CleanupIntentsFunc,
    cleanupTxnIntentsAsyncFn CleanupTxnIntentsAsyncFunc,
) (Info, error)

Run runs garbage collection for the specified descriptor on the provided Engine (which is not mutated). It uses the provided gcFn to run garbage collection once on all implicated spans, cleanupIntentsFn to resolve intents synchronously, and cleanupTxnIntentsAsyncFn to asynchronously cleanup intents and associated transaction record on success.

type NoopGCer Uses

type NoopGCer struct{}

NoopGCer implements GCer by doing nothing.

func (NoopGCer) GC Uses

func (NoopGCer) GC(context.Context, []roachpb.GCRequest_GCKey) error

GC implements storage.GCer.

func (NoopGCer) SetGCThreshold Uses

func (NoopGCer) SetGCThreshold(context.Context, Threshold) error

SetGCThreshold implements storage.GCer.

type PureGCer Uses

type PureGCer interface {
    GC(context.Context, []roachpb.GCRequest_GCKey) error

PureGCer is part of the GCer interface.

type Threshold Uses

type Threshold struct {
    Key hlc.Timestamp
    Txn hlc.Timestamp

Threshold holds the key and txn span GC thresholds, respectively.

type Thresholder Uses

type Thresholder interface {
    SetGCThreshold(context.Context, Threshold) error

Thresholder is part of the GCer interface.

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