storage

package
v0.0.0-...-69190e3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2017 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Overview

Package storage is a generated protocol buffer package.

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

It has these top-level messages:
	StoreRequestHeader
	PollFrozenRequest
	PollFrozenResponse
	CollectChecksumRequest
	CollectChecksumResponse
	Liveness
	RaftHeartbeat
	RaftMessageRequest
	RaftMessageRequestBatch
	RaftMessageResponseUnion
	RaftMessageResponse
	SnapshotRequest
	SnapshotResponse
	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()

clock := hlc.NewClock(hlc.UnixNano, time.Nanosecond)

// Model a set of stores in a cluster,
// randomly adding / removing stores and adding bytes.
rpcContext := rpc.NewContext(
	log.AmbientContext{},
	&base.Config{Insecure: true},
	clock,
	stopper,
)
server := rpc.NewServer(rpcContext) // never started
g := gossip.NewTest(1, rpcContext, server, nil, stopper, metric.NewRegistry())
// Deterministic must be set as this test is comparing the exact output
// after each rebalance.
sp := NewStorePool(
	log.AmbientContext{},
	g,
	clock,
	newMockNodeLiveness(nodeStatusLive).nodeLivenessFunc,
	TestTimeUntilStoreDeadOff,
	/* deterministic */ true,
)
alloc := MakeAllocator(sp, func(string) (time.Duration, bool) {
	return 0, false
})

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

const generations = 100
const nodes = 20
const printGenerations = generations / 2

// 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))

table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_RIGHT)

header := make([]string, len(testStores)+1)
header[0] = "gen"
for i := 0; i < len(testStores); i++ {
	header[i+1] = fmt.Sprintf("store %d", i)
}
table.SetHeader(header)

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, err := alloc.RebalanceTarget(
			context.Background(),
			config.Constraints{},
			[]roachpb.ReplicaDescriptor{{NodeID: ts.Node.NodeID, StoreID: ts.StoreID}},
			firstRange,
		)
		if err != nil {
			panic(err)
		}
		if target != nil {
			testStores[j].rebalance(&testStores[int(target.StoreID)], alloc.randGen.Int63n(1<<20))
		}
	}

	if i%(generations/printGenerations) == 0 {
		var totalBytes int64
		for j := 0; j < len(testStores); j++ {
			totalBytes += testStores[j].Capacity.Capacity - testStores[j].Capacity.Available
		}
		row := make([]string, len(testStores)+1)
		row[0] = fmt.Sprintf("%d", i)
		for j := 0; j < len(testStores); j++ {
			ts := testStores[j]
			bytes := ts.Capacity.Capacity - ts.Capacity.Available
			row[j+1] = fmt.Sprintf("%3d %3d%%", ts.Capacity.RangeCount, (100*bytes)/totalBytes)
		}
		table.Append(row)
	}
}

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
}
table.Render()
fmt.Printf("Total bytes=%d, ranges=%d\n", totBytes, totRanges)
Output:

+-----+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+
| gen | store 0  | store 1  | store 2  | store 3  | store 4  | store 5  | store 6  | store 7  | store 8  | store 9  | store 10 | store 11 | store 12 | store 13 | store 14 | store 15 | store 16 | store 17 | store 18 | store 19 |
+-----+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+
|   0 |   2 100% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|   2 |   4 100% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|   4 |   6 100% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|   6 |   8 100% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|   8 |  10 100% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|  10 |  10  68% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   1   2% |   0   0% |   0   0% |   1  11% |   0   0% |   1  18% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |   0   0% |
|  12 |  10  21% |   1  10% |   0   0% |   1   1% |   1   3% |   1   5% |   2   7% |   1   9% |   1   7% |   0   0% |   0   0% |   1   7% |   1   5% |   1  10% |   0   0% |   1   2% |   1   4% |   1   4% |   0   0% |   1   0% |
|  14 |  10   8% |   2   5% |   3   5% |   2   1% |   2   3% |   2   4% |   2   4% |   2   5% |   2   7% |   2   5% |   2   4% |   2   7% |   2   7% |   2   5% |   8  10% |   2   0% |   2   2% |   2   4% |   3   4% |   2   0% |
|  16 |  10   5% |   4   4% |   5   4% |   4   1% |   5   6% |   4   5% |   4   4% |   4   4% |   5   7% |   4   4% |   4   4% |   5   9% |   4   5% |   4   5% |   8   4% |   4   2% |   4   4% |   4   5% |   5   3% |   5   5% |
|  18 |  10   2% |   7   6% |   7   4% |   6   2% |   7   5% |   6   5% |   6   4% |   7   6% |   7   6% |   7   5% |   6   5% |   7   7% |   6   4% |   6   5% |   8   3% |   6   2% |   7   5% |   6   5% |   7   3% |   7   6% |
|  20 |  10   0% |   9   5% |   9   5% |   8   3% |   9   5% |   9   6% |   8   4% |   9   6% |   9   6% |   9   6% |   8   4% |   9   7% |   9   5% |   8   5% |  10   2% |   8   3% |   9   4% |   8   5% |   9   3% |   9   6% |
|  22 |  12   1% |  11   4% |  11   5% |  10   3% |  11   5% |  11   5% |  10   4% |  11   6% |  11   6% |  11   6% |  10   4% |  11   6% |  11   6% |  10   5% |  12   2% |  10   3% |  11   4% |  10   5% |  11   4% |  11   6% |
|  24 |  14   1% |  13   4% |  13   6% |  12   3% |  13   5% |  13   5% |  12   3% |  13   6% |  13   6% |  13   6% |  12   4% |  13   6% |  13   6% |  12   5% |  14   3% |  12   3% |  13   4% |  12   5% |  13   3% |  13   6% |
|  26 |  16   2% |  15   4% |  15   6% |  14   3% |  15   4% |  15   5% |  14   3% |  15   6% |  15   5% |  15   7% |  14   4% |  15   6% |  15   6% |  14   4% |  16   4% |  14   3% |  15   4% |  14   5% |  15   4% |  15   5% |
|  28 |  18   2% |  17   4% |  17   6% |  16   3% |  17   5% |  17   5% |  16   3% |  17   5% |  17   5% |  17   7% |  16   4% |  17   5% |  17   6% |  16   4% |  18   4% |  16   3% |  17   5% |  16   5% |  17   4% |  17   5% |
|  30 |  20   2% |  19   4% |  19   5% |  18   3% |  19   5% |  19   5% |  18   3% |  19   5% |  19   5% |  19   6% |  18   4% |  19   5% |  19   6% |  18   4% |  20   4% |  18   3% |  19   4% |  18   5% |  19   4% |  19   5% |
|  32 |  22   2% |  21   5% |  21   5% |  20   3% |  21   5% |  21   5% |  20   3% |  21   5% |  21   5% |  21   6% |  20   4% |  21   6% |  21   6% |  20   4% |  22   4% |  20   3% |  21   4% |  20   5% |  21   4% |  21   5% |
|  34 |  24   3% |  23   5% |  23   5% |  22   3% |  23   5% |  23   5% |  22   3% |  23   5% |  23   5% |  23   5% |  22   4% |  23   6% |  23   6% |  22   4% |  24   4% |  22   3% |  23   4% |  22   5% |  23   4% |  23   6% |
|  36 |  26   3% |  25   5% |  25   5% |  24   3% |  25   5% |  25   5% |  24   3% |  25   5% |  25   5% |  25   5% |  24   4% |  25   6% |  25   6% |  24   4% |  26   4% |  24   4% |  25   4% |  24   5% |  25   4% |  25   6% |
|  38 |  28   3% |  27   5% |  27   4% |  26   4% |  27   5% |  27   5% |  26   3% |  27   4% |  27   5% |  27   5% |  26   4% |  27   6% |  27   6% |  26   4% |  28   3% |  26   4% |  27   5% |  26   5% |  27   4% |  27   6% |
|  40 |  30   3% |  29   5% |  29   4% |  28   4% |  29   5% |  29   6% |  28   4% |  29   4% |  29   5% |  29   5% |  28   4% |  29   6% |  29   6% |  28   4% |  30   3% |  28   4% |  29   5% |  28   5% |  29   4% |  29   6% |
|  42 |  32   3% |  31   5% |  31   4% |  30   4% |  31   5% |  31   5% |  30   4% |  31   4% |  31   4% |  31   5% |  30   4% |  31   5% |  31   5% |  30   4% |  32   3% |  30   4% |  31   4% |  30   5% |  31   4% |  31   6% |
|  44 |  34   4% |  33   5% |  33   4% |  32   4% |  33   5% |  33   6% |  32   4% |  33   4% |  33   4% |  33   5% |  32   4% |  33   5% |  33   6% |  32   4% |  34   3% |  32   4% |  33   4% |  32   5% |  33   4% |  33   5% |
|  46 |  36   4% |  35   5% |  35   4% |  34   4% |  35   5% |  35   6% |  34   4% |  35   4% |  35   4% |  35   5% |  34   4% |  35   5% |  35   5% |  34   4% |  36   4% |  34   4% |  35   4% |  34   5% |  35   4% |  35   5% |
|  48 |  38   4% |  37   5% |  37   5% |  36   4% |  37   5% |  37   5% |  36   4% |  37   5% |  37   4% |  37   5% |  36   4% |  37   5% |  37   5% |  36   4% |  38   4% |  36   4% |  37   5% |  36   5% |  37   4% |  37   5% |
|  50 |  40   4% |  39   5% |  39   5% |  38   4% |  39   5% |  39   5% |  38   4% |  39   5% |  39   4% |  39   5% |  38   4% |  39   5% |  39   5% |  38   4% |  40   4% |  38   4% |  39   5% |  38   5% |  39   4% |  39   5% |
|  52 |  42   4% |  41   5% |  41   5% |  40   4% |  41   5% |  41   5% |  40   4% |  41   5% |  41   4% |  41   5% |  40   4% |  41   5% |  41   5% |  40   4% |  42   4% |  40   4% |  41   5% |  40   5% |  41   4% |  41   5% |
|  54 |  44   4% |  43   5% |  43   4% |  42   5% |  43   4% |  43   5% |  42   4% |  43   5% |  43   4% |  43   5% |  42   4% |  43   5% |  43   5% |  42   4% |  44   4% |  42   4% |  43   5% |  42   5% |  43   4% |  43   5% |
|  56 |  46   4% |  45   5% |  45   4% |  44   4% |  45   4% |  45   5% |  44   4% |  45   5% |  45   4% |  45   5% |  44   4% |  45   5% |  45   5% |  44   4% |  46   4% |  44   4% |  45   5% |  44   5% |  45   4% |  45   5% |
|  58 |  48   4% |  47   5% |  47   5% |  46   4% |  47   4% |  47   5% |  46   4% |  47   5% |  47   4% |  47   5% |  46   4% |  47   5% |  47   5% |  46   4% |  48   4% |  46   4% |  47   5% |  46   5% |  47   4% |  47   5% |
|  60 |  50   4% |  49   5% |  49   4% |  48   4% |  49   4% |  49   5% |  48   4% |  49   5% |  49   4% |  49   5% |  48   4% |  49   5% |  49   5% |  48   4% |  50   4% |  48   4% |  49   5% |  48   5% |  49   4% |  49   5% |
|  62 |  52   4% |  51   5% |  51   4% |  50   4% |  51   4% |  51   5% |  50   4% |  51   5% |  51   4% |  51   5% |  50   4% |  51   5% |  51   5% |  50   4% |  52   4% |  50   4% |  51   5% |  50   5% |  51   4% |  51   5% |
|  64 |  54   4% |  53   5% |  53   4% |  52   4% |  53   4% |  53   5% |  52   4% |  53   5% |  53   4% |  53   5% |  52   4% |  53   5% |  53   5% |  52   4% |  54   4% |  52   4% |  53   5% |  52   5% |  53   4% |  53   5% |
|  66 |  56   4% |  55   5% |  55   4% |  54   4% |  55   4% |  55   5% |  54   4% |  55   5% |  55   4% |  55   5% |  54   4% |  55   5% |  55   5% |  54   4% |  56   4% |  54   4% |  55   4% |  54   5% |  55   4% |  55   5% |
|  68 |  58   4% |  57   5% |  57   4% |  56   5% |  57   4% |  57   5% |  56   4% |  57   5% |  57   4% |  57   5% |  56   4% |  57   5% |  57   5% |  56   4% |  58   4% |  56   4% |  57   4% |  56   5% |  57   4% |  57   5% |
|  70 |  60   4% |  59   5% |  59   4% |  58   4% |  59   4% |  59   5% |  58   4% |  59   5% |  59   4% |  59   5% |  58   4% |  59   5% |  59   5% |  58   4% |  60   4% |  58   4% |  59   4% |  58   5% |  59   4% |  59   5% |
|  72 |  62   4% |  61   5% |  61   4% |  60   4% |  61   4% |  61   5% |  60   4% |  61   5% |  61   4% |  61   5% |  60   4% |  61   5% |  61   5% |  60   4% |  62   4% |  60   4% |  61   4% |  60   5% |  61   4% |  61   5% |
|  74 |  64   4% |  63   5% |  63   4% |  62   4% |  63   4% |  63   5% |  62   4% |  63   5% |  63   4% |  63   5% |  62   4% |  63   5% |  63   5% |  62   4% |  64   4% |  62   4% |  63   4% |  62   5% |  63   4% |  63   5% |
|  76 |  66   4% |  65   5% |  65   4% |  64   4% |  65   4% |  65   5% |  64   4% |  65   5% |  65   4% |  65   5% |  64   4% |  65   5% |  65   5% |  64   4% |  66   4% |  64   5% |  65   4% |  64   5% |  65   4% |  65   5% |
|  78 |  68   4% |  67   5% |  67   4% |  66   4% |  67   5% |  67   5% |  66   4% |  67   5% |  67   4% |  67   5% |  66   4% |  67   5% |  67   5% |  66   4% |  68   4% |  66   5% |  67   4% |  66   5% |  67   4% |  67   5% |
|  80 |  70   4% |  69   5% |  69   4% |  68   4% |  69   5% |  69   5% |  68   4% |  69   4% |  69   4% |  69   5% |  68   4% |  69   5% |  69   5% |  68   4% |  70   4% |  68   5% |  69   4% |  68   5% |  69   4% |  69   5% |
|  82 |  72   4% |  71   4% |  71   4% |  70   4% |  71   5% |  71   5% |  70   4% |  71   4% |  71   4% |  71   5% |  70   4% |  71   5% |  71   5% |  70   4% |  72   4% |  70   5% |  71   4% |  70   5% |  71   4% |  71   5% |
|  84 |  74   4% |  73   4% |  73   4% |  72   4% |  73   5% |  73   5% |  72   4% |  73   4% |  73   4% |  73   5% |  72   5% |  73   5% |  73   5% |  72   4% |  74   4% |  72   5% |  73   4% |  72   5% |  73   4% |  73   5% |
|  86 |  76   4% |  75   5% |  75   4% |  74   4% |  75   5% |  75   5% |  74   4% |  75   4% |  75   4% |  75   5% |  74   5% |  75   5% |  75   5% |  74   4% |  76   4% |  74   5% |  75   4% |  74   5% |  75   4% |  75   5% |
|  88 |  78   4% |  77   5% |  77   4% |  76   4% |  77   5% |  77   5% |  76   4% |  77   4% |  77   4% |  77   5% |  76   5% |  77   5% |  77   5% |  76   4% |  78   4% |  76   5% |  77   4% |  76   5% |  77   4% |  77   5% |
|  90 |  80   4% |  79   5% |  79   4% |  78   4% |  79   4% |  79   5% |  78   4% |  79   4% |  79   4% |  79   5% |  78   5% |  79   5% |  79   5% |  78   4% |  80   4% |  78   5% |  79   4% |  78   5% |  79   4% |  79   5% |
|  92 |  82   4% |  81   5% |  81   4% |  80   4% |  81   4% |  81   5% |  80   4% |  81   4% |  81   4% |  81   5% |  80   5% |  81   5% |  81   5% |  80   4% |  82   4% |  80   5% |  81   4% |  80   5% |  81   4% |  81   5% |
|  94 |  84   4% |  83   4% |  83   4% |  82   4% |  83   4% |  83   5% |  82   4% |  83   4% |  83   4% |  83   5% |  82   5% |  83   5% |  83   5% |  82   4% |  84   4% |  82   5% |  83   4% |  82   5% |  83   4% |  83   5% |
|  96 |  86   4% |  85   4% |  85   4% |  84   4% |  85   4% |  85   5% |  84   4% |  85   4% |  85   4% |  85   5% |  84   5% |  85   5% |  85   5% |  84   4% |  86   4% |  84   5% |  85   4% |  84   5% |  85   4% |  85   5% |
|  98 |  88   4% |  87   4% |  87   4% |  86   4% |  87   4% |  87   5% |  86   4% |  87   4% |  87   4% |  87   5% |  86   5% |  87   5% |  87   5% |  86   4% |  88   4% |  86   5% |  87   4% |  86   5% |  87   4% |  87   5% |
+-----+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+----------+
Total bytes=915941810, ranges=1756

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 (
	// 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
)
View Source
const (
	// TimeSeriesMaintenanceInterval is the minimum interval between two
	// time series maintenance runs on a replica.
	TimeSeriesMaintenanceInterval = 24 * time.Hour // daily
)

Variables

View Source
var (
	// MinLeaseTransferStatsDuration configures the minimum amount of time a
	// replica must wait for stats about request counts to accumulate before
	// making decisions based on them.
	// Made configurable for the sake of testing.
	MinLeaseTransferStatsDuration = time.Minute

	// EnableLoadBasedLeaseRebalancing controls whether lease rebalancing is done
	// via the new heuristic based on request load and latency or via the simpler
	// approach that purely seeks to balance the number of leases per node evenly.
	EnableLoadBasedLeaseRebalancing = envutil.EnvOrDefaultBool("COCKROACH_ENABLE_LOAD_BASED_LEASE_REBALANCING", false)

	// LeaseRebalancingAggressiveness enables users to tweak how aggressive their
	// cluster is at moving leases towards the localities where the most requests
	// are coming from. Settings lower than 1.0 will make the system less
	// aggressive about moving leases toward requests than the default, while
	// settings greater than 1.0 will cause more aggressive placement.
	//
	// Setting this to 0 effectively disables load-based lease rebalancing, and
	// settings less than 0 are disallowed.
	LeaseRebalancingAggressiveness = envutil.EnvOrDefaultFloat("COCKROACH_LEASE_REBALANCING_AGGRESSIVENESS", 1.0)
)
View Source
var (
	ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowApi   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	ErrInvalidLengthLiveness = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowLiveness   = 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 (
	// ErrNoLivenessRecord is returned when asking for liveness information
	// about a node for which nothing is known.
	ErrNoLivenessRecord = errors.New("node not in the liveness table")
)
View Source
var SnapshotResponse_Status_name = map[int32]string{
	0: "UNKNOWN",
	1: "ACCEPTED",
	2: "APPLIED",
	3: "ERROR",
	4: "DECLINED",
}
View Source
var SnapshotResponse_Status_value = map[string]int32{
	"UNKNOWN":  0,
	"ACCEPTED": 1,
	"APPLIED":  2,
	"ERROR":    3,
	"DECLINED": 4,
}

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) (storagebase.CmdIDKey, []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 DefaultDeclareKeys

func DefaultDeclareKeys(header roachpb.Header, req roachpb.Request, spans *SpanSet)

DefaultDeclareKeys is the default implementation of Command.DeclareKeys

func IsSnapshotError

func IsSnapshotError(err error) bool

IsSnapshotError returns true iff the error indicates a preemptive snapshot failed.

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 NodeLivenessDurations

func NodeLivenessDurations(
	raftElectionTimeout time.Duration,
) (livenessActive time.Duration, livenessRenewal time.Duration)

NodeLivenessDurations computes durations for node liveness expiration and renewal based on a default multiple of Raft election timeout.

func ProposerEvaluatedKVEnabled

func ProposerEvaluatedKVEnabled() bool

ProposerEvaluatedKVEnabled returns whether experimental support for proposer-evaluated KV is enabled.

func RaftElectionTimeout

func RaftElectionTimeout(
	raftTickInterval time.Duration, raftElectionTimeoutTicks int,
) time.Duration

RaftElectionTimeout returns the raft election timeout, as computed from the specified tick interval and number of election timeout ticks. If raftElectionTimeoutTicks is 0, uses the value of defaultRaftElectionTimeoutTicks.

func RangeLeaseDurations

func RangeLeaseDurations(
	raftElectionTimeout time.Duration,
) (rangeLeaseActive time.Duration, rangeLeaseRenewal time.Duration)

RangeLeaseDurations computes durations for range lease expiration and renewal based on a default multiple of Raft election timeout.

func ReadStoreIdent

func ReadStoreIdent(ctx context.Context, eng engine.Engine) (roachpb.StoreIdent, error)

ReadStoreIdent reads the StoreIdent from the store. It returns *NotBootstrappedError if the ident is missing (meaning that the store needs to be bootstrapped).

func RegisterConsistencyServer

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

func RegisterFreezeServer

func RegisterFreezeServer(s *grpc.Server, srv FreezeServer)

func RegisterMultiRaftServer

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

func SetExportCmd

func SetExportCmd(cmd Command)

SetExportCmd allows setting the function that will be called as the implementation of the Export command. Only allowed to be called by Init.

func SetImportCmd

func SetImportCmd(fn ImportCmdFunc)

SetImportCmd allows setting the function that will be called as the implementation of the Import command. Only allowed to be called by Init.

func SetWriteBatchCmd

func SetWriteBatchCmd(cmd Command)

SetWriteBatchCmd allows setting the function that will be called as the implementation of the WriteBatch command. Only allowed to be called by Init.

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 cache is range-specific. It is updated when an intent for an aborted txn is cleared from a range, and is consulted before read commands are processed on a range.

The AbortCache stores responses in the underlying engine, using keys derived from Range ID and txn ID. Note that the epoch number is not used to query the cache: once aborted, even higher epochs are prohibited from reading data. That's because, for better or worse, the intent resolution process clears intents even from epochs higher than the txn meta used for clearing (see engine.MVCCResolveWriteIntent), and this clearing can race with the new epoch laying intents.

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, 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, nodeLatencyFn func(addr string) (time.Duration, bool),
) Allocator

MakeAllocator creates a new allocator using the specified StorePool.

func (*Allocator) AllocateTarget

func (a *Allocator) AllocateTarget(
	ctx context.Context,
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	rangeID roachpb.RangeID,
	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. The range ID of the replica being allocated for is also passed in to ensure that we don't try to replace an existing dead replica on a store. 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(
	ctx context.Context, 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 priority.

func (Allocator) RebalanceTarget

func (a Allocator) RebalanceTarget(
	ctx context.Context,
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	rangeID roachpb.RangeID,
) (*roachpb.StoreDescriptor, error)

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 range ID of the replica being allocated.

The existing replicas modulo any store with dead replicas 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(
	ctx context.Context, constraints config.Constraints, existing []roachpb.ReplicaDescriptor,
) (roachpb.ReplicaDescriptor, error)

RemoveTarget returns a suitable replica to remove from the provided replica set. It first attempts to randomly select a target from the set of stores that have greater than the average number of replicas. Failing that, it falls back to selecting a random target from any of the existing replicas.

func (*Allocator) ShouldTransferLease

func (a *Allocator) ShouldTransferLease(
	ctx context.Context,
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	leaseStoreID roachpb.StoreID,
	rangeID roachpb.RangeID,
	stats *replicaStats,
) bool

ShouldTransferLease returns true if the specified store is overfull in terms of leases with respect to the other stores matching the specified attributes.

func (*Allocator) TransferLeaseTarget

func (a *Allocator) TransferLeaseTarget(
	ctx context.Context,
	constraints config.Constraints,
	existing []roachpb.ReplicaDescriptor,
	leaseStoreID roachpb.StoreID,
	rangeID roachpb.RangeID,
	stats *replicaStats,
	checkTransferLeaseSource bool,
	checkCandidateFullness bool,
) roachpb.ReplicaDescriptor

TransferLeaseTarget returns a suitable replica to transfer the range lease to from the provided list. It excludes the current lease holder replica unless asked to do otherwise by the checkTransferLeaseSource parameter.

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.

func (AllocatorAction) String

func (a AllocatorAction) String() string

type CollectChecksumRequest

type CollectChecksumRequest struct {
	StoreRequestHeader `protobuf:"bytes,1,opt,name=header,embedded=header" json:"header"`
	RangeID            github_com_cockroachdb_cockroach_pkg_roachpb.RangeID `` /* 145-byte string literal not displayed */
	// checksum_id identifies the corresponding roachpb.ComputeChecksumRequest.
	ChecksumID github_com_cockroachdb_cockroach_pkg_util_uuid.UUID `` /* 144-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 Command

type Command struct {
	// DeclareKeys adds all keys this command touches to the given spanSet.
	DeclareKeys func(roachpb.Header, roachpb.Request, *SpanSet)

	// Eval evaluates a command on the given engine. It should populate
	// the supplied response (always a non-nil pointer to the correct
	// type) and return special side effects (if any) in the EvalResult.
	// If it writes to the engine it should also update
	// *CommandArgs.Stats.
	Eval func(context.Context, engine.ReadWriter, CommandArgs, roachpb.Response) (EvalResult, error)
}

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

type CommandArgs

type CommandArgs struct {
	Repl   *Replica
	Header roachpb.Header
	Args   roachpb.Request

	// If MaxKeys is non-zero, span requests should limit themselves to
	// that many keys. Commands using this feature should also set
	// NumKeys and ResumeSpan in their responses.
	MaxKeys int64

	// *Stats should be mutated to reflect any writes made by the command.
	Stats *enginepb.MVCCStats
}

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

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(coveringOptimization bool) *CommandQueue

NewCommandQueue returns a new command queue. The boolean specifies whether to enable the covering span optimization. With this optimization, whenever a command consisting of multiple spans is added, a covering span is computed and only that covering span inserted. The individual spans are inserted (i.e. the covering span expanded) only when required by a later overlapping command, the hope being that that occurs infrequently, and that in the common case savings are made due to the reduced number of spans active in the tree. As such, the optimization makes sense for workloads in which commands typically contain many spans, but are spatially disjoint.

func (*CommandQueue) String

func (cq *CommandQueue) String() string

String dumps the contents of the command queue for testing.

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
	// storagebase.RaftCommand).
	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 EvalResult

type EvalResult struct {
	Local      LocalEvalResult
	Replicated storagebase.ReplicatedEvalResult
	WriteBatch *storagebase.WriteBatch
}

EvalResult is the result of evaluating a KV request. That is, the proposer (which holds the lease, at least in the case in which the command will complete successfully) has evaluated the request and is holding on to:

a) changes to be written to disk when applying the command b) changes to the state which may require special handling (i.e. code

execution) on all Replicas

c) data which isn't sent to the followers but the proposer needs for tasks

it must run when the command has applied (such as resolving intents).

func (*EvalResult) MergeAndDestroy

func (p *EvalResult) MergeAndDestroy(q EvalResult) error

MergeAndDestroy absorbs the supplied EvalResult while validating that the resulting EvalResult makes sense. For example, it is forbidden to absorb two lease updates or log truncations, or multiple splits and/or merges.

The passed EvalResult must not be used once passed to Merge.

type FreezeClient

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

func NewFreezeClient

func NewFreezeClient(cc *grpc.ClientConn) FreezeClient

type FreezeServer

type FreezeServer interface {
	PollFrozen(context.Context, *PollFrozenRequest) (*PollFrozenResponse, 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.
	NumKeysAffected, IntentsConsidered, IntentTxns int
	// TransactionSpanTotal is the total number of entries in the transaction span.
	TransactionSpanTotal int
	// Summary of transactions which were found GCable (assuming that
	// potentially necessary intent resolutions did not fail).
	TransactionSpanGCAborted, TransactionSpanGCCommitted, 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 HeartbeatCallback

type HeartbeatCallback func(context.Context) error

HeartbeatCallback is invoked whenever this node updates its own liveness status, indicating that it is alive.

type ImportCmdFunc

type ImportCmdFunc func(context.Context, CommandArgs) error

ImportCmdFunc is the type of the function that will be called as the implementation of the Import command.

type IncomingSnapshot

type IncomingSnapshot struct {
	SnapUUID uuid.UUID
	// The RocksDB BatchReprs that make up this snapshot.
	Batches [][]byte
	// The Raft log entries for this snapshot.
	LogEntries [][]byte
	// The replica state at the time the snapshot was generated (never nil).
	State *storagebase.ReplicaState
	// contains filtered or unexported fields
}

IncomingSnapshot contains the data for an incoming streaming snapshot message.

type IsLiveCallback

type IsLiveCallback func(nodeID roachpb.NodeID)

IsLiveCallback is invoked when a node's IsLive state changes to true. Callbacks can be registered via NodeLiveness.RegisterCallback().

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 LeaseStatus

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

LeaseStatus holds the lease state, the timestamp at which the state is accurate, the lease and optionally the liveness if the lease is epoch-based.

type Liveness

type Liveness struct {
	NodeID github_com_cockroachdb_cockroach_pkg_roachpb.NodeID `` /* 141-byte string literal not displayed */
	// Epoch is a monotonically-increasing value for node liveness. It
	// may be incremented if the liveness record expires (current time
	// is later than the expiration timestamp).
	Epoch int64 `protobuf:"varint,2,opt,name=epoch,proto3" json:"epoch,omitempty"`
	// The timestamp at which this liveness record expires.
	Expiration cockroach_util_hlc.Timestamp `protobuf:"bytes,3,opt,name=expiration" json:"expiration"`
	Draining   bool                         `protobuf:"varint,4,opt,name=draining,proto3" json:"draining,omitempty"`
}

Liveness holds information about a node's latest heartbeat and epoch.

func (*Liveness) Descriptor

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

func (*Liveness) Marshal

func (m *Liveness) Marshal() (dAtA []byte, err error)

func (*Liveness) MarshalTo

func (m *Liveness) MarshalTo(dAtA []byte) (int, error)

func (*Liveness) ProtoMessage

func (*Liveness) ProtoMessage()

func (*Liveness) Reset

func (m *Liveness) Reset()

func (*Liveness) Size

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

func (*Liveness) String

func (m *Liveness) String() string

func (*Liveness) Unmarshal

func (m *Liveness) Unmarshal(dAtA []byte) error

type LivenessMetrics

type LivenessMetrics struct {
	LiveNodes          *metric.Gauge
	HeartbeatSuccesses *metric.Counter
	HeartbeatFailures  *metric.Counter
	EpochIncrements    *metric.Counter
}

LivenessMetrics holds metrics for use with node liveness activity.

type LocalEvalResult

type LocalEvalResult struct {
	// The error resulting from the proposal. Most failing proposals will
	// fail-fast, i.e. will return an error to the client above Raft. However,
	// some proposals need to commit data even on error, and in that case we
	// treat the proposal like a successful one, except that the error stored
	// here will be sent to the client when the associated batch commits. In
	// the common case, this field is nil.
	Err   *roachpb.Error
	Reply *roachpb.BatchResponse
	// contains filtered or unexported fields
}

LocalEvalResult is data belonging to an evaluated command that is only used on the node on which the command was proposed. Note that the proposing node may die before the local results are processed, so any side effects here are only best-effort.

TODO(tschottdorf): once the WriteBatch is available in the replicated proposal data (i.e. once we really do proposer-evaluted KV), experiment with holding on to the proposer's constructed engine.Batch in this struct, which could give a performance gain.

type MultiRaftClient

type MultiRaftClient interface {
	RaftMessageBatch(ctx context.Context, opts ...grpc.CallOption) (MultiRaft_RaftMessageBatchClient, error)
	RaftSnapshot(ctx context.Context, opts ...grpc.CallOption) (MultiRaft_RaftSnapshotClient, error)
}

func NewMultiRaftClient

func NewMultiRaftClient(cc *grpc.ClientConn) MultiRaftClient

type MultiRaftServer

type MultiRaftServer interface {
	RaftMessageBatch(MultiRaft_RaftMessageBatchServer) error
	RaftSnapshot(MultiRaft_RaftSnapshotServer) error
}

type MultiRaft_RaftMessageBatchClient

type MultiRaft_RaftMessageBatchClient interface {
	Send(*RaftMessageRequestBatch) error
	Recv() (*RaftMessageResponse, error)
	grpc.ClientStream
}

type MultiRaft_RaftMessageBatchServer

type MultiRaft_RaftMessageBatchServer interface {
	Send(*RaftMessageResponse) error
	Recv() (*RaftMessageRequestBatch, error)
	grpc.ServerStream
}

type MultiRaft_RaftSnapshotClient

type MultiRaft_RaftSnapshotClient interface {
	Send(*SnapshotRequest) error
	Recv() (*SnapshotResponse, error)
	grpc.ClientStream
}

type MultiRaft_RaftSnapshotServer

type MultiRaft_RaftSnapshotServer interface {
	Send(*SnapshotResponse) error
	Recv() (*SnapshotRequest, 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 NodeLiveness

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

NodeLiveness encapsulates information on node liveness and provides an API for querying, updating, and invalidating node liveness. Nodes periodically "heartbeat" the range holding the node liveness system table to indicate that they're available. The resulting liveness information is used to ignore unresponsive nodes while making range quiescense decisions, as well as for efficient, node liveness epoch-based range leases.

func NewNodeLiveness

func NewNodeLiveness(
	ambient log.AmbientContext,
	clock *hlc.Clock,
	db *client.DB,
	g *gossip.Gossip,
	livenessThreshold time.Duration,
	renewalDuration time.Duration,
) *NodeLiveness

NewNodeLiveness returns a new instance of NodeLiveness configured with the specified gossip instance.

func (*NodeLiveness) GetIsLiveMap

func (nl *NodeLiveness) GetIsLiveMap() map[roachpb.NodeID]bool

GetIsLiveMap returns a map of nodeID to boolean liveness status of each node.

func (*NodeLiveness) GetLiveness

func (nl *NodeLiveness) GetLiveness(nodeID roachpb.NodeID) (*Liveness, error)

GetLiveness returns the liveness record for the specified nodeID. ErrNoLivenessRecord is returned in the event that nothing is yet known about nodeID via liveness gossip.

func (*NodeLiveness) GetLivenessThreshold

func (nl *NodeLiveness) GetLivenessThreshold() time.Duration

GetLivenessThreshold returns the maximum duration between heartbeats before a node is considered not-live.

func (*NodeLiveness) GetLivenesses

func (nl *NodeLiveness) GetLivenesses() []Liveness

GetLivenesses returns a slice containing the liveness status of every node on the cluster.

func (*NodeLiveness) Heartbeat

func (nl *NodeLiveness) Heartbeat(ctx context.Context, liveness *Liveness) error

Heartbeat is called to update a node's expiration timestamp. This method does a conditional put on the node liveness record, and if successful, stores the updated liveness record in the nodes map.

func (*NodeLiveness) IncrementEpoch

func (nl *NodeLiveness) IncrementEpoch(ctx context.Context, liveness *Liveness) error

IncrementEpoch is called to increment the current liveness epoch, thereby invalidating anything relying on the liveness of the previous epoch. This method does a conditional put on the node liveness record, and if successful, stores the updated liveness record in the nodes map. If this method is called on a node ID which is considered live according to the most recent information gathered through gossip, an error is returned.

func (*NodeLiveness) IsLive

func (nl *NodeLiveness) IsLive(nodeID roachpb.NodeID) (bool, error)

IsLive returns whether or not the specified node is considered live based on the last receipt of a liveness update via gossip. It is an error if the specified node is not in the local liveness table.

func (*NodeLiveness) Metrics

func (nl *NodeLiveness) Metrics() LivenessMetrics

Metrics returns a struct which contains metrics related to node liveness activity.

func (*NodeLiveness) PauseHeartbeat

func (nl *NodeLiveness) PauseHeartbeat(pause bool)

PauseHeartbeat stops or restarts the periodic heartbeat depending on the pause parameter.

func (*NodeLiveness) RegisterCallback

func (nl *NodeLiveness) RegisterCallback(cb IsLiveCallback)

RegisterCallback registers a callback to be invoked any time a node's IsLive() state changes to true.

func (*NodeLiveness) Self

func (nl *NodeLiveness) Self() (*Liveness, error)

Self returns the liveness record for this node. ErrNoLivenessRecord is returned in the event that the node has neither heartbeat its liveness record successfully, nor received a gossip message containing a former liveness update on restart.

func (*NodeLiveness) SetDraining

func (nl *NodeLiveness) SetDraining(ctx context.Context, drain bool)

SetDraining calls PauseHeartbeat with the given boolean and then attempts to update the liveness record.

func (*NodeLiveness) StartHeartbeat

func (nl *NodeLiveness) StartHeartbeat(
	ctx context.Context, stopper *stop.Stopper, alive HeartbeatCallback,
)

StartHeartbeat starts a periodic heartbeat to refresh this node's last heartbeat in the node liveness table. The optionally provided HeartbeatCallback will be invoked whenever this node updates its own liveness.

type NodeLivenessFunc

type NodeLivenessFunc func(roachpb.NodeID, time.Time, time.Duration) nodeStatus

A NodeLivenessFunc accepts a node ID, current time and threshold before a node is considered dead and returns whether or not the node is live.

func MakeStorePoolNodeLivenessFunc

func MakeStorePoolNodeLivenessFunc(nodeLiveness *NodeLiveness) NodeLivenessFunc

MakeStorePoolNodeLivenessFunc returns a function which determines the status of a node based on information provided by the specified NodeLiveness.

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 OutgoingSnapshot

type OutgoingSnapshot struct {
	SnapUUID uuid.UUID
	// The Raft snapshot message to send. Contains SnapUUID as its data.
	RaftSnap raftpb.Snapshot
	// The RocksDB snapshot that will be streamed from.
	EngineSnap engine.Reader
	// The complete range iterator for the snapshot to stream.
	Iter *ReplicaDataIterator
	// The replica state within the snapshot.
	State storagebase.ReplicaState
}

OutgoingSnapshot contains the data required to stream a snapshot to a recipient. Once one is created, it needs to be closed via Close() to prevent resource leakage.

func (*OutgoingSnapshot) Close

func (s *OutgoingSnapshot) Close()

Close releases the resources associated with the snapshot.

type OutgoingSnapshotStream

type OutgoingSnapshotStream interface {
	Send(*SnapshotRequest) error
	Recv() (*SnapshotResponse, error)
}

OutgoingSnapshotStream is the minimal interface on a GRPC stream required to send a snapshot over the network.

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 ProposalData

type ProposalData struct {

	// Local contains the results of evaluating the request in
	// propEvalKV, tying the upstream evaluation of the request to the
	// downstream application of the command. If propEvalKV is false,
	// Local is nil.
	Local *LocalEvalResult

	// Request is the client's original BatchRequest.
	// TODO(tschottdorf): tests which use TestingCommandFilter use this.
	// Decide how that will work in the future, presumably the
	// CommandFilter would run at proposal time or we allow an opaque
	// struct to be attached to a proposal which is then available as it
	// applies. Other than tests, we only need a few bits of the request
	// here; this could be replaced with isLease and isChangeReplicas
	// booleans.
	Request *roachpb.BatchRequest
	// contains filtered or unexported fields
}

ProposalData is data about a command which allows it to be evaluated, proposed to raft, and for the result of the command to be returned to the caller.

type RaftHeartbeat

type RaftHeartbeat struct {
	RangeID       github_com_cockroachdb_cockroach_pkg_roachpb.RangeID   `` /* 128-byte string literal not displayed */
	FromReplicaID github_com_cockroachdb_cockroach_pkg_roachpb.ReplicaID `` /* 150-byte string literal not displayed */
	ToReplicaID   github_com_cockroachdb_cockroach_pkg_roachpb.ReplicaID `` /* 144-byte string literal not displayed */
	Term          uint64                                                 `protobuf:"varint,4,opt,name=term" json:"term"`
	Commit        uint64                                                 `protobuf:"varint,5,opt,name=commit" json:"commit"`
	Quiesce       bool                                                   `protobuf:"varint,6,opt,name=quiesce" json:"quiesce"`
}

RaftHeartbeat is a request that contains the barebones information for a raftpb.MsgHeartbeat raftpb.Message. RaftHeartbeats are coalesced and sent in a RaftMessageRequest, and reconstructed by the receiver into individual raftpb.Message protos.

func (*RaftHeartbeat) Descriptor

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

func (*RaftHeartbeat) Marshal

func (m *RaftHeartbeat) Marshal() (dAtA []byte, err error)

func (*RaftHeartbeat) MarshalTo

func (m *RaftHeartbeat) MarshalTo(dAtA []byte) (int, error)

func (*RaftHeartbeat) ProtoMessage

func (*RaftHeartbeat) ProtoMessage()

func (*RaftHeartbeat) Reset

func (m *RaftHeartbeat) Reset()

func (*RaftHeartbeat) Size

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

func (*RaftHeartbeat) String

func (m *RaftHeartbeat) String() string

func (*RaftHeartbeat) Unmarshal

func (m *RaftHeartbeat) Unmarshal(dAtA []byte) error

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. An error is returned if and only if
	// the underlying Raft connection should be closed.
	HandleRaftResponse(context.Context, *RaftMessageResponse) error

	// HandleSnapshot is called for each new incoming snapshot stream, after
	// parsing the initial SnapshotRequest_Header on the stream.
	HandleSnapshot(header *SnapshotRequest_Header, respStream SnapshotResponseStream) error
}

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

type RaftMessageRequest

type RaftMessageRequest struct {
	RangeID     github_com_cockroachdb_cockroach_pkg_roachpb.RangeID `` /* 128-byte string literal not displayed */
	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"`
	// A coalesced heartbeat request is any RaftMessageRequest with a nonzero number of
	// heartbeats or heartbeat_resps.
	Heartbeats     []RaftHeartbeat `protobuf:"bytes,6,rep,name=heartbeats" json:"heartbeats"`
	HeartbeatResps []RaftHeartbeat `protobuf:"bytes,7,rep,name=heartbeat_resps,json=heartbeatResps" json:"heartbeat_resps"`
}

RaftMessageRequest is the request used to send raft messages using our protobuf-based RPC codec. If a RaftMessageRequest has a non-empty number of heartbeats or heartbeat_resps, the contents of the message field is treated as a dummy message and discarded. A coalesced heartbeat request's replica descriptor's range ID must be zero.

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 RaftMessageRequestBatch

type RaftMessageRequestBatch struct {
	Requests []RaftMessageRequest `protobuf:"bytes,1,rep,name=requests" json:"requests"`
}

func (*RaftMessageRequestBatch) Descriptor

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

func (*RaftMessageRequestBatch) Marshal

func (m *RaftMessageRequestBatch) Marshal() (dAtA []byte, err error)

func (*RaftMessageRequestBatch) MarshalTo

func (m *RaftMessageRequestBatch) MarshalTo(dAtA []byte) (int, error)

func (*RaftMessageRequestBatch) ProtoMessage

func (*RaftMessageRequestBatch) ProtoMessage()

func (*RaftMessageRequestBatch) Reset

func (m *RaftMessageRequestBatch) Reset()

func (*RaftMessageRequestBatch) Size

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

func (*RaftMessageRequestBatch) String

func (m *RaftMessageRequestBatch) String() string

func (*RaftMessageRequestBatch) Unmarshal

func (m *RaftMessageRequestBatch) Unmarshal(dAtA []byte) error

type RaftMessageResponse

type RaftMessageResponse struct {
	RangeID     github_com_cockroachdb_cockroach_pkg_roachpb.RangeID `` /* 128-byte string literal not displayed */
	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 the 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 RaftTransport

type RaftTransport struct {
	log.AmbientContext
	// 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(
	ambient log.AmbientContext,
	resolver NodeAddressResolver,
	grpcServer *grpc.Server,
	rpcContext *rpc.Context,
) *RaftTransport

NewRaftTransport creates a new RaftTransport.

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) RaftMessageBatch

func (t *RaftTransport) RaftMessageBatch(stream MultiRaft_RaftMessageBatchServer) error

RaftMessageBatch proxies the incoming requests to the listening server interface.

func (*RaftTransport) RaftSnapshot

func (t *RaftTransport) RaftSnapshot(stream MultiRaft_RaftSnapshotServer) error

RaftSnapshot handles incoming streaming snapshot requests.

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) SendSnapshot

func (t *RaftTransport) SendSnapshot(
	ctx context.Context,
	storePool *StorePool,
	header SnapshotRequest_Header,
	snap *OutgoingSnapshot,
	newBatch func() engine.Batch,
	sent func(),
) error

SendSnapshot streams the given outgoing snapshot. The caller is responsible for closing the OutgoingSnapshot.

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 {
	log.AmbientContext

	// 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 args.SplitKey.

func (*Replica) AdminTransferLease

func (r *Replica) AdminTransferLease(ctx context.Context, target roachpb.StoreID) error

AdminTransferLease transfers the LeaderLease to another replica. A valid LeaseStatus must be supplied. 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 IsLeaseValid). 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 NotLeaseHolderError is returned.

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 "adminSplitWithDescriptor" 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.

TODO(tschottdorf): We should call this AdminCheckConsistency.

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) DB

func (r *Replica) DB() *client.DB

DB returns the Replica's client.DB.

func (*Replica) Desc

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

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

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) GCThreshold

func (r *Replica) GCThreshold() hlc.Timestamp

GCThreshold returns the GC threshold of the Range, typically updated when keys are garbage collected. Reads and writes at timestamps <= this time will not be served.

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, snapType string) (*OutgoingSnapshot, error)

GetSnapshot returns a snapshot of the replica appropriate for sending to a replica. If this method returns without error, callers must eventually call OutgoingSnapshot.Close.

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) IsDestroyed

func (r *Replica) IsDestroyed() error

IsDestroyed returns a non-nil error if the replica has been destroyed.

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) IsLeaseValid

func (r *Replica) IsLeaseValid(lease *roachpb.Lease, ts hlc.Timestamp) bool

IsLeaseValid returns true if the replica's lease is owned by this replica and is valid (not expired, not in stasis).

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) Less

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

Less implements the btree.Item interface.

func (*Replica) NodeID

func (r *Replica) NodeID() roachpb.NodeID

NodeID returns the ID of the node this replica belongs to.

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) 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. Note that the returned snapshot is a placeholder and does not contain any of the replica data. The snapshot is actually generated (and sent) by the Raft snapshot queue.

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.

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 ReplicaGCQueueMetrics

type ReplicaGCQueueMetrics struct {
	RemoveReplicaCount *metric.Counter
}

ReplicaGCQueueMetrics is the set of metrics for the replica GC queue.

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 ReplicaSnapshotDiffSlice

type ReplicaSnapshotDiffSlice []ReplicaSnapshotDiff

ReplicaSnapshotDiffSlice groups multiple ReplicaSnapshotDiff records and exposes a formatting helper.

func (ReplicaSnapshotDiffSlice) String

func (rsds ReplicaSnapshotDiffSlice) String() string

func (ReplicaSnapshotDiffSlice) WriteTo

func (rsds ReplicaSnapshotDiffSlice) WriteTo(w io.Writer) (int64, error)

WriteTo writes a string representation of itself to the given writer.

type ReplicateQueueMetrics

type ReplicateQueueMetrics struct {
	AddReplicaCount        *metric.Counter
	RemoveReplicaCount     *metric.Counter
	RemoveDeadReplicaCount *metric.Counter
	RebalanceReplicaCount  *metric.Counter
	TransferLeaseCount     *metric.Counter
}

ReplicateQueueMetrics is the set of metrics for the replicate queue.

type Server

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

Server implements FreezeServer and ConsistencyServer.

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 FreezeServer interface.

type SnapshotRequest

type SnapshotRequest struct {
	Header *SnapshotRequest_Header `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"`
	// A RocksDB BatchRepr. Multiple kv_batches may be sent across multiple request messages.
	KVBatch []byte `protobuf:"bytes,2,opt,name=kv_batch,json=kvBatch" json:"kv_batch,omitempty"`
	// These are really raftpb.Entry, but we model them as raw bytes to avoid
	// roundtripping through memory. They are separate from the kv_batch to
	// allow flexibility in log implementations.
	LogEntries [][]byte `protobuf:"bytes,3,rep,name=log_entries,json=logEntries" json:"log_entries,omitempty"`
	Final      bool     `protobuf:"varint,4,opt,name=final" json:"final"`
}

SnapshotRequest is the request used to send streaming snapshot requests.

func (*SnapshotRequest) Descriptor

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

func (*SnapshotRequest) Marshal

func (m *SnapshotRequest) Marshal() (dAtA []byte, err error)

func (*SnapshotRequest) MarshalTo

func (m *SnapshotRequest) MarshalTo(dAtA []byte) (int, error)

func (*SnapshotRequest) ProtoMessage

func (*SnapshotRequest) ProtoMessage()

func (*SnapshotRequest) Reset

func (m *SnapshotRequest) Reset()

func (*SnapshotRequest) Size

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

func (*SnapshotRequest) String

func (m *SnapshotRequest) String() string

func (*SnapshotRequest) Unmarshal

func (m *SnapshotRequest) Unmarshal(dAtA []byte) error

type SnapshotRequest_Header

type SnapshotRequest_Header struct {
	// The replica state at the time the snapshot was generated. Note
	// that ReplicaState.Desc differs from the above range_descriptor
	// field which holds the updated descriptor after the new replica
	// has been added while ReplicaState.Desc holds the descriptor
	// before the new replica has been added.
	State cockroach_storage_storagebase.ReplicaState `protobuf:"bytes,5,opt,name=state" json:"state"`
	// The inner raft message is of type MsgSnap, and its snapshot data contains a UUID.
	RaftMessageRequest RaftMessageRequest `protobuf:"bytes,2,opt,name=raft_message_request,json=raftMessageRequest" json:"raft_message_request"`
	// The estimated size of the range, to be used in reservation decisions.
	RangeSize int64 `protobuf:"varint,3,opt,name=range_size,json=rangeSize" json:"range_size"`
	// can_decline is set on preemptive snapshots, but not those generated
	// by raft because at that point it is better to queue up the stream
	// than to cancel it.
	CanDecline bool `protobuf:"varint,4,opt,name=can_decline,json=canDecline" json:"can_decline"`
}

func (*SnapshotRequest_Header) Descriptor

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

func (*SnapshotRequest_Header) Marshal

func (m *SnapshotRequest_Header) Marshal() (dAtA []byte, err error)

func (*SnapshotRequest_Header) MarshalTo

func (m *SnapshotRequest_Header) MarshalTo(dAtA []byte) (int, error)

func (*SnapshotRequest_Header) ProtoMessage

func (*SnapshotRequest_Header) ProtoMessage()

func (*SnapshotRequest_Header) Reset

func (m *SnapshotRequest_Header) Reset()

func (*SnapshotRequest_Header) Size

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

func (*SnapshotRequest_Header) String

func (m *SnapshotRequest_Header) String() string

func (*SnapshotRequest_Header) Unmarshal

func (m *SnapshotRequest_Header) Unmarshal(dAtA []byte) error

type SnapshotResponse

type SnapshotResponse struct {
	Status  SnapshotResponse_Status `protobuf:"varint,1,opt,name=status,enum=cockroach.storage.SnapshotResponse_Status" json:"status"`
	Message string                  `protobuf:"bytes,2,opt,name=message" json:"message"`
}

func (*SnapshotResponse) Descriptor

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

func (*SnapshotResponse) Marshal

func (m *SnapshotResponse) Marshal() (dAtA []byte, err error)

func (*SnapshotResponse) MarshalTo

func (m *SnapshotResponse) MarshalTo(dAtA []byte) (int, error)

func (*SnapshotResponse) ProtoMessage

func (*SnapshotResponse) ProtoMessage()

func (*SnapshotResponse) Reset

func (m *SnapshotResponse) Reset()

func (*SnapshotResponse) Size

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

func (*SnapshotResponse) String

func (m *SnapshotResponse) String() string

func (*SnapshotResponse) Unmarshal

func (m *SnapshotResponse) Unmarshal(dAtA []byte) error

type SnapshotResponseStream

type SnapshotResponseStream interface {
	Context() context.Context
	Send(*SnapshotResponse) error
	Recv() (*SnapshotRequest, error)
}

SnapshotResponseStream is the subset of the MultiRaft_RaftSnapshotServer interface that is needed for sending responses.

type SnapshotResponse_Status

type SnapshotResponse_Status int32
const (
	SnapshotResponse_UNKNOWN  SnapshotResponse_Status = 0
	SnapshotResponse_ACCEPTED SnapshotResponse_Status = 1
	SnapshotResponse_APPLIED  SnapshotResponse_Status = 2
	SnapshotResponse_ERROR    SnapshotResponse_Status = 3
	SnapshotResponse_DECLINED SnapshotResponse_Status = 4
)

func (SnapshotResponse_Status) Enum

func (SnapshotResponse_Status) EnumDescriptor

func (SnapshotResponse_Status) EnumDescriptor() ([]byte, []int)

func (SnapshotResponse_Status) String

func (x SnapshotResponse_Status) String() string

func (*SnapshotResponse_Status) UnmarshalJSON

func (x *SnapshotResponse_Status) UnmarshalJSON(data []byte) error

type SnapshotStorePool

type SnapshotStorePool interface {
	// contains filtered or unexported methods
}

SnapshotStorePool narrows StorePool to make sendSnapshot easier to test.

type SpanAccess

type SpanAccess int

SpanAccess records the intended mode of access in SpanSet.

const (
	SpanReadOnly SpanAccess = iota
	SpanReadWrite
)

Constants for SpanAccess. Higher-valued accesses imply lower-level ones.

type SpanSet

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

SpanSet tracks the set of key spans touched by a command. The set is divided into subsets for access type (read-only or read/write) and key scope (local or global; used to facilitate use by the separate local and global command queues).

func (*SpanSet) Add

func (ss *SpanSet) Add(access SpanAccess, span roachpb.Span)

Add a span to the set.

type SpanSetIterator

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

SpanSetIterator wraps an engine.Iterator and ensures that it can only be used to access spans in a SpanSet.

func (*SpanSetIterator) Close

func (s *SpanSetIterator) Close()

Close implements engine.Iterator.

func (*SpanSetIterator) ComputeStats

func (s *SpanSetIterator) ComputeStats(
	start, end engine.MVCCKey, nowNanos int64,
) (enginepb.MVCCStats, error)

ComputeStats implements engine.Iterator.

func (*SpanSetIterator) Error

func (s *SpanSetIterator) Error() error

Error implements engine.Iterator.

func (*SpanSetIterator) Iterator

func (s *SpanSetIterator) Iterator() engine.Iterator

Iterator returns the underlying engine.Iterator.

func (*SpanSetIterator) Key

func (s *SpanSetIterator) Key() engine.MVCCKey

Key implements engine.Iterator.

func (*SpanSetIterator) Less

func (s *SpanSetIterator) Less(key engine.MVCCKey) bool

Less implements engine.Iterator.

func (*SpanSetIterator) Next

func (s *SpanSetIterator) Next()

Next implements engine.Iterator.

func (*SpanSetIterator) NextKey

func (s *SpanSetIterator) NextKey()

NextKey implements engine.Iterator.

func (*SpanSetIterator) Prev

func (s *SpanSetIterator) Prev()

Prev implements engine.Iterator.

func (*SpanSetIterator) PrevKey

func (s *SpanSetIterator) PrevKey()

PrevKey implements engine.Iterator.

func (*SpanSetIterator) Seek

func (s *SpanSetIterator) Seek(key engine.MVCCKey)

Seek implements engine.Iterator.

func (*SpanSetIterator) SeekReverse

func (s *SpanSetIterator) SeekReverse(key engine.MVCCKey)

SeekReverse implements engine.Iterator.

func (*SpanSetIterator) UnsafeKey

func (s *SpanSetIterator) UnsafeKey() engine.MVCCKey

UnsafeKey implements engine.Iterator.

func (*SpanSetIterator) UnsafeValue

func (s *SpanSetIterator) UnsafeValue() []byte

UnsafeValue implements engine.Iterator.

func (*SpanSetIterator) Valid

func (s *SpanSetIterator) Valid() bool

Valid implements engine.Iterator.

func (*SpanSetIterator) Value

func (s *SpanSetIterator) Value() []byte

Value implements engine.Iterator.

func (*SpanSetIterator) ValueProto

func (s *SpanSetIterator) ValueProto(msg proto.Message) error

ValueProto implements engine.Iterator.

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(cfg StoreConfig, eng engine.Engine, nodeDesc *roachpb.NodeDescriptor) *Store

NewStore returns a new instance of a store.

func (*Store) AnnotateCtx

func (s *Store) AnnotateCtx(ctx context.Context) context.Context

AnnotateCtx is a convenience wrapper; see AmbientContext.

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) 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(ctx context.Context, 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) 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) 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,
) *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) error

HandleRaftResponse implements the RaftMessageHandler interface. It requires that s.mu is not held.

func (*Store) HandleRaftUncoalescedRequest

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

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

func (*Store) HandleSnapshot

func (s *Store) HandleSnapshot(header *SnapshotRequest_Header, stream SnapshotResponseStream) error

HandleSnapshot reads an incoming streaming snapshot and applies it if possible.

func (*Store) IsDraining

func (s *Store) IsDraining() bool

IsDraining accessor.

func (*Store) IsStarted

func (s *Store) IsStarted() bool

IsStarted returns true if the Store has been started.

func (*Store) LeaseCount

func (s *Store) LeaseCount() int

LeaseCount returns the number of replicas this store holds leases for.

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(
	ctx context.Context,
	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) NotifyBootstrapped

func (s *Store) NotifyBootstrapped()

NotifyBootstrapped tells the store that it was bootstrapped and allows idle replicas to campaign immediately. This primarily affects tests.

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) ReadLastUpTimestamp

func (s *Store) ReadLastUpTimestamp(ctx context.Context) (hlc.Timestamp, error)

ReadLastUpTimestamp returns the "last up" timestamp recorded in this store. This value can be used to approximate the last time the engine was was being served as a store by a running node. If the store does not contain a "last up" timestamp (for example, on a newly bootstrapped store), the zero timestamp is returned instead.

func (*Store) Registry

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

Registry returns the store registry.

func (*Store) RemoveReplica

func (s *Store) RemoveReplica(
	ctx context.Context, rep *Replica, consistentDesc 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) 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) SetDraining

func (s *Store) SetDraining(drain bool)

SetDraining (when called with 'true') causes incoming lease transfers to be rejected, prevents all of the Store's Replicas from acquiring or extending range leases, and attempts to transfer away any leases owned. When called with 'false', returns to the normal mode of operation.

func (*Store) SplitRange

func (s *Store) SplitRange(ctx context.Context, 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 and newRng.raftMu 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.

func (*Store) WriteLastUpTimestamp

func (s *Store) WriteLastUpTimestamp(ctx context.Context, time hlc.Timestamp) error

WriteLastUpTimestamp records the supplied timestamp into the "last up" key on this store. This value should be refreshed whenever this store's node updates its own liveness record; it is used by a restarting store to determine the approximate time that it stopped.

type StoreConfig

type StoreConfig struct {
	AmbientCtx log.AmbientContext

	Clock        *hlc.Clock
	DB           *client.DB
	Gossip       *gossip.Gossip
	NodeLiveness *NodeLiveness
	StorePool    *StorePool
	Transport    *RaftTransport
	RPCContext   *rpc.Context

	// 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

	// TimeSeriesDataStore is an interface used by the store's time series
	// maintenance queue to dispatch individual maintenance tasks.
	TimeSeriesDataStore TimeSeriesDataStore

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

	// DontRetryPushTxnFailures will propagate a push txn failure immediately
	// instead of utilizing the push txn queue to wait for the transaction to
	// finish or be pushed by a higher priority contender.
	DontRetryPushTxnFailures bool

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

	// CoalescedHeartbeatsInterval is the interval for which heartbeat messages
	// are queued and then sent as a single coalesced heartbeat; it is a
	// fraction of the RaftTickInterval so that heartbeats don't get delayed by
	// an entire tick. Delaying coalescing heartbeat responses has a bad
	// interaction with quiescence because the coalesced (delayed) heartbeat
	// response can unquiesce the leader. Consider:
	//
	// T+0: leader queues MsgHeartbeat
	// T+1: leader sends MsgHeartbeat
	//                                        follower receives MsgHeartbeat
	//                                        follower queues MsgHeartbeatResp
	// T+2: leader queues quiesce message
	//                                        follower sends MsgHeartbeatResp
	//      leader receives MsgHeartbeatResp
	// T+3: leader sends quiesce message
	//
	// Thus we want to make sure that heartbeats are responded to faster than
	// the quiesce cadence.
	CoalescedHeartbeatsInterval 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

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

	// 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

	// RangeLeaseActiveDuration is the duration of the active period of leader
	// leases requested.
	RangeLeaseActiveDuration time.Duration

	// RangeLeaseRenewalDuration specifies a time interval at the end of the
	// active lease interval (i.e. bounded to the right by the start of the stasis
	// period) during which operations will trigger an asynchronous renewal of the
	// lease.
	RangeLeaseRenewalDuration time.Duration

	// MetricsSampleInterval is (server.Context).MetricsSampleInterval
	MetricsSampleInterval time.Duration

	// HistogramWindowInterval is (server.Context).HistogramWindowInterval
	HistogramWindowInterval time.Duration

	// EnableCoalescedHeartbeats controls whether heartbeats are coalesced.
	EnableCoalescedHeartbeats bool

	// EnableEpochRangeLeases controls whether epoch-based range leases are used.
	EnableEpochRangeLeases bool

	// GossipWhenCapacityDeltaExceedsFraction specifies the fraction from the last
	// gossiped store capacity values which need be exceeded before the store will
	// gossip immediately without waiting for the periodic gossip interval.
	GossipWhenCapacityDeltaExceedsFraction float64
	// contains filtered or unexported fields
}

A StoreConfig 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.

func TestStoreConfig

func TestStoreConfig(clock *hlc.Clock) StoreConfig

TestStoreConfig has some fields initialized with values relevant in tests.

func (*StoreConfig) LeaseExpiration

func (sc *StoreConfig) LeaseExpiration() int64

LeaseExpiration returns an int64 to increment a manual clock with to make sure that all active range leases expire.

func (*StoreConfig) SetDefaults

func (sc *StoreConfig) SetDefaults()

SetDefaults initializes unset fields in StoreConfig to values suitable for use on a local network. TODO(tschottdorf) see if this ought to be configurable via flags.

func (*StoreConfig) Valid

func (sc *StoreConfig) Valid() bool

Valid returns true if the StoreConfig 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

	// Replica CommandQueue metrics.
	MaxCommandQueueSize       *metric.Gauge
	MaxCommandQueueWriteCount *metric.Gauge
	MaxCommandQueueReadCount  *metric.Gauge
	MaxCommandQueueTreeSize   *metric.Gauge
	MaxCommandQueueOverlaps   *metric.Gauge
	CombinedCommandQueueSize  *metric.Gauge
	CombinedCommandWriteCount *metric.Gauge
	CombinedCommandReadCount  *metric.Gauge

	// Range metrics.
	RangeCount                *metric.Gauge
	UnavailableRangeCount     *metric.Gauge
	UnderReplicatedRangeCount *metric.Gauge

	// Lease request metrics for successful and failed lease requests. These
	// count proposals (i.e. it does not matter how many replicas apply the
	// lease).
	LeaseRequestSuccessCount  *metric.Counter
	LeaseRequestErrorCount    *metric.Counter
	LeaseTransferSuccessCount *metric.Counter
	LeaseTransferErrorCount   *metric.Counter
	LeaseExpirationCount      *metric.Gauge
	LeaseEpochCount           *metric.Gauge

	// 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
	RdbNumSSTables              *metric.Gauge

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

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

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

	// Raft log metrics.
	RaftLogFollowerBehindCount *metric.Gauge
	RaftLogSelfBehindCount     *metric.Gauge
	RaftLogTruncated           *metric.Counter

	RaftEnqueuedPending            *metric.Gauge
	RaftCoalescedHeartbeatsPending *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
	RaftSnapshotQueueSuccesses                *metric.Counter
	RaftSnapshotQueueFailures                 *metric.Counter
	RaftSnapshotQueuePending                  *metric.Gauge
	RaftSnapshotQueueProcessingNanos          *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
	TimeSeriesMaintenanceQueueSuccesses       *metric.Counter
	TimeSeriesMaintenanceQueueFailures        *metric.Counter
	TimeSeriesMaintenanceQueuePending         *metric.Gauge
	TimeSeriesMaintenanceQueueProcessingNanos *metric.Counter

	// GCInfo cumulative totals.
	GCNumKeysAffected            *metric.Counter
	GCIntentsConsidered          *metric.Counter
	GCIntentTxns                 *metric.Counter
	GCTransactionSpanScanned     *metric.Counter
	GCTransactionSpanGCAborted   *metric.Counter
	GCTransactionSpanGCCommitted *metric.Counter
	GCTransactionSpanGCPending   *metric.Counter
	GCAbortSpanScanned           *metric.Counter
	GCAbortSpanConsidered        *metric.Counter
	GCAbortSpanGCNum             *metric.Counter
	GCPushTxn                    *metric.Counter
	GCResolveTotal               *metric.Counter
	GCResolveSuccess             *metric.Counter

	// Slow request counts.
	SlowCommandQueueRequests *metric.Gauge
	SlowLeaseRequests        *metric.Gauge
	SlowRaftRequests         *metric.Gauge
	// contains filtered or unexported fields
}

StoreMetrics is the set of metrics for a given store.

type StorePool

type StorePool struct {
	log.AmbientContext
	// 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(
	ambient log.AmbientContext,
	g *gossip.Gossip,
	clock *hlc.Clock,
	nodeLivenessFn NodeLivenessFunc,
	timeUntilStoreDead time.Duration,
	deterministic bool,
) *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_pkg_roachpb.NodeID  `` /* 141-byte string literal not displayed */
	StoreID github_com_cockroachdb_cockroach_pkg_roachpb.StoreID `` /* 145-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 {

	// TestingEvalFilter is called before evaluating each command. The
	// number of times this callback is run depends on the propEvalKV
	// setting, and it is therefore deprecated in favor of either
	// TestingProposalFilter (which runs only on the lease holder) or
	// TestingApplyFilter (which runs on each replica). If your filter is
	// not idempotent, consider wrapping it in a
	// ReplayProtectionFilterWrapper.
	// TODO(bdarnell,tschottdorf): Migrate existing tests which use this
	// to one of the other filters. See #10493
	TestingEvalFilter storagebase.ReplicaCommandFilter

	// TestingApplyFilter is called before applying the results of a
	// command on each replica. If it returns an error, the command will
	// not be applied. If it returns an error on some replicas but not
	// others, the behavior is poorly defined unless that error is a
	// ReplicaCorruptionError.
	TestingApplyFilter storagebase.ReplicaApplyFilter

	// TestingPostApplyFilter is called after a command is applied to
	// rocksdb but before in-memory side effects have been processed.
	TestingPostApplyFilter storagebase.ReplicaApplyFilter

	// TestingResponseFilter is called after the replica processes a
	// command in order for unittests to modify the batch response,
	// error returned to the client, or to simulate network failures.
	TestingResponseFilter storagebase.ReplicaResponseFilter

	// 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)
	// OnCampaign is called if the replica campaigns for Raft leadership
	// when initializing the Raft group. Note that this method is invoked
	// with both Replica.raftMu and Replica.mu locked.
	OnCampaign func(*Replica)
	// MaxOffset, if set, overrides the server clock's MaxOffset at server
	// creation time.
	// See also DisableMaxOffsetCheck.
	MaxOffset time.Duration
	// DisableMaxOffsetCheck disables the rejection (in Store.Send) of requests
	// with the timestamp too much in the future. Normally, this rejection is a
	// good sanity check, but certain tests unfortunately insert a "message from
	// the future" into the system to advance the clock of a TestServer. We
	// should get rid of such practices once we make TestServer take a
	// ManualClock.
	DisableMaxOffsetCheck bool
	// DontPreventUseOfOldLeaseOnStart disables the initialization of
	// replica.mu.minLeaseProposedTS on replica.Init(). This has the effect of
	// allowing the replica to use the lease that it had in a previous life (in
	// case the tests persisted the engine used in said previous life).
	DontPreventUseOfOldLeaseOnStart bool
	// LeaseRequestEvent, if set, is called when replica.requestLeaseLocked() is
	// called to acquire a new lease. This can be used to assert that a request
	// triggers a lease acquisition.
	LeaseRequestEvent func(ts hlc.Timestamp)
	// 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 replica GC queue.
	DisableReplicaGCQueue bool
	// DisableReplicateQueue disables the replication queue.
	DisableReplicateQueue bool
	// DisableSplitQueue disables the split queue.
	DisableSplitQueue bool
	// DisableTimeSeriesMaintenanceQueue disables the time series maintenance
	// queue.
	DisableTimeSeriesMaintenanceQueue bool
	// DisableScanner disables the replica scanner.
	DisableScanner bool
	// DisablePeriodicGossips disables periodic gossiping.
	DisablePeriodicGossips 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
	// DisableLastProcessedCheck disables checking on replica queue last processed times.
	DisableLastProcessedCheck bool
	// ReplicateQueueAcceptsUnsplit allows the replication queue to
	// process ranges that need to be split, for use in tests that use
	// the replication queue but disable the split queue.
	ReplicateQueueAcceptsUnsplit bool
	// NumKeysEvaluatedForRangeIntentResolution is set by the stores to the
	// number of keys evaluated for range intent resolution.
	NumKeysEvaluatedForRangeIntentResolution *int64
	// SkipMinSizeCheck, if set, makes the store creation process skip the check
	// for a minimum size.
	SkipMinSizeCheck bool
	// DisableAsyncIntentResolution disables the async intent resolution
	// path (but leaves synchronous resolution). This can avoid some
	// edge cases in tests that start and stop servers.
	DisableAsyncIntentResolution bool
}

StoreTestingKnobs is a part of the context used to control parts of the system. The Testing*Filter functions are called at various points in the request pipeline if they are non-nil. These can be used either for synchronization (e.g. to write to a channel when a particular point is reached) or to change the behavior by returning an error (which aborts all further processing for the command).

func (*StoreTestingKnobs) ModuleTestingKnobs

func (*StoreTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type Stores

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

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(ambient log.AmbientContext, 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 TimeSeriesDataStore

type TimeSeriesDataStore interface {
	ContainsTimeSeries(roachpb.RKey, roachpb.RKey) bool
	PruneTimeSeries(
		context.Context, engine.Reader, roachpb.RKey, roachpb.RKey, *client.DB, hlc.Timestamp,
	) error
}

TimeSeriesDataStore is an interface defined in the storage package that can be implemented by the higher-level time series system. This allows the storage queues to run periodic time series maintenance; importantly, this maintenance can then be informed by data from the local store.

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