storage

package
v0.0.0-...-ad86efc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2016 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Overview

Package storage is a generated protocol buffer package.

It is generated from these files:
	cockroach/storage/api.proto
	cockroach/storage/raft.proto

It has these top-level messages:
	StoreRequestHeader
	PollFrozenRequest
	PollFrozenResponse
	ReservationRequest
	ReservationResponse
	CollectChecksumRequest
	CollectChecksumResponse
	RaftMessageRequest
	RaftMessageResponseUnion
	RaftMessageResponse
	ConfChangeContext

Package storage provides access to the Store and Range abstractions. Each Cockroach node handles one or more stores, each of which multiplexes to one or more ranges, identified by [start, end) keys. Ranges are contiguous regions of the keyspace. Each range implements an instance of the Raft consensus algorithm to synchronize participating range replicas.

Each store is represented by a single engine.Engine instance. The ranges hosted by a store all have access to the same engine, but write to only a range-limited keyspace within it. Ranges access the underlying engine via the MVCC interface, which provides historical versioned values.

Example (Rebalancing)
stopper := stop.NewStopper()
defer stopper.Stop()

// Model a set of stores in a cluster,
// randomly adding / removing stores and adding bytes.
rpcContext := rpc.NewContext(context.TODO(), &base.Context{Insecure: true}, nil, stopper)
server := rpc.NewServer(rpcContext) // never started
g := gossip.New(context.Background(), rpcContext, server, nil, stopper, metric.NewRegistry())
// Have to call g.SetNodeID before call g.AddInfo
g.SetNodeID(roachpb.NodeID(1))
sp := NewStorePool(
	g,
	hlc.NewClock(hlc.UnixNano),
	nil,
	/* reservationsEnabled */ true,
	TestTimeUntilStoreDeadOff,
	stopper,
)
alloc := MakeAllocator(sp, AllocatorOptions{AllowRebalance: true, Deterministic: true})

var wg sync.WaitGroup
g.RegisterCallback(gossip.MakePrefixPattern(gossip.KeyStorePrefix), func(_ string, _ roachpb.Value) { wg.Done() })

const generations = 100
const nodes = 20

// Initialize testStores.
var testStores [nodes]testStore
for i := 0; i < len(testStores); i++ {
	testStores[i].StoreID = roachpb.StoreID(i)
	testStores[i].Node = roachpb.NodeDescriptor{NodeID: roachpb.NodeID(i)}
	testStores[i].Capacity = roachpb.StoreCapacity{Capacity: 1 << 30, Available: 1 << 30}
}
// Initialize the cluster with a single range.
testStores[0].add(alloc.randGen.Int63n(1 << 20))

for i := 0; i < generations; i++ {
	// First loop through test stores and add data.
	wg.Add(len(testStores))
	for j := 0; j < len(testStores); j++ {
		// Add a pretend range to the testStore if there's already one.
		if testStores[j].Capacity.RangeCount > 0 {
			testStores[j].add(alloc.randGen.Int63n(1 << 20))
		}
		if err := g.AddInfoProto(gossip.MakeStoreKey(roachpb.StoreID(j)), &testStores[j].StoreDescriptor, 0); err != nil {
			panic(err)
		}
	}
	wg.Wait()

	// Next loop through test stores and maybe rebalance.
	for j := 0; j < len(testStores); j++ {
		ts := &testStores[j]
		target := alloc.RebalanceTarget(
			config.Constraints{},
			[]roachpb.ReplicaDescriptor{{NodeID: ts.Node.NodeID, StoreID: ts.StoreID}},
			-1)
		if target != nil {
			testStores[j].rebalance(&testStores[int(target.StoreID)], alloc.randGen.Int63n(1<<20))
		}
	}

	// Output store capacities as hexadecimal 2-character values.
	if i%(generations/50) == 0 {
		var maxBytes int64
		for j := 0; j < len(testStores); j++ {
			bytes := testStores[j].Capacity.Capacity - testStores[j].Capacity.Available
			if bytes > maxBytes {
				maxBytes = bytes
			}
		}
		if maxBytes > 0 {
			for j := 0; j < len(testStores); j++ {
				endStr := " "
				if j == len(testStores)-1 {
					endStr = ""
				}
				bytes := testStores[j].Capacity.Capacity - testStores[j].Capacity.Available
				fmt.Printf("%03d%s", (999*bytes)/maxBytes, endStr)
			}
			fmt.Printf("\n")
		}
	}
}

var totBytes int64
var totRanges int32
for i := 0; i < len(testStores); i++ {
	totBytes += testStores[i].Capacity.Capacity - testStores[i].Capacity.Available
	totRanges += testStores[i].Capacity.RangeCount
}
fmt.Printf("Total bytes=%d, ranges=%d\n", totBytes, totRanges)
Output:

999 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
999 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
999 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
999 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
999 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
999 000 000 000 014 000 000 118 000 000 000 000 111 000 000 000 000 000 000 000
999 113 095 000 073 064 000 221 003 000 020 178 182 000 057 000 027 000 055 000
999 398 222 000 299 366 000 525 239 135 263 385 424 261 261 000 260 194 207 322
999 423 307 294 401 286 292 648 294 426 388 454 511 445 162 521 179 403 280 581
999 396 446 333 445 481 408 602 351 418 492 578 603 526 193 553 279 444 385 568
999 511 598 392 572 526 515 741 441 500 641 672 802 541 310 698 421 447 466 577
999 611 726 528 721 640 564 804 524 568 721 743 811 558 433 706 541 588 500 678
999 668 764 582 716 696 604 832 594 572 695 690 828 607 497 728 595 682 609 689
999 635 729 536 706 736 596 764 614 561 674 659 831 595 492 740 564 732 592 683
999 726 848 539 794 806 676 750 669 637 675 711 930 684 558 750 654 748 658 764
999 664 847 560 811 757 658 748 674 628 694 660 896 647 561 729 704 754 652 775
999 693 901 587 826 799 671 756 655 649 702 727 923 645 600 712 767 816 738 800
999 712 964 600 820 768 705 762 630 698 708 774 929 636 583 725 835 866 734 819
999 734 996 666 816 765 735 809 612 728 687 800 942 625 562 730 816 922 758 834
999 750 956 647 834 771 761 776 616 759 696 799 952 622 576 732 808 963 732 839
999 780 980 699 792 779 736 827 668 762 672 778 986 608 578 732 849 943 727 861
999 749 929 686 770 754 726 803 671 723 723 774 996 628 592 728 862 945 734 903
999 736 886 669 770 716 714 794 654 710 694 725 985 599 621 732 849 924 692 873
999 740 900 699 801 752 747 815 679 717 715 770 962 612 639 773 882 923 717 882
999 810 923 735 815 776 772 823 703 775 750 818 963 637 667 814 891 949 746 933
999 791 882 723 827 760 774 795 671 756 761 777 941 636 654 809 858 932 714 896
999 804 893 726 836 764 752 806 663 747 778 780 958 622 652 812 861 928 724 908
999 819 898 760 875 804 777 809 669 768 809 799 959 617 682 825 879 939 748 910
999 827 882 740 878 834 779 841 702 784 816 828 950 631 689 810 853 915 757 938
999 835 885 759 882 837 762 835 738 791 832 823 953 648 705 816 872 932 763 958
999 838 878 756 880 843 802 850 749 807 838 813 975 683 735 838 888 944 780 967
999 837 883 759 900 826 814 844 752 795 821 792 944 686 750 832 881 925 754 969
999 880 905 784 920 854 834 883 765 837 835 794 958 726 799 854 885 971 776 971
999 897 906 792 926 849 832 894 785 869 852 799 969 735 805 864 909 949 799 975
999 874 888 781 905 844 833 894 787 867 836 792 962 720 806 856 918 943 783 943
999 891 871 756 907 823 836 896 800 844 843 799 934 725 818 836 925 956 758 943
999 901 888 782 893 842 838 894 806 858 838 801 934 742 821 839 947 938 761 931
999 930 909 811 905 872 846 912 812 887 877 816 965 766 844 864 975 953 782 960
999 917 895 810 903 860 862 927 800 886 881 831 954 753 840 869 983 940 774 948
999 920 910 828 894 853 873 911 801 908 893 821 966 757 850 867 987 944 790 951
994 927 918 835 915 876 888 910 808 907 909 843 966 762 844 884 999 941 799 936
999 930 919 848 910 869 901 921 808 897 888 840 967 780 857 888 980 935 793 917
999 917 918 835 903 870 910 913 800 897 873 830 960 765 866 877 971 937 793 915
999 909 904 831 874 875 883 896 791 896 863 833 926 758 841 879 959 932 772 904
999 940 902 849 882 888 899 920 812 918 859 844 953 776 857 896 981 963 775 901
999 926 887 849 869 876 886 898 813 894 834 823 947 762 839 884 979 955 785 890
999 924 881 855 866 867 870 905 820 888 819 805 948 758 836 877 967 938 782 897
999 929 896 863 895 873 874 917 823 913 831 818 964 783 848 882 974 952 791 892
999 941 908 860 888 869 894 921 835 917 826 830 953 785 872 894 970 963 810 901
999 917 895 848 871 856 896 913 831 910 828 832 951 787 875 873 952 947 800 891
Total bytes=915403982, ranges=1748

Index

Examples

Constants

View Source
const (

	// RaftLogQueueTimerDuration is the duration between truncations. This needs
	// to be relatively short so that truncations can keep up with raft log entry
	// creation.
	RaftLogQueueTimerDuration = 50 * time.Millisecond
	// RaftLogQueueStaleThreshold is the minimum threshold for stale raft log
	// entries. A stale entry is one which all replicas of the range have
	// progressed past and thus is no longer needed and can be truncated.
	RaftLogQueueStaleThreshold = 100
)
View Source
const (

	// ReplicaGCQueueInactivityThreshold is the inactivity duration after which
	// a range will be considered for garbage collection. Exported for testing.
	ReplicaGCQueueInactivityThreshold = 10 * 24 * time.Hour // 10 days
	// ReplicaGCQueueCandidateTimeout is the duration after which a range in
	// candidate Raft state (which is a typical sign of having been removed
	// from the group) will be considered for garbage collection.
	ReplicaGCQueueCandidateTimeout = 1 * time.Second
)
View Source
const (
	// TestTimeUntilStoreDead is the test value for TimeUntilStoreDead to
	// quickly mark stores as dead.
	TestTimeUntilStoreDead = 5 * time.Millisecond

	// TestTimeUntilStoreDeadOff is the test value for TimeUntilStoreDead that
	// prevents the store pool from marking stores as dead.
	TestTimeUntilStoreDeadOff = 24 * time.Hour
)
View Source
const ErrMsgConflictUpdatingRangeDesc = "conflict updating range descriptors"

ErrMsgConflictUpdatingRangeDesc is an error message that is returned by AdminSplit when it conflicts with some other process that updates range descriptors.

View Source
const (
	// MinTSCacheWindow specifies the minimum duration to hold entries in
	// the cache before allowing eviction. After this window expires,
	// transactions writing to this node with timestamps lagging by more
	// than minCacheWindow will necessarily have to advance their commit
	// timestamp.
	MinTSCacheWindow = 10 * time.Second
)

Variables

View Source
var (
	ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowApi   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRaft   = fmt.Errorf("proto: integer overflow")
)
View Source
var RebalanceThreshold = envutil.EnvOrDefaultFloat("COCKROACH_REBALANCE_THRESHOLD", 0.05)

RebalanceThreshold is the minimum ratio of a store's range surplus to the mean range count that permits rebalances away from that store.

Functions

func ComputeStatsForRange

func ComputeStatsForRange(
	d *roachpb.RangeDescriptor, e engine.Reader, nowNanos int64,
) (enginepb.MVCCStats, error)

ComputeStatsForRange computes the stats for a given range by iterating over all key ranges for the given range that should be accounted for in its stats.

func DecodeRaftCommand

func DecodeRaftCommand(data []byte) (commandID string, command []byte)

DecodeRaftCommand splits a raftpb.Entry.Data into its commandID and command portions. The caller is responsible for checking that the data is not empty (which indicates a dummy entry generated by raft rather than a real command). Usage is mostly internal to the storage package but is exported for use by debugging tools.

func IterateRangeDescriptors

func IterateRangeDescriptors(ctx context.Context,
	eng engine.Reader, fn func(desc roachpb.RangeDescriptor) (bool, error),
) error

IterateRangeDescriptors calls the provided function with each descriptor from the provided Engine. The return values of this method and fn have semantics similar to engine.MVCCIterate.

func NewReplicaCorruptionError

func NewReplicaCorruptionError(err error) *roachpb.ReplicaCorruptionError

NewReplicaCorruptionError creates a new error indicating a corrupt replica, with the supplied list of errors given as history.

func RegisterConsistencyServer

func RegisterConsistencyServer(s *grpc.Server, srv ConsistencyServer)

func RegisterMultiRaftServer

func RegisterMultiRaftServer(s *grpc.Server, srv MultiRaftServer)

func RegisterStoresServer

func RegisterStoresServer(s *grpc.Server, srv StoresServer)

func TrackRaftProtos

func TrackRaftProtos() func() []reflect.Type

TrackRaftProtos instruments proto marshalling to track protos which are marshalled downstream of raft. It returns a function that removes the instrumentation and returns the list of downstream-of-raft protos.

Types

type AbortCache

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

The AbortCache sets markers for aborted transactions to provide protection against an aborted but active transaction not reading values it wrote (due to its intents having been removed).

The AbortCache stores responses in the underlying engine, using keys derived from Range ID and txn ID.

A AbortCache is not thread safe. Access to it is serialized through Raft.

TODO(tschottdorf): we seem to have made a half-hearted attempt at naming this the "AbortSpan" instead, but large parts of the code still call this "AbortCache". We should settle for one and rename everything post-yellow.

func NewAbortCache

func NewAbortCache(rangeID roachpb.RangeID) *AbortCache

NewAbortCache returns a new abort cache. Every range replica maintains an abort cache, not just the lease holder.

func (*AbortCache) ClearData

func (sc *AbortCache) ClearData(e engine.Engine) error

ClearData removes all persisted items stored in the cache.

func (*AbortCache) CopyFrom

func (sc *AbortCache) CopyFrom(
	ctx context.Context,
	e engine.ReadWriter,
	ms *enginepb.MVCCStats,
	originRangeID roachpb.RangeID,
) (int, error)

CopyFrom copies all the persisted results from the originRangeID abort cache into this one. Note that the cache will not be locked while copying is in progress. Failures decoding individual entries return an error. The copy is done directly using the engine instead of interpreting values through MVCC for efficiency. On success, returns the number of entries (key-value pairs) copied.

func (*AbortCache) CopyInto

func (sc *AbortCache) CopyInto(
	e engine.ReadWriter,
	ms *enginepb.MVCCStats,
	destRangeID roachpb.RangeID,
) (int, error)

CopyInto copies all the results from this abort cache into the destRangeID abort cache. Failures decoding individual cache entries return an error. On success, returns the number of entries (key-value pairs) copied.

func (*AbortCache) Del

func (sc *AbortCache) Del(
	ctx context.Context,
	e engine.ReadWriter,
	ms *enginepb.MVCCStats,
	txnID *uuid.UUID,
) error

Del removes all abort cache entries for the given transaction.

func (*AbortCache) Get

func (sc *AbortCache) Get(
	ctx context.Context,
	e engine.Reader,
	txnID *uuid.UUID,
	entry *roachpb.AbortCacheEntry,
) (bool, error)

Get looks up an abort cache entry recorded for this transaction ID. Returns whether an abort record was found and any error.

func (*AbortCache) Iterate

func (sc *AbortCache) Iterate(
	ctx context.Context,
	e engine.Reader,
	f func([]byte, *uuid.UUID, roachpb.AbortCacheEntry),
)

Iterate walks through the abort cache, invoking the given callback for each unmarshaled entry with the key, the transaction ID and the decoded entry. TODO(tschottdorf): should not use a pointer to UUID.

func (*AbortCache) Put

Put writes an entry for the specified transaction ID.

type Allocator

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

Allocator tries to spread replicas as evenly as possible across the stores in the cluster.

func MakeAllocator

func MakeAllocator(storePool *StorePool, options AllocatorOptions) Allocator

MakeAllocator creates a new allocator using the specified StorePool.

func (*Allocator) AllocateTarget

func (a *Allocator) AllocateTarget(
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	relaxConstraints bool,
) (*roachpb.StoreDescriptor, error)

AllocateTarget returns a suitable store for a new allocation with the required attributes. Nodes already accommodating existing replicas are ruled out as targets. If relaxConstraints is true, then the required attributes will be relaxed as necessary, from least specific to most specific, in order to allocate a target.

func (*Allocator) ComputeAction

func (a *Allocator) ComputeAction(zone config.ZoneConfig, desc *roachpb.RangeDescriptor) (
	AllocatorAction, float64)

ComputeAction determines the exact operation needed to repair the supplied range, as governed by the supplied zone configuration. It returns the required action that should be taken and a replica on which the action should be performed.

func (Allocator) RebalanceTarget

func (a Allocator) RebalanceTarget(
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	leaseStoreID roachpb.StoreID,
) *roachpb.StoreDescriptor

RebalanceTarget returns a suitable store for a rebalance target with required attributes. Rebalance targets are selected via the same mechanism as AllocateTarget(), except the chosen target must follow some additional criteria. Namely, if chosen, it must further the goal of balancing the cluster.

The supplied parameters are the required attributes for the range, a list of the existing replicas of the range and the store ID of the lease-holder replica. The existing replicas modulo the lease-holder replica are candidates for rebalancing. Note that rebalancing is accomplished by first adding a new replica to the range, then removing the most undesirable replica.

Simply ignoring a rebalance opportunity in the event that the target chosen by AllocateTarget() doesn't fit balancing criteria is perfectly fine, as other stores in the cluster will also be doing their probabilistic best to rebalance. This helps prevent a stampeding herd targeting an abnormally under-utilized store.

func (Allocator) RemoveTarget

func (a Allocator) RemoveTarget(existing []roachpb.ReplicaDescriptor, leaseStoreID roachpb.StoreID) (roachpb.ReplicaDescriptor, error)

RemoveTarget returns a suitable replica to remove from the provided replica set. It attempts to consider which of the provided replicas would be the best candidate for removal. It also will exclude any replica that belongs to the range lease holder's store ID.

TODO(mrtracy): removeTarget eventually needs to accept the attributes from the zone config associated with the provided replicas. This will allow it to make correct decisions in the case of ranges with heterogeneous replica requirements (i.e. multiple data centers).

type AllocatorAction

type AllocatorAction int

AllocatorAction enumerates the various replication adjustments that may be recommended by the allocator.

const (
	AllocatorNoop AllocatorAction
	AllocatorRemove
	AllocatorAdd
	AllocatorRemoveDead
)

These are the possible allocator actions.

type AllocatorOptions

type AllocatorOptions struct {
	// AllowRebalance allows this store to attempt to rebalance its own
	// replicas to other stores.
	AllowRebalance bool

	// Deterministic makes allocation decisions deterministic, based on
	// current cluster statistics. If this flag is not set, allocation operations
	// will have random behavior. This flag is intended to be set for testing
	// purposes only.
	Deterministic bool
}

AllocatorOptions are configurable options which effect the way that the replicate queue will handle rebalancing opportunities.

type CollectChecksumRequest

type CollectChecksumRequest struct {
	StoreRequestHeader `protobuf:"bytes,1,opt,name=header,embedded=header" json:"header"`
	RangeID            github_com_cockroachdb_cockroach_roachpb.RangeID `` /* 141-byte string literal not displayed */
	// checksum_id identifies the corresponding roachpb.ComputeChecksumRequest.
	ChecksumID github_com_cockroachdb_cockroach_util_uuid.UUID `` /* 140-byte string literal not displayed */
	Checksum   []byte                                          `protobuf:"bytes,4,opt,name=checksum,proto3" json:"checksum,omitempty"`
}

A CollectChecksumRequest asks the addressed replica for the result of a roachpb.ComputeChecksumRequest.

func (*CollectChecksumRequest) Descriptor

func (*CollectChecksumRequest) Descriptor() ([]byte, []int)

func (*CollectChecksumRequest) Marshal

func (m *CollectChecksumRequest) Marshal() (data []byte, err error)

func (*CollectChecksumRequest) MarshalTo

func (m *CollectChecksumRequest) MarshalTo(data []byte) (int, error)

func (*CollectChecksumRequest) ProtoMessage

func (*CollectChecksumRequest) ProtoMessage()

func (*CollectChecksumRequest) Reset

func (m *CollectChecksumRequest) Reset()

func (*CollectChecksumRequest) Size

func (m *CollectChecksumRequest) Size() (n int)

func (*CollectChecksumRequest) String

func (m *CollectChecksumRequest) String() string

func (*CollectChecksumRequest) Unmarshal

func (m *CollectChecksumRequest) Unmarshal(data []byte) error

type CollectChecksumResponse

type CollectChecksumResponse struct {
	Checksum []byte `protobuf:"bytes,1,opt,name=checksum,proto3" json:"checksum,omitempty"`
	// snapshot is set if the roachpb.ComputeChecksumRequest had snapshot = true
	// and the response checksum is different from the request checksum.
	Snapshot *cockroach_roachpb1.RaftSnapshotData `protobuf:"bytes,2,opt,name=snapshot" json:"snapshot,omitempty"`
}

func (*CollectChecksumResponse) Descriptor

func (*CollectChecksumResponse) Descriptor() ([]byte, []int)

func (*CollectChecksumResponse) Marshal

func (m *CollectChecksumResponse) Marshal() (data []byte, err error)

func (*CollectChecksumResponse) MarshalTo

func (m *CollectChecksumResponse) MarshalTo(data []byte) (int, error)

func (*CollectChecksumResponse) ProtoMessage

func (*CollectChecksumResponse) ProtoMessage()

func (*CollectChecksumResponse) Reset

func (m *CollectChecksumResponse) Reset()

func (*CollectChecksumResponse) Size

func (m *CollectChecksumResponse) Size() (n int)

func (*CollectChecksumResponse) String

func (m *CollectChecksumResponse) String() string

func (*CollectChecksumResponse) Unmarshal

func (m *CollectChecksumResponse) Unmarshal(data []byte) error

type CommandQueue

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

A CommandQueue maintains an interval tree of keys or key ranges for executing commands. New commands affecting keys or key ranges must wait on already-executing commands which overlap their key range.

Before executing, a command invokes GetWait() to acquire a slice of channels belonging to overlapping commands which are already running. Each channel is waited on by the caller for confirmation that all overlapping, pending commands have completed and the pending command can proceed.

After waiting, a command is added to the queue's already-executing set via add(). add accepts a parameter indicating whether the command is read-only. Read-only commands don't need to wait on other read-only commands, so the channels returned via GetWait() don't include read-only on read-only overlapping commands as an optimization.

Once commands complete, remove() is invoked to remove the executing command and close its channel, possibly signaling waiting commands who were gated by the executing command's affected key(s).

CommandQueue is not thread safe.

func NewCommandQueue

func NewCommandQueue() *CommandQueue

NewCommandQueue returns a new command queue.

type ConfChangeContext

type ConfChangeContext struct {
	CommandID string `protobuf:"bytes,1,opt,name=command_id,json=commandId" json:"command_id"`
	// Payload is the application-level command (i.e. an encoded
	// roachpb.EndTransactionRequest).
	Payload []byte `protobuf:"bytes,2,opt,name=payload" json:"payload,omitempty"`
	// Replica contains full details about the replica being added or removed.
	Replica cockroach_roachpb.ReplicaDescriptor `protobuf:"bytes,3,opt,name=replica" json:"replica"`
}

ConfChangeContext is encoded in the raftpb.ConfChange.Context field.

func (*ConfChangeContext) Descriptor

func (*ConfChangeContext) Descriptor() ([]byte, []int)

func (*ConfChangeContext) Marshal

func (m *ConfChangeContext) Marshal() (data []byte, err error)

func (*ConfChangeContext) MarshalTo

func (m *ConfChangeContext) MarshalTo(data []byte) (int, error)

func (*ConfChangeContext) ProtoMessage

func (*ConfChangeContext) ProtoMessage()

func (*ConfChangeContext) Reset

func (m *ConfChangeContext) Reset()

func (*ConfChangeContext) Size

func (m *ConfChangeContext) Size() (n int)

func (*ConfChangeContext) String

func (m *ConfChangeContext) String() string

func (*ConfChangeContext) Unmarshal

func (m *ConfChangeContext) Unmarshal(data []byte) error

type ConsistencyClient

type ConsistencyClient interface {
	CollectChecksum(ctx context.Context, in *CollectChecksumRequest, opts ...grpc.CallOption) (*CollectChecksumResponse, error)
}

func NewConsistencyClient

func NewConsistencyClient(cc *grpc.ClientConn) ConsistencyClient

type ConsistencyServer

type ConsistencyServer interface {
	CollectChecksum(context.Context, *CollectChecksumRequest) (*CollectChecksumResponse, error)
}

type GCInfo

type GCInfo struct {
	// Now is the timestamp used for age computations.
	Now hlc.Timestamp
	// Policy is the policy used for this garbage collection cycle.
	Policy config.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.
	GCKeys, 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, TransactionSpanGCPending int
	// TxnSpanGCThreshold is the cutoff for transaction span GC. Transactions
	// with a smaller LastActive() were considered for GC.
	TxnSpanGCThreshold hlc.Timestamp
	// AbortSpanTotal is the total number of transactions present in the abort cache.
	AbortSpanTotal int
	// AbortSpanConsidered is the number of abort cache 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 abort cache 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
	// ResolveErrors is the number of successful intent resolutions.
	ResolveSuccess int
	// Threshold is the computed expiration timestamp. Equal to `Now - Policy`.
	Threshold hlc.Timestamp
}

GCInfo contains statistics and insights from a GC run.

func RunGC

func RunGC(
	ctx context.Context,
	desc *roachpb.RangeDescriptor,
	snap engine.Reader,
	now hlc.Timestamp,
	policy config.GCPolicy,
	pushTxnFn pushFunc,
	resolveIntentsFn resolveFunc,
) ([]roachpb.GCRequest_GCKey, GCInfo, error)

RunGC runs garbage collection for the specified descriptor on the provided Engine (which is not mutated). It uses the provided functions pushTxnFn and resolveIntentsFn to clarify the true status of and clean up after encountered transactions. It returns a slice of gc'able keys from the data, transaction, and abort spans.

type KeyRange

type KeyRange interface {
	Desc() *roachpb.RangeDescriptor

	btree.Item
	fmt.Stringer
	// contains filtered or unexported methods
}

KeyRange is an interface type for the replicasByKey BTree, to compare Replica and ReplicaPlaceholder.

type MultiRaftClient

type MultiRaftClient interface {
	RaftMessage(ctx context.Context, opts ...grpc.CallOption) (MultiRaft_RaftMessageClient, error)
	RaftMessageSync(ctx context.Context, in *RaftMessageRequest, opts ...grpc.CallOption) (*RaftMessageResponse, error)
}

func NewMultiRaftClient

func NewMultiRaftClient(cc *grpc.ClientConn) MultiRaftClient

type MultiRaftServer

type MultiRaftServer interface {
	RaftMessage(MultiRaft_RaftMessageServer) error
	RaftMessageSync(context.Context, *RaftMessageRequest) (*RaftMessageResponse, error)
}

type MultiRaft_RaftMessageClient

type MultiRaft_RaftMessageClient interface {
	Send(*RaftMessageRequest) error
	Recv() (*RaftMessageResponse, error)
	grpc.ClientStream
}

type MultiRaft_RaftMessageServer

type MultiRaft_RaftMessageServer interface {
	Send(*RaftMessageResponse) error
	Recv() (*RaftMessageRequest, error)
	grpc.ServerStream
}

type NodeAddressResolver

type NodeAddressResolver func(roachpb.NodeID) (net.Addr, error)

NodeAddressResolver is the function used by RaftTransport to map node IDs to network addresses.

func GossipAddressResolver

func GossipAddressResolver(gossip *gossip.Gossip) NodeAddressResolver

GossipAddressResolver is a thin wrapper around gossip's GetNodeIDAddress that allows its return value to be used as the net.Addr interface.

type NotBootstrappedError

type NotBootstrappedError struct{}

A NotBootstrappedError indicates that an engine has not yet been bootstrapped due to a store identifier not being present.

func (*NotBootstrappedError) Error

func (e *NotBootstrappedError) Error() string

Error formats error.

type PollFrozenRequest

type PollFrozenRequest struct {
	StoreRequestHeader `protobuf:"bytes,1,opt,name=header,embedded=header" json:"header"`
	// When true, collect the frozen Replicas, and the thawed ones otherwise.
	CollectFrozen bool `protobuf:"varint,2,opt,name=collect_frozen,json=collectFrozen,proto3" json:"collect_frozen,omitempty"`
}

A PollFrozenRequest asks the addressed Store for its frozen or thawed Replicas.

func (*PollFrozenRequest) Descriptor

func (*PollFrozenRequest) Descriptor() ([]byte, []int)

func (*PollFrozenRequest) Marshal

func (m *PollFrozenRequest) Marshal() (data []byte, err error)

func (*PollFrozenRequest) MarshalTo

func (m *PollFrozenRequest) MarshalTo(data []byte) (int, error)

func (*PollFrozenRequest) ProtoMessage

func (*PollFrozenRequest) ProtoMessage()

func (*PollFrozenRequest) Reset

func (m *PollFrozenRequest) Reset()

func (*PollFrozenRequest) Size

func (m *PollFrozenRequest) Size() (n int)

func (*PollFrozenRequest) String

func (m *PollFrozenRequest) String() string

func (*PollFrozenRequest) Unmarshal

func (m *PollFrozenRequest) Unmarshal(data []byte) error

type PollFrozenResponse

type PollFrozenResponse struct {
	Results []cockroach_roachpb.ReplicaDescriptor `protobuf:"bytes,1,rep,name=results" json:"results"`
}

A PollFrozenResponse is the response returned from a PollFrozenRequest.

func (*PollFrozenResponse) Descriptor

func (*PollFrozenResponse) Descriptor() ([]byte, []int)

func (*PollFrozenResponse) Marshal

func (m *PollFrozenResponse) Marshal() (data []byte, err error)

func (*PollFrozenResponse) MarshalTo

func (m *PollFrozenResponse) MarshalTo(data []byte) (int, error)

func (*PollFrozenResponse) ProtoMessage

func (*PollFrozenResponse) ProtoMessage()

func (*PollFrozenResponse) Reset

func (m *PollFrozenResponse) Reset()

func (*PollFrozenResponse) Size

func (m *PollFrozenResponse) Size() (n int)

func (*PollFrozenResponse) String

func (m *PollFrozenResponse) String() string

func (*PollFrozenResponse) Unmarshal

func (m *PollFrozenResponse) Unmarshal(data []byte) error

type PostCommitTrigger

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

PostCommitTrigger is returned from Raft processing as a side effect which signals that further action should be taken as part of the processing of the Raft command. Depending on the content, actions may be executed on all Replicas, the lease holder, or a Replica determined by other conditions present in the specific trigger.

type RaftMessageHandler

type RaftMessageHandler interface {
	// HandleRaftRequest is called for each incoming Raft message. If it returns
	// an error it will be streamed back to the sender of the message as a
	// RaftMessageResponse. If the stream parameter is nil the request should be
	// processed synchronously. If the stream is non-nil the request can be
	// processed asynchronously and any error should be sent on the stream.
	HandleRaftRequest(ctx context.Context, req *RaftMessageRequest,
		respStream RaftMessageResponseStream) *roachpb.Error

	// HandleRaftResponse is called for each raft response. Note that
	// not all messages receive a response.
	HandleRaftResponse(context.Context, *RaftMessageResponse)
}

RaftMessageHandler is the interface that must be implemented by arguments to RaftTransport.Listen.

type RaftMessageRequest

type RaftMessageRequest struct {
	RangeID     github_com_cockroachdb_cockroach_roachpb.RangeID `protobuf:"varint,1,opt,name=range_id,json=rangeId,casttype=github.com/cockroachdb/cockroach/roachpb.RangeID" json:"range_id"`
	FromReplica cockroach_roachpb.ReplicaDescriptor              `protobuf:"bytes,2,opt,name=from_replica,json=fromReplica" json:"from_replica"`
	ToReplica   cockroach_roachpb.ReplicaDescriptor              `protobuf:"bytes,3,opt,name=to_replica,json=toReplica" json:"to_replica"`
	Message     raftpb.Message                                   `protobuf:"bytes,4,opt,name=message" json:"message"`
	// Is this a quiesce request? A quiesce request is a MsgHeartbeat
	// which is requesting the recipient to stop ticking its local
	// replica as long as the current Raft state matches the heartbeat
	// Term/Commit. If the Term/Commit match, the recipient is marked as
	// quiescent. If they don't match, the message is passed along to
	// Raft which will generate a MsgHeartbeatResp that will unquiesce
	// the sender.
	Quiesce bool `protobuf:"varint,5,opt,name=quiesce" json:"quiesce"`
}

RaftMessageRequest is the request used to send raft messages using our protobuf-based RPC codec.

func (*RaftMessageRequest) Descriptor

func (*RaftMessageRequest) Descriptor() ([]byte, []int)

func (*RaftMessageRequest) GetUser

func (*RaftMessageRequest) GetUser() string

GetUser implements security.RequestWithUser. Raft messages are always sent by the node user.

func (*RaftMessageRequest) Marshal

func (m *RaftMessageRequest) Marshal() (data []byte, err error)

func (*RaftMessageRequest) MarshalTo

func (m *RaftMessageRequest) MarshalTo(data []byte) (int, error)

func (*RaftMessageRequest) ProtoMessage

func (*RaftMessageRequest) ProtoMessage()

func (*RaftMessageRequest) Reset

func (m *RaftMessageRequest) Reset()

func (*RaftMessageRequest) Size

func (m *RaftMessageRequest) Size() (n int)

func (*RaftMessageRequest) String

func (m *RaftMessageRequest) String() string

func (*RaftMessageRequest) Unmarshal

func (m *RaftMessageRequest) Unmarshal(data []byte) error

type RaftMessageResponse

type RaftMessageResponse struct {
	RangeID     github_com_cockroachdb_cockroach_roachpb.RangeID `protobuf:"varint,1,opt,name=range_id,json=rangeId,casttype=github.com/cockroachdb/cockroach/roachpb.RangeID" json:"range_id"`
	FromReplica cockroach_roachpb.ReplicaDescriptor              `protobuf:"bytes,2,opt,name=from_replica,json=fromReplica" json:"from_replica"`
	ToReplica   cockroach_roachpb.ReplicaDescriptor              `protobuf:"bytes,3,opt,name=to_replica,json=toReplica" json:"to_replica"`
	Union       RaftMessageResponseUnion                         `protobuf:"bytes,4,opt,name=union" json:"union"`
}

RaftMessageResponse may be sent to the sender of a RaftMessageRequest. RaftMessage does not use the usual request/response pattern; it is primarily modeled as a one-way stream of requests. Normal 'responses' are usually sent as new requests on a separate stream in the other direction. RaftMessageResponse is not sent for every RaftMessageRequest, but may be used for certain error conditions.

func (*RaftMessageResponse) Descriptor

func (*RaftMessageResponse) Descriptor() ([]byte, []int)

func (*RaftMessageResponse) Marshal

func (m *RaftMessageResponse) Marshal() (data []byte, err error)

func (*RaftMessageResponse) MarshalTo

func (m *RaftMessageResponse) MarshalTo(data []byte) (int, error)

func (*RaftMessageResponse) ProtoMessage

func (*RaftMessageResponse) ProtoMessage()

func (*RaftMessageResponse) Reset

func (m *RaftMessageResponse) Reset()

func (*RaftMessageResponse) Size

func (m *RaftMessageResponse) Size() (n int)

func (*RaftMessageResponse) String

func (m *RaftMessageResponse) String() string

func (*RaftMessageResponse) Unmarshal

func (m *RaftMessageResponse) Unmarshal(data []byte) error

type RaftMessageResponseStream

type RaftMessageResponseStream interface {
	Context() context.Context
	Send(*RaftMessageResponse) error
}

RaftMessageResponseStream is a subset of the MultiRaft_RaftMessageServer interface that is needed for sending responses.

type RaftMessageResponseUnion

type RaftMessageResponseUnion struct {
	Error *cockroach_roachpb3.Error `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
}

func (*RaftMessageResponseUnion) Descriptor

func (*RaftMessageResponseUnion) Descriptor() ([]byte, []int)

func (*RaftMessageResponseUnion) GetValue

func (this *RaftMessageResponseUnion) GetValue() interface{}

func (*RaftMessageResponseUnion) Marshal

func (m *RaftMessageResponseUnion) Marshal() (data []byte, err error)

func (*RaftMessageResponseUnion) MarshalTo

func (m *RaftMessageResponseUnion) MarshalTo(data []byte) (int, error)

func (*RaftMessageResponseUnion) ProtoMessage

func (*RaftMessageResponseUnion) ProtoMessage()

func (*RaftMessageResponseUnion) Reset

func (m *RaftMessageResponseUnion) Reset()

func (*RaftMessageResponseUnion) SetValue

func (this *RaftMessageResponseUnion) SetValue(value interface{}) bool

func (*RaftMessageResponseUnion) Size

func (m *RaftMessageResponseUnion) Size() (n int)

func (*RaftMessageResponseUnion) String

func (m *RaftMessageResponseUnion) String() string

func (*RaftMessageResponseUnion) Unmarshal

func (m *RaftMessageResponseUnion) Unmarshal(data []byte) error

type RaftSnapshotStatus

type RaftSnapshotStatus struct {
	Req *RaftMessageRequest
	Err error
}

RaftSnapshotStatus contains a MsgSnap message and its resulting error, for asynchronous notification of completion.

type RaftTransport

type RaftTransport struct {
	SnapshotStatusChan chan RaftSnapshotStatus
	// contains filtered or unexported fields
}

RaftTransport handles the rpc messages for raft.

The raft transport is asynchronous with respect to the caller, and internally multiplexes outbound messages. Internally, each message is queued on a per-destination queue before being asynchronously delivered.

Callers are required to construct a RaftSender before being able to dispatch messages, and must provide an error handler which will be invoked asynchronously in the event that the recipient of any message closes its inbound RPC stream. This callback is asynchronous with respect to the outbound message which caused the remote to hang up; all that is known is which remote hung up.

func NewDummyRaftTransport

func NewDummyRaftTransport() *RaftTransport

NewDummyRaftTransport returns a dummy raft transport for use in tests which need a non-nil raft transport that need not function.

func NewRaftTransport

func NewRaftTransport(resolver NodeAddressResolver, grpcServer *grpc.Server, rpcContext *rpc.Context) *RaftTransport

NewRaftTransport creates a new RaftTransport with specified resolver and grpc server. Callers are responsible for monitoring RaftTransport.SnapshotStatusChan.

func (*RaftTransport) GetCircuitBreaker

func (t *RaftTransport) GetCircuitBreaker(nodeID roachpb.NodeID) *circuit.Breaker

GetCircuitBreaker returns the circuit breaker controlling connection attempts to the specified node.

func (*RaftTransport) Listen

func (t *RaftTransport) Listen(storeID roachpb.StoreID, handler RaftMessageHandler)

Listen registers a raftMessageHandler to receive proxied messages.

func (*RaftTransport) RaftMessage

func (t *RaftTransport) RaftMessage(stream MultiRaft_RaftMessageServer) (err error)

RaftMessage proxies the incoming requests to the listening server interface.

func (*RaftTransport) RaftMessageSync

func (t *RaftTransport) RaftMessageSync(ctx context.Context, req *RaftMessageRequest,
) (*RaftMessageResponse, error)

RaftMessageSync proxies the incoming request to the listening server interface.

func (*RaftTransport) SendAsync

func (t *RaftTransport) SendAsync(req *RaftMessageRequest) bool

SendAsync sends a message to the recipient specified in the request. It returns false if the outgoing queue is full and calls s.onError when the recipient closes the stream.

func (*RaftTransport) SendSync

func (t *RaftTransport) SendSync(ctx context.Context, req *RaftMessageRequest) error

SendSync sends a raft message and waits for an acknowledgement.

func (*RaftTransport) Stop

func (t *RaftTransport) Stop(storeID roachpb.StoreID)

Stop unregisters a raftMessageHandler.

type RangeEventLogType

type RangeEventLogType string

RangeEventLogType describes a specific event type recorded in the range log table.

const (
	// RangeEventLogSplit is the event type recorded when a range splits.
	RangeEventLogSplit RangeEventLogType = "split"
	// RangeEventLogAdd is the event type recorded when a range adds a
	// new replica.
	RangeEventLogAdd RangeEventLogType = "add"
	// RangeEventLogRemove is the event type recorded when a range removes a
	// replica.
	RangeEventLogRemove RangeEventLogType = "remove"
)

type Replica

type Replica struct {

	// TODO(tschottdorf): Duplicates r.mu.state.desc.RangeID; revisit that.
	RangeID roachpb.RangeID // Should only be set by the constructor.
	// contains filtered or unexported fields
}

A Replica is a contiguous keyspace with writes managed via an instance of the Raft consensus algorithm. Many ranges may exist in a store and they are unlikely to be contiguous. Ranges are independent units and are responsible for maintaining their own integrity by replacing failed replicas, splitting and merging as appropriate.

func NewReplica

func NewReplica(
	desc *roachpb.RangeDescriptor, store *Store, replicaID roachpb.ReplicaID,
) (*Replica, error)

NewReplica initializes the replica using the given metadata. If the replica is initialized (i.e. desc contains more than a RangeID), replicaID should be 0 and the replicaID will be discovered from the descriptor.

func (*Replica) AdminMerge

AdminMerge extends this range to subsume the range that comes next in the key space. The merge is performed inside of a distributed transaction which writes the left hand side range descriptor (the subsuming range) and deletes the range descriptor for the right hand side range (the subsumed range). It also updates the range addressing metadata. The handover of responsibility for the reassigned key range is carried out seamlessly through a merge trigger carried out as part of the commit of that transaction. A merge requires that the two ranges are collocated on the same set of replicas.

The supplied RangeDescriptor is used as a form of optimistic lock. See the comment of "AdminSplit" for more information on this pattern.

func (*Replica) AdminSplit

AdminSplit divides the range into into two ranges, using either args.SplitKey (if provided) or an internally computed key that aims to roughly equipartition the range by size. The split is done inside of a distributed txn which writes updated left and new right hand side range descriptors, and updates the range addressing metadata. The handover of responsibility for the reassigned key range is carried out seamlessly through a split trigger carried out as part of the commit of that transaction.

The supplied RangeDescriptor is used as a form of optimistic lock. An operation which might split a range should obtain a copy of the range's current descriptor before making the decision to split. If the decision is affirmative the descriptor is passed to AdminSplit, which performs a Conditional Put on the RangeDescriptor to ensure that no other operation has modified the range in the time the decision was being made. TODO(tschottdorf): should assert that split key is not a local key.

See the comment on splitTrigger for details on the complexities.

func (*Replica) AdminTransferLease

func (r *Replica) AdminTransferLease(target roachpb.StoreID) error

AdminTransferLease transfers the LeaderLease to another replica. Only the current holder of the LeaderLease can do a transfer, because it needs to stop serving reads and proposing Raft commands (CPut is a read) after sending the transfer command. If it did not stop serving reads immediately, it would potentially serve reads with timestamps greater than the start timestamp of the new (transferred) lease. More subtly, the replica can't even serve reads or propose commands with timestamps lower than the start of the new lease because it could lead to read your own write violations (see comments on the stasis period in the Lease proto). We could, in principle, serve reads more than the maximum clock offset in the past.

The method waits for any in-progress lease extension to be done, and it also blocks until the transfer is done. If a transfer is already in progress, this method joins in waiting for it to complete if it's transferring to the same replica. Otherwise, a NotLeaderError is returned.

TODO(andrei): figure out how to persist the "not serving" state across node restarts.

func (*Replica) BeginTransaction

BeginTransaction writes the initial transaction record. Fails in the event that a transaction record is already written. This may occur if a transaction is started with a batch containing writes to different ranges, and the range containing the txn record fails to receive the write batch before a heartbeat or txn push is performed first and aborts the transaction.

func (*Replica) ChangeFrozen

ChangeFrozen freezes or unfreezes the Replica idempotently.

func (*Replica) ChangeReplicas

func (r *Replica) ChangeReplicas(
	ctx context.Context,
	changeType roachpb.ReplicaChangeType,
	repDesc roachpb.ReplicaDescriptor,
	desc *roachpb.RangeDescriptor,
) error

ChangeReplicas adds or removes a replica of a range. The change is performed in a distributed transaction and takes effect when that transaction is committed. When removing a replica, only the NodeID and StoreID fields of the Replica are used.

The supplied RangeDescriptor is used as a form of optimistic lock. See the comment of "AdminSplit" for more information on this pattern.

Changing the replicas for a range is complicated. A change is initiated by the "replicate" queue when it encounters a range which has too many replicas, too few replicas or requires rebalancing. Addition and removal of a replica is divided into four phases. The first phase, which occurs in Replica.ChangeReplicas, is performed via a distributed transaction which updates the range descriptor and the meta range addressing information. This transaction includes a special ChangeReplicasTrigger on the EndTransaction request. A ConditionalPut of the RangeDescriptor implements the optimistic lock on the RangeDescriptor mentioned previously. Like all transactions, the requests within the transaction are replicated via Raft, including the EndTransaction request.

The second phase of processing occurs when the batch containing the EndTransaction is proposed to raft. This proposing occurs on whatever replica received the batch, usually, but not always the range lease holder. defaultProposeRaftCommandLocked notices that the EndTransaction contains a ChangeReplicasTrigger and proposes a ConfChange to Raft (via raft.RawNode.ProposeConfChange).

The ConfChange is propagated to all of the replicas similar to a normal Raft command, though additional processing is done inside of Raft. A Replica encounters the ConfChange in Replica.handleRaftReady and executes it using raft.RawNode.ApplyConfChange. If a new replica was added the Raft leader will start sending it heartbeat messages and attempting to bring it up to date. If a replica was removed, it is at this point that the Raft leader will stop communicating with it.

The fourth phase of change replicas occurs when each replica for the range encounters the ChangeReplicasTrigger when applying the EndTransaction request. The replica will update its local range descriptor so as to contain the new set of replicas. If the replica is the one that is being removed, it will queue itself for removal with replicaGCQueue.

Note that a removed replica may not see the EndTransaction containing the ChangeReplicasTrigger. The ConfChange operation will be applied as soon as a quorum of nodes have committed it. If the removed replica is down or the message is dropped for some reason the removed replica will not be notified. The replica GC queue will eventually discover and cleanup this state.

When a new replica is added, it will have to catch up to the state of the other replicas. The Raft leader automatically handles this by either sending the new replica Raft log entries to apply, or by generating and sending a snapshot. See Replica.Snapshot and Replica.Entries.

Note that Replica.ChangeReplicas returns when the distributed transaction has been committed to a quorum of replicas in the range. The actual replication of data occurs asynchronously via a snapshot or application of Raft log entries. This is important for the replicate queue to be aware of. A node can process hundreds or thousands of ChangeReplicas operations per second even though the actual replication of data proceeds at a much slower base. In order to avoid having this background replication overwhelm the system, replication is throttled via a reservation system. When allocating a new replica for a range, the replicate queue reserves space for that replica on the target store via a ReservationRequest. (See StorePool.reserve). The reservation is fulfilled when the snapshot is applied.

TODO(peter): There is a rare scenario in which a replica can be brought up to date via Raft log replay. In this scenario, the reservation will be left dangling until it expires. See #7849.

TODO(peter): Describe preemptive snapshots. Preemptive snapshots are needed for the replicate queue to function properly. Currently the replicate queue will fire off as many replica additions as possible until it starts getting reservations denied at which point it will ignore the replica until the next scanner cycle.

func (*Replica) CheckConsistency

CheckConsistency runs a consistency check on the range. It first applies a ComputeChecksum command on the range. It then issues CollectChecksum commands to the other replicas.

func (*Replica) ComputeChecksum

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

func (*Replica) ConditionalPut

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

func (*Replica) ContainsKey

func (r *Replica) ContainsKey(key roachpb.Key) bool

ContainsKey returns whether this range contains the specified key.

func (*Replica) ContainsKeyRange

func (r *Replica) ContainsKeyRange(start, end roachpb.Key) bool

ContainsKeyRange returns whether this range contains the specified key range from start to end.

func (*Replica) Delete

Delete deletes the key and value specified by key.

func (*Replica) DeleteRange

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

func (*Replica) Desc

func (r *Replica) Desc() *roachpb.RangeDescriptor

Desc returns the authoritative range descriptor, acquiring a replica lock in the process.

func (*Replica) Destroy

func (r *Replica) Destroy(origDesc roachpb.RangeDescriptor, destroyData bool) error

Destroy clears pending command queue by sending each pending command an error and cleans up all data associated with this range.

func (*Replica) EndTransaction

EndTransaction either commits or aborts (rolls back) an extant transaction according to the args.Commit parameter. Rolling back an already rolled-back txn is ok.

func (*Replica) Entries

func (r *Replica) Entries(lo, hi, maxBytes uint64) ([]raftpb.Entry, error)

Entries implements the raft.Storage interface. Note that maxBytes is advisory and this method will always return at least one entry even if it exceeds maxBytes. Passing maxBytes equal to zero disables size checking. Entries requires that the replica lock is held.

func (*Replica) FirstIndex

func (r *Replica) FirstIndex() (uint64, error)

FirstIndex implements the raft.Storage interface. FirstIndex requires that the replica lock is held.

func (*Replica) GC

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 (*Replica) Get

Get returns the value for a specified key.

func (*Replica) GetFirstIndex

func (r *Replica) GetFirstIndex() (uint64, error)

GetFirstIndex is the same function as FirstIndex but it does not require that the replica lock is held.

func (*Replica) GetMVCCStats

func (r *Replica) GetMVCCStats() enginepb.MVCCStats

GetMVCCStats returns a copy of the MVCC stats object for this range.

func (*Replica) GetMaxBytes

func (r *Replica) GetMaxBytes() int64

GetMaxBytes atomically gets the range maximum byte limit.

func (*Replica) GetReplicaDescriptor

func (r *Replica) GetReplicaDescriptor() (roachpb.ReplicaDescriptor, error)

GetReplicaDescriptor returns the replica for this range from the range descriptor. Returns a *RangeNotFoundError if the replica is not found. No other errors are returned.

func (*Replica) GetSnapshot

func (r *Replica) GetSnapshot(ctx context.Context) (raftpb.Snapshot, error)

GetSnapshot wraps Snapshot() but does not require the replica lock to be held and it will block instead of returning ErrSnapshotTemporaryUnavailable.

func (*Replica) HeartbeatTxn

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

func (*Replica) Increment

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 (*Replica) InitPut

InitPut sets the value for a specified key only if it doesn't exist. It returns an error if the key exists with an existing value that is different from the value provided.

func (*Replica) InitialState

func (r *Replica) InitialState() (raftpb.HardState, raftpb.ConfState, error)

InitialState implements the raft.Storage interface. InitialState requires that the replica lock be held.

func (*Replica) IsFirstRange

func (r *Replica) IsFirstRange() bool

IsFirstRange returns true if this is the first range.

func (*Replica) IsInitialized

func (r *Replica) IsInitialized() bool

IsInitialized is true if we know the metadata of this range, either because we created it or we have received an initial snapshot from another node. It is false when a range has been created in response to an incoming message but we are waiting for our initial snapshot.

func (*Replica) LastIndex

func (r *Replica) LastIndex() (uint64, error)

LastIndex implements the raft.Storage interface. LastIndex requires that the replica lock is held.

func (*Replica) LeaseInfo

LeaseInfo returns information about the lease holder for the range.

func (*Replica) Less

func (r *Replica) Less(i btree.Item) bool

Less implements the btree.Item interface.

func (*Replica) Merge

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 (*Replica) PushTxn

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" (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.PushTxn -- the pushee txn whose intent(s) caused the conflict). A pusher is either transactional, in which case PushTxn is completely initialized, or not, in which case the PushTxn has only the priority set.

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

Txn Timeout: If pushee txn entry isn't present or its LastHeartbeat timestamp isn't set, use its as LastHeartbeat. If current time - LastHeartbeat > 2 * DefaultHeartbeatInterval, then the pushee txn should be either pushed forward, aborted, or confirmed not pending, depending on value of Request.PushType.

Old Txn Epoch: If persisted pushee txn entry has a newer Epoch than PushTxn.Epoch, return success, as older epoch may be removed.

Lower Txn Priority: If pushee txn has a lower priority than pusher, adjust pushee's persisted txn depending on value of args.PushType. If args.PushType is PUSH_ABORT, set txn.Status to ABORTED, and priority to one less than the pusher's priority and return success. If args.PushType is PUSH_TIMESTAMP, set txn.Timestamp to just after PushTo.

Higher Txn Priority: If pushee txn has a higher priority than pusher, return TransactionPushError. Transaction will be retried with priority one less than the pushee's higher priority.

If the pusher is non-transactional, args.PusherTxn is an empty proto with only the priority set.

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 abort cache, allowing the GC queue to purge entries for which the transaction coordinator must have found out via its heartbeats that the transaction has failed.

func (*Replica) Put

Put sets the value for a specified key.

func (*Replica) RaftStatus

func (r *Replica) RaftStatus() *raft.Status

RaftStatus returns the current raft status of the replica. It returns nil if the Raft group has not been initialized yet.

func (*Replica) RangeLookup

RangeLookup is used to look up RangeDescriptors - a RangeDescriptor is a metadata structure which describes the key range and replica locations of a distinct range in the cluster.

RangeDescriptors are stored as values in the cockroach cluster's key-value store. However, they are always stored using special "Range Metadata keys", which are "ordinary" keys with a special prefix prepended. The Range Metadata Key for an ordinary key can be generated with the `keys.RangeMetaKey(key)` function. The RangeDescriptor for the range which contains a given key can be retrieved by generating its Range Metadata Key and dispatching it to RangeLookup.

Note that the Range Metadata Key sent to RangeLookup is NOT the key at which the desired RangeDescriptor is stored. Instead, this method returns the RangeDescriptor stored at the _lowest_ existing key which is _greater_ than the given key. The returned RangeDescriptor will thus contain the ordinary key which was originally used to generate the Range Metadata Key sent to RangeLookup.

The "Range Metadata Key" for a range is built by appending the end key of the range to the respective meta prefix.

Lookups for range metadata keys usually want to read inconsistently, but some callers need a consistent result; both are supported.

This method has an important optimization in the inconsistent case: instead of just returning the request RangeDescriptor, it also returns a slice of additional range descriptors immediately consecutive to the desired RangeDescriptor. This is intended to serve as a sort of caching pre-fetch, so that the requesting nodes can aggressively cache RangeDescriptors which are likely to be desired by their current workload. The Reverse flag specifies whether descriptors are prefetched in descending or ascending order.

func (*Replica) RequestLease

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 clearing the command queue and timestamp cache.

func (*Replica) ResolveIntent

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

func (*Replica) ResolveIntentRange

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

func (*Replica) ReverseScan

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 (*Replica) Scan

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 (*Replica) Send

Send adds a command for execution on this range. The command's affected keys are verified to be contained within the range and the range's lease is confirmed. The command is then dispatched either along the read-only execution path or the read-write Raft command queue. ctx should contain the log tags from the store (and up).

func (*Replica) SetMaxBytes

func (r *Replica) SetMaxBytes(maxBytes int64)

SetMaxBytes atomically sets the maximum byte limit before split. This value is cached by the range for efficiency.

func (*Replica) Snapshot

func (r *Replica) Snapshot() (raftpb.Snapshot, error)

Snapshot implements the raft.Storage interface. Snapshot requires that the replica lock is held.

func (*Replica) SnapshotWithContext

func (r *Replica) SnapshotWithContext(ctx context.Context) (raftpb.Snapshot, error)

SnapshotWithContext is main implementation for Snapshot() but it takes a context to allow tracing.

func (*Replica) State

func (r *Replica) State() storagebase.RangeInfo

State returns a copy of the internal state of the Replica, along with some auxiliary information.

func (*Replica) String

func (r *Replica) String() string

String returns the string representation of the replica using an inconsistent copy of the range descriptor. Therefore, String does not require a lock and its output may not be atomic with other ongoing work in the replica. This is done to prevent deadlocks in logging sites.

func (*Replica) Term

func (r *Replica) Term(i uint64) (uint64, error)

Term implements the raft.Storage interface. Term requires that the replica lock is held.

func (*Replica) TransferLease

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 (*Replica) TruncateLog

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.

type ReplicaDataIterator

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

ReplicaDataIterator provides a complete iteration over all key / value rows in a range, including all system-local metadata and user data. The ranges keyRange slice specifies the key ranges which comprise all of the range's data.

A ReplicaDataIterator provides a subset of the engine.Iterator interface.

func NewReplicaDataIterator

func NewReplicaDataIterator(
	d *roachpb.RangeDescriptor, e engine.Reader, replicatedOnly bool,
) *ReplicaDataIterator

NewReplicaDataIterator creates a ReplicaDataIterator for the given replica.

func (*ReplicaDataIterator) Close

func (ri *ReplicaDataIterator) Close()

Close the underlying iterator.

func (*ReplicaDataIterator) Error

func (ri *ReplicaDataIterator) Error() error

Error returns the error, if any, which the iterator encountered.

func (*ReplicaDataIterator) Key

Key returns the current key.

func (*ReplicaDataIterator) Next

func (ri *ReplicaDataIterator) Next()

Next advances to the next key in the iteration.

func (*ReplicaDataIterator) Valid

func (ri *ReplicaDataIterator) Valid() bool

Valid returns true if the iterator currently points to a valid value.

func (*ReplicaDataIterator) Value

func (ri *ReplicaDataIterator) Value() []byte

Value returns the current value.

type ReplicaPlaceholder

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

ReplicaPlaceholder is created by a Store in anticipation of replacing it at some point in the future with a Replica. It has a RangeDescriptor.

func (*ReplicaPlaceholder) Desc

Desc returns the range Placeholder's descriptor.

func (*ReplicaPlaceholder) Less

func (r *ReplicaPlaceholder) Less(i btree.Item) bool

Less implements the btree.Item interface.

func (*ReplicaPlaceholder) String

func (r *ReplicaPlaceholder) String() string

type ReplicaSnapshotDiff

type ReplicaSnapshotDiff struct {
	// LeaseHolder is set to true of this k:v pair is only present on the lease
	// holder.
	LeaseHolder bool
	Key         roachpb.Key
	Timestamp   hlc.Timestamp
	Value       []byte
}

ReplicaSnapshotDiff is a part of a []ReplicaSnapshotDiff which represents a diff between two replica snapshots. For now it's only a diff between their KV pairs.

type ReservationRequest

type ReservationRequest struct {
	StoreRequestHeader `protobuf:"bytes,1,opt,name=header,embedded=header" json:"header"`
	FromNodeID         github_com_cockroachdb_cockroach_roachpb.NodeID  `` /* 151-byte string literal not displayed */
	FromStoreID        github_com_cockroachdb_cockroach_roachpb.StoreID `` /* 155-byte string literal not displayed */
	RangeID            github_com_cockroachdb_cockroach_roachpb.RangeID `` /* 141-byte string literal not displayed */
	RangeSize          int64                                            `protobuf:"varint,5,opt,name=range_size,json=rangeSize,proto3" json:"range_size,omitempty"`
}

A ReservationRequest asks the addressed Store to reserve the space for a new replica for the Range of RangeID reserving RangeSize bytes.

func (*ReservationRequest) Descriptor

func (*ReservationRequest) Descriptor() ([]byte, []int)

func (*ReservationRequest) Marshal

func (m *ReservationRequest) Marshal() (data []byte, err error)

func (*ReservationRequest) MarshalTo

func (m *ReservationRequest) MarshalTo(data []byte) (int, error)

func (*ReservationRequest) ProtoMessage

func (*ReservationRequest) ProtoMessage()

func (*ReservationRequest) Reset

func (m *ReservationRequest) Reset()

func (*ReservationRequest) Size

func (m *ReservationRequest) Size() (n int)

func (*ReservationRequest) String

func (m *ReservationRequest) String() string

func (*ReservationRequest) Unmarshal

func (m *ReservationRequest) Unmarshal(data []byte) error

type ReservationResponse

type ReservationResponse struct {
	Reserved bool `protobuf:"varint,1,opt,name=reserved,proto3" json:"reserved,omitempty"`
	// The current number of ranges and reservations on the target
	// store. This is returned even if the reservation isn't filled.
	RangeCount int32 `protobuf:"varint,2,opt,name=range_count,json=rangeCount,proto3" json:"range_count,omitempty"`
}

A ReservationResponse is the response returned from a ReservationRequest.

func (*ReservationResponse) Descriptor

func (*ReservationResponse) Descriptor() ([]byte, []int)

func (*ReservationResponse) Marshal

func (m *ReservationResponse) Marshal() (data []byte, err error)

func (*ReservationResponse) MarshalTo

func (m *ReservationResponse) MarshalTo(data []byte) (int, error)

func (*ReservationResponse) ProtoMessage

func (*ReservationResponse) ProtoMessage()

func (*ReservationResponse) Reset

func (m *ReservationResponse) Reset()

func (*ReservationResponse) Size

func (m *ReservationResponse) Size() (n int)

func (*ReservationResponse) String

func (m *ReservationResponse) String() string

func (*ReservationResponse) Unmarshal

func (m *ReservationResponse) Unmarshal(data []byte) error

type Server

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

Server implements the storage parts of the StoresServer interface.

func MakeServer

func MakeServer(
	descriptor *roachpb.NodeDescriptor, stores *Stores,
) Server

MakeServer returns a new instance of Server.

func (Server) CollectChecksum

func (is Server) CollectChecksum(
	ctx context.Context, req *CollectChecksumRequest,
) (*CollectChecksumResponse, error)

CollectChecksum implements ConsistencyServer.

func (Server) PollFrozen

func (is Server) PollFrozen(
	ctx context.Context, args *PollFrozenRequest,
) (*PollFrozenResponse, error)

PollFrozen implements the StoresServer interface.

func (Server) Reserve

func (is Server) Reserve(
	ctx context.Context, req *ReservationRequest,
) (*ReservationResponse, error)

Reserve implements the StoresServer interface.

type Store

type Store struct {
	Ident roachpb.StoreIdent
	// contains filtered or unexported fields
}

A Store maintains a map of ranges by start key. A Store corresponds to one physical device.

func NewStore

func NewStore(ctx StoreContext, eng engine.Engine, nodeDesc *roachpb.NodeDescriptor) *Store

NewStore returns a new instance of a store.

func (*Store) AcquireRaftSnapshot

func (s *Store) AcquireRaftSnapshot() bool

AcquireRaftSnapshot returns true if a new raft snapshot can start. If true is returned, the caller MUST call ReleaseRaftSnapshot.

func (*Store) AddReplicaTest

func (s *Store) AddReplicaTest(rng *Replica) error

AddReplicaTest adds the replica to the store's replica map and to the sorted replicasByKey slice. To be used only by unittests.

func (*Store) Attrs

func (s *Store) Attrs() roachpb.Attributes

Attrs returns the attributes of the underlying store.

func (*Store) Bootstrap

func (s *Store) Bootstrap(ident roachpb.StoreIdent, stopper *stop.Stopper) error

Bootstrap writes a new store ident to the underlying engine. To ensure that no crufty data already exists in the engine, it scans the engine contents before writing the new store ident. The engine should be completely empty. It returns an error if called on a non-empty engine.

func (*Store) BootstrapRange

func (s *Store) BootstrapRange(initialValues []roachpb.KeyValue) error

BootstrapRange creates the first range in the cluster and manually writes it to the store. Default range addressing records are created for meta1 and meta2. Default configurations for zones are created. All configs are specified for the empty key prefix, meaning they apply to the entire database. The zone requires three replicas with no other specifications. It also adds the range tree and the root node, the first range, to it. The 'initialValues' are written as well after each value's checksum is initialized.

func (*Store) Capacity

func (s *Store) Capacity() (roachpb.StoreCapacity, error)

Capacity returns the capacity of the underlying storage engine. Note that this does not include reservations.

func (*Store) Clock

func (s *Store) Clock() *hlc.Clock

Clock accessor.

func (*Store) ClusterID

func (s *Store) ClusterID() uuid.UUID

ClusterID accessor.

func (*Store) ComputeMetrics

func (s *Store) ComputeMetrics(tick int) error

ComputeMetrics immediately computes the current value of store metrics which cannot be computed incrementally. This method should be invoked periodically by a higher-level system which records store metrics.

func (*Store) ComputeStatsForKeySpan

func (s *Store) ComputeStatsForKeySpan(startKey, endKey roachpb.RKey) (enginepb.MVCCStats, int)

ComputeStatsForKeySpan computes the aggregated MVCCStats for all replicas on this store which contain any keys in the supplied range.

func (*Store) Ctx

func (s *Store) Ctx() context.Context

Ctx returns the base context for the store.

func (*Store) DB

func (s *Store) DB() *client.DB

DB accessor.

func (*Store) Descriptor

func (s *Store) Descriptor() (*roachpb.StoreDescriptor, error)

Descriptor returns a StoreDescriptor including current store capacity information.

func (*Store) DrainLeases

func (s *Store) DrainLeases(drain bool) error

DrainLeases (when called with 'true') prevents all of the Store's Replicas from acquiring or extending range leases and waits until all of them have expired. If an error is returned, the draining state is still active, but there may be active leases held by some of the Store's Replicas. When called with 'false', returns to the normal mode of operation.

func (*Store) Engine

func (s *Store) Engine() engine.Engine

Engine accessor.

func (*Store) FrozenStatus

func (s *Store) FrozenStatus(collectFrozen bool) (repDescs []roachpb.ReplicaDescriptor)

FrozenStatus returns all of the Store's Replicas which are frozen (if the parameter is true) or unfrozen (otherwise). It makes no attempt to prevent new data being rebalanced to the Store, and thus does not guarantee that the Store remains in the reported state.

func (*Store) GetReplica

func (s *Store) GetReplica(rangeID roachpb.RangeID) (*Replica, error)

GetReplica fetches a replica by Range ID. Returns an error if no replica is found.

func (*Store) Gossip

func (s *Store) Gossip() *gossip.Gossip

Gossip accessor.

func (*Store) GossipDeadReplicas

func (s *Store) GossipDeadReplicas(ctx context.Context) error

GossipDeadReplicas broadcasts the stores dead replicas on the gossip network.

func (*Store) GossipStore

func (s *Store) GossipStore(ctx context.Context) error

GossipStore broadcasts the store on the gossip network.

func (*Store) HandleRaftRequest

func (s *Store) HandleRaftRequest(
	ctx context.Context,
	req *RaftMessageRequest,
	respStream RaftMessageResponseStream,
) (pErr *roachpb.Error)

HandleRaftRequest dispatches a raft message to the appropriate Replica. It requires that s.mu is not held.

func (*Store) HandleRaftResponse

func (s *Store) HandleRaftResponse(ctx context.Context, resp *RaftMessageResponse)

HandleRaftResponse handles response messages from the raft transport. It requires that s.mu is not held.

func (*Store) IsDrainingLeases

func (s *Store) IsDrainingLeases() bool

IsDrainingLeases accessor.

func (*Store) IsStarted

func (s *Store) IsStarted() bool

IsStarted returns true if the Store has been started.

func (*Store) LookupReplica

func (s *Store) LookupReplica(start, end roachpb.RKey) *Replica

LookupReplica looks up a replica via binary search over the "replicasByKey" btree. Returns nil if no replica is found for specified key range. Note that the specified keys are transformed using Key.Address() to ensure we lookup replicas correctly for local keys. When end is nil, a replica that contains start is looked up.

func (*Store) MVCCStats

func (s *Store) MVCCStats() enginepb.MVCCStats

MVCCStats returns the current MVCCStats accumulated for this store. TODO(mrtracy): This should be removed as part of #4465, this is only needed to support the current StatusSummary structures which will be changing.

func (*Store) MergeRange

func (s *Store) MergeRange(subsumingRng *Replica, updatedEndKey roachpb.RKey, subsumedRangeID roachpb.RangeID) error

MergeRange expands the subsuming range to absorb the subsumed range. This merge operation will fail if the two ranges are not collocated on the same store. The subsumed range's raftMu is assumed held.

func (*Store) Metrics

func (s *Store) Metrics() *StoreMetrics

Metrics returns the store's metric struct.

func (*Store) NewRangeDescriptor

func (s *Store) NewRangeDescriptor(
	start, end roachpb.RKey, replicas []roachpb.ReplicaDescriptor,
) (*roachpb.RangeDescriptor, error)

NewRangeDescriptor creates a new descriptor based on start and end keys and the supplied roachpb.Replicas slice. It allocates a new range ID and returns a RangeDescriptor whose Replicas are a copy of the supplied replicas slice, with appropriate ReplicaIDs assigned.

func (*Store) NewSnapshot

func (s *Store) NewSnapshot() engine.Reader

NewSnapshot creates a new snapshot engine.

func (*Store) RaftStatus

func (s *Store) RaftStatus(rangeID roachpb.RangeID) *raft.Status

RaftStatus returns the current raft status of the local replica of the given range.

func (*Store) Registry

func (s *Store) Registry() *metric.Registry

Registry returns the store registry.

func (*Store) ReleaseRaftSnapshot

func (s *Store) ReleaseRaftSnapshot()

ReleaseRaftSnapshot decrements the count of active snapshots.

func (*Store) RemoveReplica

func (s *Store) RemoveReplica(rep *Replica, origDesc roachpb.RangeDescriptor, destroy bool) error

RemoveReplica removes the replica from the store's replica map and from the sorted replicasByKey btree. The version of the replica descriptor that was used to make the removal decision is passed in, and the removal is aborted if the replica ID has changed since then. If `destroy` is true, all data belonging to the replica will be deleted. In either case a tombstone record will be written.

func (*Store) ReplicaCount

func (s *Store) ReplicaCount() int

ReplicaCount returns the number of replicas contained by this store.

func (*Store) Reserve

Reserve requests a reservation from the store's bookie.

func (*Store) Send

func (s *Store) Send(ctx context.Context, ba roachpb.BatchRequest) (br *roachpb.BatchResponse, pErr *roachpb.Error)

Send fetches a range based on the header's replica, assembles method, args & reply into a Raft Cmd struct and executes the command using the fetched range. An incoming request may be transactional or not. If it is not transactional, the timestamp at which it executes may be higher than that optionally specified through the incoming BatchRequest, and it is not guaranteed that all operations are written at the same timestamp. If it is transactional, a timestamp must not be set - it is deduced automatically from the transaction. In particular, the read (original) timestamp will be used for all reads _and writes_ (see the TxnMeta.OrigTimestamp for details).

Should a transactional operation be forced to a higher timestamp (for instance due to the timestamp cache or finding a committed value in the path of one of its writes), the response will have a transaction set which should be used to update the client transaction.

func (*Store) SplitRange

func (s *Store) SplitRange(origRng, newRng *Replica) error

SplitRange shortens the original range to accommodate the new range. The new range is added to the ranges map and the replicasByKey btree. origRng.raftMu, newRng.raftMu and Store.uninitRaftMu must be held.

This is only called from the split trigger in the context of the execution of a Raft command.

func (*Store) Start

func (s *Store) Start(ctx context.Context, stopper *stop.Stopper) error

Start the engine, set the GC and read the StoreIdent.

func (*Store) Stopper

func (s *Store) Stopper() *stop.Stopper

Stopper accessor.

func (*Store) StoreID

func (s *Store) StoreID() roachpb.StoreID

StoreID accessor.

func (*Store) String

func (s *Store) String() string

String formats a store for debug output.

func (*Store) TestingKnobs

func (s *Store) TestingKnobs() *StoreTestingKnobs

TestingKnobs accessor.

func (*Store) Tracer

func (s *Store) Tracer() opentracing.Tracer

Tracer accessor.

func (*Store) WaitForInit

func (s *Store) WaitForInit()

WaitForInit waits for any asynchronous processes begun in Start() to complete their initialization. In particular, this includes gossiping. In some cases this may block until the range GC queue has completed its scan. Only for testing.

type StoreContext

type StoreContext struct {
	// Base context to be used for logs and traces inside the node or store; must
	// have a Tracer set.
	Ctx context.Context

	Clock     *hlc.Clock
	DB        *client.DB
	Gossip    *gossip.Gossip
	StorePool *StorePool
	Transport *RaftTransport

	// SQLExecutor is used by the store to execute SQL statements in a way that
	// is more direct than using a sql.Executor.
	SQLExecutor sqlutil.InternalExecutor

	// RangeRetryOptions are the retry options when retryable errors are
	// encountered sending commands to ranges.
	RangeRetryOptions retry.Options

	// RaftTickInterval is the resolution of the Raft timer; other raft timeouts
	// are defined in terms of multiples of this value.
	RaftTickInterval time.Duration

	// RaftHeartbeatIntervalTicks is the number of ticks that pass between heartbeats.
	RaftHeartbeatIntervalTicks int

	// RaftElectionTimeoutTicks is the number of ticks that must pass before a follower
	// considers a leader to have failed and calls a new election. Should be significantly
	// higher than RaftHeartbeatIntervalTicks. The raft paper recommends a value of 150ms
	// for local networks.
	RaftElectionTimeoutTicks int

	// ScanInterval is the default value for the scan interval
	ScanInterval time.Duration

	// ScanMaxIdleTime is the maximum time the scanner will be idle between ranges.
	// If enabled (> 0), the scanner may complete in less than ScanInterval for small
	// stores.
	ScanMaxIdleTime time.Duration

	// ConsistencyCheckInterval is the default time period in between consecutive
	// consistency checks on a range.
	ConsistencyCheckInterval time.Duration

	// ConsistencyCheckPanicOnFailure causes the node to panic when it detects a
	// replication consistency check failure.
	ConsistencyCheckPanicOnFailure bool

	// AllocatorOptions configures how the store will attempt to rebalance its
	// replicas to other stores.
	AllocatorOptions AllocatorOptions

	// If LogRangeEvents is true, major changes to ranges will be logged into
	// the range event log.
	LogRangeEvents bool

	// BlockingSnapshotDuration is the amount of time Replica.Snapshot
	// will wait before switching to asynchronous mode. Zero is a good
	// choice for production but non-zero values can speed up tests.
	// (This only blocks on the first attempt; it will not block a
	// second time if the generation is still in progress).
	BlockingSnapshotDuration time.Duration

	// AsyncSnapshotMaxAge is the maximum amount of time that an
	// asynchronous snapshot will be held while waiting for raft to pick
	// it up (counted from when the snapshot generation is completed).
	AsyncSnapshotMaxAge time.Duration

	// RaftEntryCacheSize is the size in bytes of the Raft log entry cache
	// shared by all Raft groups managed by the store.
	RaftEntryCacheSize uint64

	TestingKnobs StoreTestingKnobs

	// Locality is a description of the topography of the store.
	Locality roachpb.Locality
	// contains filtered or unexported fields
}

A StoreContext encompasses the auxiliary objects and configuration required to create a store. All fields holding a pointer or an interface are required to create a store; the rest will have sane defaults set if omitted. TODO(radu): rename this to StoreConfig

func TestStoreContext

func TestStoreContext() StoreContext

TestStoreContext has some fields initialized with values relevant in tests.

func (*StoreContext) Valid

func (sc *StoreContext) Valid() bool

Valid returns true if the StoreContext is populated correctly. We don't check for Gossip and DB since some of our tests pass that as nil.

type StoreList

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

StoreList holds a list of store descriptors and associated count and used stats for those stores.

func (StoreList) String

func (sl StoreList) String() string

type StoreMetrics

type StoreMetrics struct {

	// Replica metrics.
	ReplicaCount                  *metric.Counter // Does not include reserved replicas.
	ReservedReplicaCount          *metric.Counter
	RaftLeaderCount               *metric.Gauge
	RaftLeaderNotLeaseHolderCount *metric.Gauge
	LeaseHolderCount              *metric.Gauge
	QuiescentCount                *metric.Gauge

	// Range metrics.
	AvailableRangeCount *metric.Gauge

	// Replication metrics.
	ReplicaAllocatorNoopCount       *metric.Gauge
	ReplicaAllocatorRemoveCount     *metric.Gauge
	ReplicaAllocatorAddCount        *metric.Gauge
	ReplicaAllocatorRemoveDeadCount *metric.Gauge

	// Lease request metrics.
	LeaseRequestSuccessCount *metric.Counter
	LeaseRequestErrorCount   *metric.Counter

	// Storage metrics.
	LiveBytes       *metric.Gauge
	KeyBytes        *metric.Gauge
	ValBytes        *metric.Gauge
	IntentBytes     *metric.Gauge
	LiveCount       *metric.Gauge
	KeyCount        *metric.Gauge
	ValCount        *metric.Gauge
	IntentCount     *metric.Gauge
	IntentAge       *metric.Gauge
	GcBytesAge      *metric.Gauge
	LastUpdateNanos *metric.Gauge
	Capacity        *metric.Gauge
	Available       *metric.Gauge
	Reserved        *metric.Counter
	SysBytes        *metric.Gauge
	SysCount        *metric.Gauge

	// RocksDB metrics.
	RdbBlockCacheHits           *metric.Gauge
	RdbBlockCacheMisses         *metric.Gauge
	RdbBlockCacheUsage          *metric.Gauge
	RdbBlockCachePinnedUsage    *metric.Gauge
	RdbBloomFilterPrefixChecked *metric.Gauge
	RdbBloomFilterPrefixUseful  *metric.Gauge
	RdbMemtableHits             *metric.Gauge
	RdbMemtableMisses           *metric.Gauge
	RdbMemtableTotalSize        *metric.Gauge
	RdbFlushes                  *metric.Gauge
	RdbCompactions              *metric.Gauge
	RdbTableReadersMemEstimate  *metric.Gauge
	RdbReadAmplification        *metric.Gauge

	// Range event metrics.
	RangeSplits                     *metric.Counter
	RangeAdds                       *metric.Counter
	RangeRemoves                    *metric.Counter
	RangeSnapshotsGenerated         *metric.Counter
	RangeSnapshotsNormalApplied     *metric.Counter
	RangeSnapshotsPreemptiveApplied *metric.Counter

	// Raft processing metrics.
	RaftTicks                *metric.Counter
	RaftWorkingDurationNanos *metric.Counter
	RaftTickingDurationNanos *metric.Counter

	// Raft message metrics.
	RaftRcvdMsgProp           *metric.Counter
	RaftRcvdMsgApp            *metric.Counter
	RaftRcvdMsgAppResp        *metric.Counter
	RaftRcvdMsgVote           *metric.Counter
	RaftRcvdMsgVoteResp       *metric.Counter
	RaftRcvdMsgSnap           *metric.Counter
	RaftRcvdMsgHeartbeat      *metric.Counter
	RaftRcvdMsgHeartbeatResp  *metric.Counter
	RaftRcvdMsgTransferLeader *metric.Counter
	RaftRcvdMsgTimeoutNow     *metric.Counter
	RaftRcvdMsgDropped        *metric.Counter

	RaftEnqueuedPending *metric.Gauge

	// Replica queue metrics.
	GCQueueSuccesses                *metric.Counter
	GCQueueFailures                 *metric.Counter
	GCQueuePending                  *metric.Gauge
	GCQueueProcessingNanos          *metric.Counter
	RaftLogQueueSuccesses           *metric.Counter
	RaftLogQueueFailures            *metric.Counter
	RaftLogQueuePending             *metric.Gauge
	RaftLogQueueProcessingNanos     *metric.Counter
	ConsistencyQueueSuccesses       *metric.Counter
	ConsistencyQueueFailures        *metric.Counter
	ConsistencyQueuePending         *metric.Gauge
	ConsistencyQueueProcessingNanos *metric.Counter
	ReplicaGCQueueSuccesses         *metric.Counter
	ReplicaGCQueueFailures          *metric.Counter
	ReplicaGCQueuePending           *metric.Gauge
	ReplicaGCQueueProcessingNanos   *metric.Counter
	ReplicateQueueSuccesses         *metric.Counter
	ReplicateQueueFailures          *metric.Counter
	ReplicateQueuePending           *metric.Gauge
	ReplicateQueueProcessingNanos   *metric.Counter
	ReplicateQueuePurgatory         *metric.Gauge
	SplitQueueSuccesses             *metric.Counter
	SplitQueueFailures              *metric.Counter
	SplitQueuePending               *metric.Gauge
	SplitQueueProcessingNanos       *metric.Counter
	// contains filtered or unexported fields
}

StoreMetrics is the set of metrics for a given store.

type StorePool

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

StorePool maintains a list of all known stores in the cluster and information on their health.

func NewStorePool

func NewStorePool(
	g *gossip.Gossip,
	clock *hlc.Clock,
	rpcContext *rpc.Context,
	reservationsEnabled bool,
	timeUntilStoreDead time.Duration,
	stopper *stop.Stopper,
) *StorePool

NewStorePool creates a StorePool and registers the store updating callback with gossip.

func (*StorePool) String

func (sp *StorePool) String() string

type StoreRequestHeader

type StoreRequestHeader struct {
	NodeID  github_com_cockroachdb_cockroach_roachpb.NodeID  `` /* 137-byte string literal not displayed */
	StoreID github_com_cockroachdb_cockroach_roachpb.StoreID `` /* 141-byte string literal not displayed */
}

StoreRequestHeader locates a Store on a Node.

func (*StoreRequestHeader) Descriptor

func (*StoreRequestHeader) Descriptor() ([]byte, []int)

func (*StoreRequestHeader) Marshal

func (m *StoreRequestHeader) Marshal() (data []byte, err error)

func (*StoreRequestHeader) MarshalTo

func (m *StoreRequestHeader) MarshalTo(data []byte) (int, error)

func (*StoreRequestHeader) ProtoMessage

func (*StoreRequestHeader) ProtoMessage()

func (*StoreRequestHeader) Reset

func (m *StoreRequestHeader) Reset()

func (*StoreRequestHeader) Size

func (m *StoreRequestHeader) Size() (n int)

func (*StoreRequestHeader) String

func (m *StoreRequestHeader) String() string

func (*StoreRequestHeader) Unmarshal

func (m *StoreRequestHeader) Unmarshal(data []byte) error

type StoreTestingKnobs

type StoreTestingKnobs struct {
	// A callback to be called when executing every replica command.
	// If your filter is not idempotent, consider wrapping it in a
	// ReplayProtectionFilterWrapper.
	TestingCommandFilter storagebase.ReplicaCommandFilter
	// If non-nil, BadChecksumPanic is called by CheckConsistency() instead of
	// panicking on a checksum mismatch.
	BadChecksumPanic func(roachpb.StoreIdent)
	// If non-nil, BadChecksumReportDiff is called by CheckConsistency() on a
	// checksum mismatch to report the diff between snapshots.
	BadChecksumReportDiff func(roachpb.StoreIdent, []ReplicaSnapshotDiff)
	// Disables the use of one phase commits.
	DisableOnePhaseCommits bool
	// A hack to manipulate the clock before sending a batch request to a replica.
	// TODO(kaneda): This hook is not encouraged to use. Get rid of it once
	// we make TestServer take a ManualClock.
	ClockBeforeSend func(*hlc.Clock, roachpb.BatchRequest)
	// LeaseTransferBlockedOnExtensionEvent, if set, is called when
	// replica.TransferLease() encounters an in-progress lease extension.
	// nextLeader is the replica that we're trying to transfer the lease to.
	LeaseTransferBlockedOnExtensionEvent func(nextLeader roachpb.ReplicaDescriptor)
	// DisableReplicaGCQueue disables the replication queue.
	DisableReplicaGCQueue bool
	// DisableReplicateQueue disables the replication queue.
	DisableReplicateQueue bool
	// DisableSplitQueue disables the split queue.
	DisableSplitQueue bool
	// DisableScanner disables the replica scanner.
	DisableScanner bool
	// DisableRefreshReasonTicks disables refreshing pending commands when a new
	// leader is discovered.
	DisableRefreshReasonNewLeader bool
	// DisableRefreshReasonTicks disables refreshing pending commands when a
	// snapshot is applied.
	DisableRefreshReasonSnapshotApplied bool
	// DisableRefreshReasonTicks disables refreshing pending commands
	// periodically.
	DisableRefreshReasonTicks bool
	// DisableProcessRaft disables the process raft loop.
	DisableProcessRaft bool
}

StoreTestingKnobs is a part of the context used to control parts of the system.

func (*StoreTestingKnobs) ModuleTestingKnobs

func (*StoreTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type Stores

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

A Stores provides methods to access a collection of stores. There's a visitor pattern and also an implementation of the client.Sender interface which directs a call to the appropriate store based on the call's key range. Stores also implements the gossip.Storage interface, which allows gossip bootstrap information to be persisted consistently to every store and the most recent bootstrap information to be read at node startup.

func NewStores

func NewStores(clock *hlc.Clock) *Stores

NewStores returns a local-only sender which directly accesses a collection of stores.

func (*Stores) AddStore

func (ls *Stores) AddStore(s *Store)

AddStore adds the specified store to the store map.

func (*Stores) FirstRange

func (ls *Stores) FirstRange() (*roachpb.RangeDescriptor, error)

FirstRange implements the RangeDescriptorDB interface. It returns the range descriptor which contains KeyMin.

func (*Stores) GetStore

func (ls *Stores) GetStore(storeID roachpb.StoreID) (*Store, error)

GetStore looks up the store by store ID. Returns an error if not found.

func (*Stores) GetStoreCount

func (ls *Stores) GetStoreCount() int

GetStoreCount returns the number of stores this node is exporting.

func (*Stores) HasStore

func (ls *Stores) HasStore(storeID roachpb.StoreID) bool

HasStore returns true if the specified store is owned by this Stores.

func (*Stores) LookupReplica

func (ls *Stores) LookupReplica(
	start, end roachpb.RKey,
) (roachpb.RangeID, roachpb.ReplicaDescriptor, error)

LookupReplica looks up replica by key [range]. Lookups are done by consulting each store in turn via Store.LookupReplica(key). Returns RangeID and replica on success; RangeKeyMismatch error if not found. If end is nil, a replica containing start is looked up. This is only for testing usage; performance doesn't matter.

func (*Stores) ReadBootstrapInfo

func (ls *Stores) ReadBootstrapInfo(bi *gossip.BootstrapInfo) error

ReadBootstrapInfo implements the gossip.Storage interface. Read attempts to read gossip bootstrap info from every known store and finds the most recent from all stores to initialize the bootstrap info argument. Returns an error on any issues reading data for the stores (but excluding the case in which no data has been persisted yet).

func (*Stores) RemoveStore

func (ls *Stores) RemoveStore(s *Store)

RemoveStore removes the specified store from the store map.

func (*Stores) Send

Send implements the client.Sender interface. The store is looked up from the store map if specified by the request; otherwise, the command is being executed locally, and the replica is determined via lookup through each store's LookupRange method. The latter path is taken only by unit tests.

func (*Stores) VisitStores

func (ls *Stores) VisitStores(visitor func(s *Store) error) error

VisitStores implements a visitor pattern over stores in the storeMap. The specified function is invoked with each store in turn. Care is taken to invoke the visitor func without the lock held to avoid inconsistent lock orderings, as some visitor functions may call back into the Stores object. Stores are visited in random order.

func (*Stores) WriteBootstrapInfo

func (ls *Stores) WriteBootstrapInfo(bi *gossip.BootstrapInfo) error

WriteBootstrapInfo implements the gossip.Storage interface. Write persists the supplied bootstrap info to every known store. Returns nil on success; otherwise returns first error encountered writing to the stores.

type StoresClient

type StoresClient interface {
	PollFrozen(ctx context.Context, in *PollFrozenRequest, opts ...grpc.CallOption) (*PollFrozenResponse, error)
	Reserve(ctx context.Context, in *ReservationRequest, opts ...grpc.CallOption) (*ReservationResponse, error)
}

func NewStoresClient

func NewStoresClient(cc *grpc.ClientConn) StoresClient

type StoresServer

type StoresServer interface {
	PollFrozen(context.Context, *PollFrozenRequest) (*PollFrozenResponse, error)
	Reserve(context.Context, *ReservationRequest) (*ReservationResponse, error)
}

Directories

Path Synopsis
Package engine provides low-level storage.
Package engine provides low-level storage.
enginepb
Package enginepb is a generated protocol buffer package.
Package enginepb is a generated protocol buffer package.
Package storagebase is a generated protocol buffer package.
Package storagebase is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL