cockroach: github.com/cockroachdb/cockroach/pkg/storage/stateloader Index | Files

package stateloader

import "github.com/cockroachdb/cockroach/pkg/storage/stateloader"

Index

Package Files

initial.go stateloader.go

func WriteInitialReplicaState Uses

func WriteInitialReplicaState(
    ctx context.Context,
    eng engine.ReadWriter,
    ms enginepb.MVCCStats,
    desc roachpb.RangeDescriptor,
    lease roachpb.Lease,
    gcThreshold hlc.Timestamp,
    activeVersion roachpb.Version,
    truncStateType TruncatedStateType,
) (enginepb.MVCCStats, error)

WriteInitialReplicaState sets up a new Range, but without writing an associated Raft state (which must be written separately via synthesizeRaftState before instantiating a Replica). The main task is to persist a ReplicaState which does not start from zero but presupposes a few entries already having applied. The supplied MVCCStats are used for the Stats field after adjusting for persisting the state itself, and the updated stats are returned.

Args: activeVersion: The cluster's version.

func WriteInitialState Uses

func WriteInitialState(
    ctx context.Context,
    eng engine.ReadWriter,
    ms enginepb.MVCCStats,
    desc roachpb.RangeDescriptor,
    lease roachpb.Lease,
    gcThreshold hlc.Timestamp,
    bootstrapVersion roachpb.Version,
    truncStateType TruncatedStateType,
) (enginepb.MVCCStats, error)

WriteInitialState calls WriteInitialReplicaState followed by SynthesizeRaftState. It is typically called during bootstrap. The supplied MVCCStats are used for the Stats field after adjusting for persisting the state itself, and the updated stats are returned.

Args: bootstrapVersion: The version at which the cluster is bootstrapped.

type StateLoader Uses

type StateLoader struct {
    keys.RangeIDPrefixBuf
}

StateLoader contains accessor methods to read or write the fields of storagebase.ReplicaState. It contains an internal buffer which is reused to avoid an allocation on frequently-accessed code paths.

Because of this internal buffer, this struct is not safe for concurrent use, and the return values of methods that return keys are invalidated the next time any method is called.

It is safe to have multiple replicaStateLoaders for the same Replica. Reusable replicaStateLoaders are typically found in a struct with a mutex, and temporary loaders may be created when locking is less desirable than an allocation.

func Make Uses

func Make(rangeID roachpb.RangeID) StateLoader

Make creates a a StateLoader.

func (StateLoader) AssertNoRangeAppliedState Uses

func (rsl StateLoader) AssertNoRangeAppliedState(ctx context.Context, reader engine.Reader) error

AssertNoRangeAppliedState asserts that no Range applied state key is present.

func (StateLoader) CalcAppliedIndexSysBytes Uses

func (rsl StateLoader) CalcAppliedIndexSysBytes(appliedIndex, leaseAppliedIndex uint64) int64

CalcAppliedIndexSysBytes calculates the size (MVCCStats.SysBytes) of the {raft,lease} applied index keys/values.

func (StateLoader) Load Uses

func (rsl StateLoader) Load(
    ctx context.Context, reader engine.Reader, desc *roachpb.RangeDescriptor,
) (storagepb.ReplicaState, error)

Load a ReplicaState from disk. The exception is the Desc field, which is updated transactionally, and is populated from the supplied RangeDescriptor under the convention that that is the latest committed version.

func (StateLoader) LoadAppliedIndex Uses

func (rsl StateLoader) LoadAppliedIndex(
    ctx context.Context, reader engine.Reader,
) (raftAppliedIndex uint64, leaseAppliedIndex uint64, err error)

LoadAppliedIndex returns the Raft applied index and the lease applied index.

func (StateLoader) LoadGCThreshold Uses

func (rsl StateLoader) LoadGCThreshold(
    ctx context.Context, reader engine.Reader,
) (*hlc.Timestamp, error)

LoadGCThreshold loads the GC threshold.

func (StateLoader) LoadHardState Uses

func (rsl StateLoader) LoadHardState(
    ctx context.Context, reader engine.Reader,
) (raftpb.HardState, error)

LoadHardState loads the HardState.

func (StateLoader) LoadLastIndex Uses

func (rsl StateLoader) LoadLastIndex(ctx context.Context, reader engine.Reader) (uint64, error)

LoadLastIndex loads the last index.

func (StateLoader) LoadLease Uses

func (rsl StateLoader) LoadLease(ctx context.Context, reader engine.Reader) (roachpb.Lease, error)

LoadLease loads the lease.

func (StateLoader) LoadLegacyTxnSpanGCThreshold Uses

func (rsl StateLoader) LoadLegacyTxnSpanGCThreshold(
    ctx context.Context, reader engine.Reader,
) (*hlc.Timestamp, error)

LoadLegacyTxnSpanGCThreshold loads the legacy transaction GC threshold. This field is NOT populated in the ReplicaState value returned by StateLoader.Load. TODO(nvanbenschoten): Remove in 20.1.

func (StateLoader) LoadMVCCStats Uses

func (rsl StateLoader) LoadMVCCStats(
    ctx context.Context, reader engine.Reader,
) (enginepb.MVCCStats, error)

LoadMVCCStats loads the MVCC stats.

func (StateLoader) LoadRaftTruncatedState Uses

func (rsl StateLoader) LoadRaftTruncatedState(
    ctx context.Context, reader engine.Reader,
) (_ roachpb.RaftTruncatedState, isLegacy bool, _ error)

LoadRaftTruncatedState loads the truncated state. The returned boolean returns whether the result was read from the TruncatedStateLegacyKey. If both keys are missing, it is false which is used to migrate into the unreplicated key.

See VersionUnreplicatedRaftTruncatedState.

func (StateLoader) LoadRangeAppliedState Uses

func (rsl StateLoader) LoadRangeAppliedState(
    ctx context.Context, reader engine.Reader,
) (*enginepb.RangeAppliedState, error)

LoadRangeAppliedState loads the Range applied state. The returned pointer will be nil if the applied state key is not found.

func (StateLoader) MigrateToRangeAppliedStateKey Uses

func (rsl StateLoader) MigrateToRangeAppliedStateKey(
    ctx context.Context, eng engine.ReadWriter, ms *enginepb.MVCCStats,
) error

MigrateToRangeAppliedStateKey deletes the keys that were replaced by the RangeAppliedState key.

func (StateLoader) Save Uses

func (rsl StateLoader) Save(
    ctx context.Context,
    eng engine.ReadWriter,
    state storagepb.ReplicaState,
    truncStateType TruncatedStateType,
) (enginepb.MVCCStats, error)

Save persists the given ReplicaState to disk. It assumes that the contained Stats are up-to-date and returns the stats which result from writing the updated State.

As an exception to the rule, the Desc field (whose on-disk state is special in that it's a full MVCC value and updated transactionally) is only used for its RangeID.

TODO(tschottdorf): test and assert that none of the optional values are missing whenever save is called. Optional values should be reserved strictly for use in Result. Do before merge.

func (StateLoader) SetGCThreshold Uses

func (rsl StateLoader) SetGCThreshold(
    ctx context.Context, eng engine.ReadWriter, ms *enginepb.MVCCStats, threshold *hlc.Timestamp,
) error

SetGCThreshold sets the GC threshold.

func (StateLoader) SetHardState Uses

func (rsl StateLoader) SetHardState(
    ctx context.Context, batch engine.Writer, hs raftpb.HardState,
) error

SetHardState overwrites the HardState.

func (StateLoader) SetLease Uses

func (rsl StateLoader) SetLease(
    ctx context.Context, eng engine.ReadWriter, ms *enginepb.MVCCStats, lease roachpb.Lease,
) error

SetLease persists a lease.

func (StateLoader) SetLegacyAppliedIndex Uses

func (rsl StateLoader) SetLegacyAppliedIndex(
    ctx context.Context,
    eng engine.ReadWriter,
    ms *enginepb.MVCCStats,
    appliedIndex, leaseAppliedIndex uint64,
) error

SetLegacyAppliedIndex sets the legacy {raft,lease} applied index values, properly accounting for existing keys in the returned stats.

The range applied state key cannot already exist or an assetion will be triggered. See comment on SetRangeAppliedState for why this is "legacy".

func (StateLoader) SetLegacyAppliedIndexBlind Uses

func (rsl StateLoader) SetLegacyAppliedIndexBlind(
    ctx context.Context,
    eng engine.ReadWriter,
    ms *enginepb.MVCCStats,
    appliedIndex, leaseAppliedIndex uint64,
) error

SetLegacyAppliedIndexBlind sets the legacy {raft,lease} applied index values using a "blind" put which ignores any existing keys. This is identical to SetLegacyAppliedIndex but is used to optimize the writing of the applied index values during write operations where we definitively know the size of the previous values.

The range applied state key cannot already exist or an assetion will be triggered. See comment on SetRangeAppliedState for why this is "legacy".

func (StateLoader) SetLegacyMVCCStats Uses

func (rsl StateLoader) SetLegacyMVCCStats(
    ctx context.Context, eng engine.ReadWriter, newMS *enginepb.MVCCStats,
) error

SetLegacyMVCCStats overwrites the legacy MVCC stats key.

The range applied state key cannot already exist or an assetion will be triggered. See comment on SetRangeAppliedState for why this is "legacy".

func (StateLoader) SetLegacyRaftTruncatedState Uses

func (rsl StateLoader) SetLegacyRaftTruncatedState(
    ctx context.Context,
    eng engine.ReadWriter,
    ms *enginepb.MVCCStats,
    truncState *roachpb.RaftTruncatedState,
) error

SetLegacyRaftTruncatedState overwrites the truncated state.

func (StateLoader) SetMVCCStats Uses

func (rsl StateLoader) SetMVCCStats(
    ctx context.Context, eng engine.ReadWriter, newMS *enginepb.MVCCStats,
) error

SetMVCCStats overwrites the MVCC stats. This needs to perform a read on the RangeAppliedState key before overwriting the stats. Use SetRangeAppliedState when performance is important.

func (StateLoader) SetRaftTruncatedState Uses

func (rsl StateLoader) SetRaftTruncatedState(
    ctx context.Context, eng engine.Writer, truncState *roachpb.RaftTruncatedState,
) error

SetRaftTruncatedState overwrites the truncated state.

func (StateLoader) SetRangeAppliedState Uses

func (rsl StateLoader) SetRangeAppliedState(
    ctx context.Context,
    eng engine.ReadWriter,
    appliedIndex, leaseAppliedIndex uint64,
    newMS *enginepb.MVCCStats,
) error

SetRangeAppliedState overwrites the range applied state. This state is a combination of the Raft and lease applied indices, along with the MVCC stats.

The applied indices and the stats used to be stored separately in different keys. We now deem those keys to be "legacy" because they have been replaced by the range applied state key.

func (StateLoader) SynthesizeHardState Uses

func (rsl StateLoader) SynthesizeHardState(
    ctx context.Context,
    eng engine.ReadWriter,
    oldHS raftpb.HardState,
    truncState roachpb.RaftTruncatedState,
    raftAppliedIndex uint64,
) error

SynthesizeHardState synthesizes an on-disk HardState from the given input, taking care that a HardState compatible with the existing data is written.

func (StateLoader) SynthesizeRaftState Uses

func (rsl StateLoader) SynthesizeRaftState(ctx context.Context, eng engine.ReadWriter) error

SynthesizeRaftState creates a Raft state which synthesizes both a HardState and a lastIndex from pre-seeded data in the engine (typically created via writeInitialReplicaState and, on a split, perhaps the activity of an uninitialized Raft group)

type TruncatedStateType Uses

type TruncatedStateType int

TruncatedStateType determines whether to use a replicated (legacy) or an unreplicated TruncatedState. See VersionUnreplicatedRaftTruncatedStateKey.

const (
    // TruncatedStateLegacyReplicated means use the legacy (replicated) key.
    TruncatedStateLegacyReplicated TruncatedStateType = iota
    // TruncatedStateUnreplicated means use the new (unreplicated) key.
    TruncatedStateUnreplicated
)

Package stateloader imports 13 packages (graph) and is imported by 12 packages. Updated 2019-11-18. Refresh now. Tools for package owners.