本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/roachpb.RangeID函数的典型用法代码示例。如果您正苦于以下问题:Golang RangeID函数的具体用法?Golang RangeID怎么用?Golang RangeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RangeID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestEntryCache
func TestEntryCache(t *testing.T) {
defer leaktest.AfterTest(t)()
rec := newRaftEntryCache(100)
rangeID := roachpb.RangeID(2)
// Add entries for range 1, indexes (1-10).
ents := addEntries(rec, rangeID, 1, 11)
// Fetch all data with an exact match.
verifyGet(t, rec, rangeID, 1, 11, ents, 11)
// Fetch point entry.
verifyGet(t, rec, rangeID, 1, 2, ents[0:1], 2)
// Fetch overlapping first half.
verifyGet(t, rec, rangeID, 0, 5, []raftpb.Entry{}, 0)
// Fetch overlapping second half.
verifyGet(t, rec, rangeID, 9, 12, ents[8:], 11)
// Fetch data from earlier range.
verifyGet(t, rec, roachpb.RangeID(1), 1, 11, []raftpb.Entry{}, 1)
// Fetch data from later range.
verifyGet(t, rec, roachpb.RangeID(3), 1, 11, []raftpb.Entry{}, 1)
// Create a gap in the entries.
rec.delEntries(rangeID, 4, 8)
// Fetch all data; verify we get only first three.
verifyGet(t, rec, rangeID, 1, 11, ents[0:3], 4)
// Try to fetch from within the gap; expect no entries.
verifyGet(t, rec, rangeID, 5, 11, []raftpb.Entry{}, 5)
// Fetch after the gap.
verifyGet(t, rec, rangeID, 8, 11, ents[7:], 11)
// Delete the prefix of entries.
rec.delEntries(rangeID, 1, 3)
// Verify entries are gone.
verifyGet(t, rec, rangeID, 1, 5, []raftpb.Entry{}, 1)
// Delete the suffix of entries.
rec.delEntries(rangeID, 10, 11)
// Verify get of entries at end of range.
verifyGet(t, rec, rangeID, 8, 11, ents[7:9], 10)
}
开发者ID:knz,项目名称:cockroach,代码行数:35,代码来源:entry_cache_test.go
示例2: localRangeIDKeyParse
func localRangeIDKeyParse(input string) (remainder string, key roachpb.Key) {
var rangeID int64
var err error
input = mustShiftSlash(input)
if endPos := strings.Index(input, "/"); endPos > 0 {
rangeID, err = strconv.ParseInt(input[:endPos], 10, 64)
if err != nil {
panic(err)
}
input = input[endPos:]
} else {
panic(errors.Errorf("illegal RangeID: %q", input))
}
input = mustShiftSlash(input)
var infix string
infix, input = mustShift(input)
var replicated bool
switch {
case bytes.Equal(localRangeIDUnreplicatedInfix, []byte(infix)):
case bytes.Equal(localRangeIDReplicatedInfix, []byte(infix)):
replicated = true
default:
panic(errors.Errorf("invalid infix: %q", infix))
}
input = mustShiftSlash(input)
// Get the suffix.
var suffix roachpb.RKey
for _, s := range rangeIDSuffixDict {
if strings.HasPrefix(input, s.name) {
input = input[len(s.name):]
if s.psFunc != nil {
remainder, key = s.psFunc(roachpb.RangeID(rangeID), input)
return
}
suffix = roachpb.RKey(s.suffix)
break
}
}
maker := MakeRangeIDUnreplicatedKey
if replicated {
maker = MakeRangeIDReplicatedKey
}
if suffix != nil {
if input != "" {
panic(&errUglifyUnsupported{errors.New("nontrivial detail")})
}
var detail roachpb.RKey
// TODO(tschottdorf): can't do this, init cycle:
// detail, err := UglyPrint(input)
// if err != nil {
// return "", nil, err
// }
remainder = ""
key = maker(roachpb.RangeID(rangeID), suffix, detail)
return
}
panic(&errUglifyUnsupported{errors.New("unhandled general range key")})
}
开发者ID:knz,项目名称:cockroach,代码行数:59,代码来源:printer.go
示例3: TestRangeIDChunk
func TestRangeIDChunk(t *testing.T) {
defer leaktest.AfterTest(t)()
var c rangeIDChunk
if c.Len() != 0 {
t.Fatalf("expected empty chunk, but found %d", c.Len())
}
if c.WriteCap() != rangeIDChunkSize {
t.Fatalf("expected %d, but found %d", rangeIDChunkSize, c.WriteCap())
}
if _, ok := c.PopFront(); ok {
t.Fatalf("successfully popped from empty chunk")
}
for i := 1; i <= rangeIDChunkSize; i++ {
if !c.PushBack(roachpb.RangeID(i)) {
t.Fatalf("%d: failed to push", i)
}
if e := i; e != c.Len() {
t.Fatalf("expected %d, but found %d", e, c.Len())
}
if e := rangeIDChunkSize - i; e != c.WriteCap() {
t.Fatalf("expected %d, but found %d", e, c.WriteCap())
}
}
if c.PushBack(0) {
t.Fatalf("successfully pushed to full chunk")
}
for i := 1; i <= rangeIDChunkSize; i++ {
id, ok := c.PopFront()
if !ok {
t.Fatalf("%d: failed to pop", i)
}
if roachpb.RangeID(i) != id {
t.Fatalf("expected %d, but found %d", i, id)
}
if e := rangeIDChunkSize - i; e != c.Len() {
t.Fatalf("expected %d, but found %d", e, c.Len())
}
if c.WriteCap() != 0 {
t.Fatalf("expected full chunk, but found %d", c.WriteCap())
}
}
if c.Len() != 0 {
t.Fatalf("expected empty chunk, but found %d", c.Len())
}
if c.WriteCap() != 0 {
t.Fatalf("expected full chunk, but found %d", c.WriteCap())
}
if _, ok := c.PopFront(); ok {
t.Fatalf("successfully popped from empty chunk")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:54,代码来源:scheduler_test.go
示例4: newTestRangeSet
// newTestRangeSet creates a new range set that has the count number of ranges.
func newTestRangeSet(count int, t *testing.T) *testRangeSet {
rs := &testRangeSet{replicasByKey: btree.New(64 /* degree */)}
for i := 0; i < count; i++ {
desc := &roachpb.RangeDescriptor{
RangeID: roachpb.RangeID(i),
StartKey: roachpb.RKey(fmt.Sprintf("%03d", i)),
EndKey: roachpb.RKey(fmt.Sprintf("%03d", i+1)),
}
// Initialize the range stat so the scanner can use it.
repl := &Replica{
RangeID: desc.RangeID,
}
repl.mu.TimedMutex = syncutil.MakeTimedMutex(defaultMuLogger)
repl.cmdQMu.TimedMutex = syncutil.MakeTimedMutex(defaultMuLogger)
repl.mu.state.Stats = enginepb.MVCCStats{
KeyBytes: 1,
ValBytes: 2,
KeyCount: 1,
LiveCount: 1,
}
if err := repl.setDesc(desc); err != nil {
t.Fatal(err)
}
if exRngItem := rs.replicasByKey.ReplaceOrInsert(repl); exRngItem != nil {
t.Fatalf("failed to insert range %s", repl)
}
}
return rs
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:31,代码来源:scanner_test.go
示例5: parseRangeID
func parseRangeID(arg string) (roachpb.RangeID, error) {
rangeIDInt, err := strconv.ParseInt(arg, 10, 64)
if err != nil {
return 0, err
}
if rangeIDInt < 1 {
return 0, fmt.Errorf("illegal RangeID: %d", rangeIDInt)
}
return roachpb.RangeID(rangeIDInt), nil
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:10,代码来源:debug.go
示例6: addRange
// addRange adds a new range to the cluster but does not attach it to any
// store.
func (c *Cluster) addRange() *Range {
rangeID := roachpb.RangeID(len(c.ranges))
newRng := newRange(rangeID, c.allocator)
c.ranges[rangeID] = newRng
// Save a sorted array of range IDs to avoid having to calculate them
// multiple times.
c.rangeIDs = append(c.rangeIDs, rangeID)
sort.Sort(c.rangeIDs)
return newRng
}
开发者ID:hvaara,项目名称:cockroach,代码行数:14,代码来源:cluster.go
示例7: TestReplicaGCQueueDropReplicaDirect
// TestReplicaGCQueueDropReplica verifies that a removed replica is
// immediately cleaned up.
func TestReplicaGCQueueDropReplicaDirect(t *testing.T) {
defer leaktest.AfterTest(t)()
mtc := &multiTestContext{}
const numStores = 3
rangeID := roachpb.RangeID(1)
// In this test, the Replica on the second Node is removed, and the test
// verifies that that Node adds this Replica to its RangeGCQueue. However,
// the queue does a consistent lookup which will usually be read from
// Node 1. Hence, if Node 1 hasn't processed the removal when Node 2 has,
// no GC will take place since the consistent RangeLookup hits the first
// Node. We use the TestingCommandFilter to make sure that the second Node
// waits for the first.
cfg := storage.TestStoreConfig(nil)
mtc.storeConfig = &cfg
mtc.storeConfig.TestingKnobs.TestingCommandFilter =
func(filterArgs storagebase.FilterArgs) *roachpb.Error {
et, ok := filterArgs.Req.(*roachpb.EndTransactionRequest)
if !ok || filterArgs.Sid != 2 {
return nil
}
crt := et.InternalCommitTrigger.GetChangeReplicasTrigger()
if crt == nil || crt.ChangeType != roachpb.REMOVE_REPLICA {
return nil
}
testutils.SucceedsSoon(t, func() error {
r, err := mtc.stores[0].GetReplica(rangeID)
if err != nil {
return err
}
if _, ok := r.Desc().GetReplicaDescriptor(2); ok {
return errors.New("expected second node gone from first node's known replicas")
}
return nil
})
return nil
}
defer mtc.Stop()
mtc.Start(t, numStores)
mtc.replicateRange(rangeID, 1, 2)
mtc.unreplicateRange(rangeID, 1)
// Make sure the range is removed from the store.
testutils.SucceedsSoon(t, func() error {
if _, err := mtc.stores[1].GetReplica(rangeID); !testutils.IsError(err, "range .* was not found") {
return errors.Errorf("expected range removal: %v", err) // NB: errors.Wrapf(nil, ...) returns nil.
}
return nil
})
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:54,代码来源:client_replica_gc_test.go
示例8: TestRangeIDQueue
func TestRangeIDQueue(t *testing.T) {
defer leaktest.AfterTest(t)()
var q rangeIDQueue
if q.Len() != 0 {
t.Fatalf("expected empty queue, but found %d", q.Len())
}
if _, ok := q.PopFront(); ok {
t.Fatalf("successfully popped from empty queue")
}
const count = 3 * rangeIDChunkSize
for i := 1; i <= count; i++ {
q.PushBack(roachpb.RangeID(i))
if e := i; e != q.Len() {
t.Fatalf("expected %d, but found %d", e, q.Len())
}
}
for i := 1; i <= count; i++ {
id, ok := q.PopFront()
if !ok {
t.Fatalf("%d: failed to pop", i)
}
if roachpb.RangeID(i) != id {
t.Fatalf("expected %d, but found %d", i, id)
}
if e := count - i; e != q.Len() {
t.Fatalf("expected %d, but found %d", e, q.Len())
}
}
if q.Len() != 0 {
t.Fatalf("expected empty queue, but found %d", q.Len())
}
if _, ok := q.PopFront(); ok {
t.Fatalf("successfully popped from empty queue")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:38,代码来源:scheduler_test.go
示例9: TestBookieReserveMaxBytes
// TestBookieReserveMaxBytes ensures that over-booking doesn't occur when trying
// to reserve more bytes than maxReservedBytes.
func TestBookieReserveMaxBytes(t *testing.T) {
defer leaktest.AfterTest(t)()
previousReservedBytes := 10
stopper, _, b := createTestBookie(time.Hour, previousReservedBytes*2, int64(previousReservedBytes))
defer stopper.Stop()
// Load up reservations with a size of 1 each.
for i := 1; i <= previousReservedBytes; i++ {
req := ReservationRequest{
StoreRequestHeader: StoreRequestHeader{
StoreID: roachpb.StoreID(i),
NodeID: roachpb.NodeID(i),
},
RangeID: roachpb.RangeID(i),
RangeSize: 1,
}
if !b.Reserve(context.Background(), req, nil).Reserved {
t.Errorf("%d: could not add reservation", i)
}
verifyBookie(t, b, i, i, int64(i))
}
overbookedReq := ReservationRequest{
StoreRequestHeader: StoreRequestHeader{
StoreID: roachpb.StoreID(previousReservedBytes + 1),
NodeID: roachpb.NodeID(previousReservedBytes + 1),
},
RangeID: roachpb.RangeID(previousReservedBytes + 1),
RangeSize: 1,
}
if b.Reserve(context.Background(), overbookedReq, nil).Reserved {
t.Errorf("expected reservation to fail due to too many already existing reservations, but it succeeded")
}
// The same numbers from the last call to verifyBookie.
verifyBookie(t, b, previousReservedBytes, previousReservedBytes, int64(previousReservedBytes))
}
开发者ID:knz,项目名称:cockroach,代码行数:40,代码来源:reservation_test.go
示例10: TestEntryCacheClearTo
func TestEntryCacheClearTo(t *testing.T) {
defer leaktest.AfterTest(t)()
rangeID := roachpb.RangeID(1)
rec := newRaftEntryCache(100)
rec.addEntries(rangeID, []raftpb.Entry{newEntry(2, 1)})
rec.addEntries(rangeID, []raftpb.Entry{newEntry(20, 1), newEntry(21, 1)})
rec.clearTo(rangeID, 21)
if ents, _, _ := rec.getEntries(rangeID, 2, 21, 0); len(ents) != 0 {
t.Errorf("expected no entries after clearTo")
}
if ents, _, _ := rec.getEntries(rangeID, 21, 22, 0); len(ents) != 1 {
t.Errorf("expected entry 22 to remain in the cache clearTo")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:14,代码来源:entry_cache_test.go
示例11: TestLeaseHolderCache
func TestLeaseHolderCache(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := context.TODO()
lc := newLeaseHolderCache(3)
if repDesc, ok := lc.Lookup(ctx, 12); ok {
t.Errorf("lookup of missing key returned: %+v", repDesc)
}
rangeID := roachpb.RangeID(5)
replica := roachpb.ReplicaDescriptor{StoreID: 1}
lc.Update(ctx, rangeID, replica)
if repDesc, ok := lc.Lookup(ctx, rangeID); !ok {
t.Fatalf("expected %+v", replica)
} else if repDesc != replica {
t.Errorf("expected %+v, got %+v", replica, repDesc)
}
newReplica := roachpb.ReplicaDescriptor{StoreID: 7}
lc.Update(ctx, rangeID, newReplica)
if repDesc, ok := lc.Lookup(ctx, rangeID); !ok {
t.Fatalf("expected %+v", replica)
} else if repDesc != newReplica {
t.Errorf("expected %+v, got %+v", newReplica, repDesc)
}
lc.Update(ctx, rangeID, roachpb.ReplicaDescriptor{})
if repDesc, ok := lc.Lookup(ctx, rangeID); ok {
t.Errorf("lookup of evicted key returned: %+v", repDesc)
}
for i := 10; i < 20; i++ {
lc.Update(ctx, roachpb.RangeID(i), replica)
}
_, ok16 := lc.Lookup(ctx, 16)
_, ok17 := lc.Lookup(ctx, 17)
if ok16 || !ok17 {
t.Fatalf("unexpected policy used in cache")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:36,代码来源:leaseholder_cache_test.go
示例12: TestEntryCacheEviction
func TestEntryCacheEviction(t *testing.T) {
defer leaktest.AfterTest(t)()
rangeID := roachpb.RangeID(1)
rec := newRaftEntryCache(100)
rec.addEntries(rangeID, []raftpb.Entry{newEntry(1, 40), newEntry(2, 40)})
ents, _, hi := rec.getEntries(rangeID, 1, 3, 0)
if len(ents) != 2 || hi != 3 {
t.Errorf("expected both entries; got %+v, %d", ents, hi)
}
// Add another entry to evict first.
rec.addEntries(rangeID, []raftpb.Entry{newEntry(3, 40)})
ents, _, hi = rec.getEntries(rangeID, 2, 4, 0)
if len(ents) != 2 || hi != 4 {
t.Errorf("expected only two entries; got %+v, %d", ents, hi)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:16,代码来源:entry_cache_test.go
示例13: init
func init() {
lastKey := roachpb.RKey(keys.MinKey)
for i, b := 0, byte('a'); b <= byte('z'); i, b = i+1, b+1 {
key := roachpb.RKey([]byte{b})
alphaRangeDescriptors = append(alphaRangeDescriptors, &roachpb.RangeDescriptor{
RangeID: roachpb.RangeID(i + 2),
StartKey: lastKey,
EndKey: key,
Replicas: []roachpb.ReplicaDescriptor{
{
NodeID: 1,
StoreID: 1,
},
},
})
lastKey = key
}
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:18,代码来源:range_iter_test.go
示例14: TestStorePoolDefaultState
// TestStorePoolDefaultState verifies that the default state of a
// store is neither alive nor dead. This is a regression test for a
// bug in which a call to deadReplicas involving an unknown store
// would have the side effect of marking that store as alive and
// eligible for return by getStoreList. It is therefore significant
// that the two methods are tested in the same test, and in this
// order.
func TestStorePoolDefaultState(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper, _, _, sp := createTestStorePool(TestTimeUntilStoreDeadOff, false /* deterministic */)
defer stopper.Stop()
if dead := sp.deadReplicas(0, []roachpb.ReplicaDescriptor{{StoreID: 1}}); len(dead) > 0 {
t.Errorf("expected 0 dead replicas; got %v", dead)
}
sl, alive, throttled := sp.getStoreList(roachpb.RangeID(0))
if len(sl.stores) > 0 {
t.Errorf("expected no live stores; got list of %v", sl)
}
if alive != 0 {
t.Errorf("expected no live stores; got an alive count of %d", alive)
}
if throttled != 0 {
t.Errorf("expected no live stores; got a throttled count of %d", throttled)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:27,代码来源:store_pool_test.go
示例15: DecodeRangeIDKey
// DecodeRangeIDKey parses a local range ID key into range ID, infix,
// suffix, and detail.
func DecodeRangeIDKey(
key roachpb.Key,
) (rangeID roachpb.RangeID, infix, suffix, detail roachpb.Key, err error) {
if !bytes.HasPrefix(key, LocalRangeIDPrefix) {
return 0, nil, nil, nil, errors.Errorf("key %s does not have %s prefix", key, LocalRangeIDPrefix)
}
// Cut the prefix, the Range ID, and the infix specifier.
b := key[len(LocalRangeIDPrefix):]
b, rangeInt, err := encoding.DecodeUvarintAscending(b)
if err != nil {
return 0, nil, nil, nil, err
}
if len(b) < localSuffixLength+1 {
return 0, nil, nil, nil, errors.Errorf("malformed key does not contain range ID infix and suffix")
}
infix = b[:1]
b = b[1:]
suffix = b[:localSuffixLength]
b = b[localSuffixLength:]
return roachpb.RangeID(rangeInt), infix, suffix, b, nil
}
开发者ID:knz,项目名称:cockroach,代码行数:24,代码来源:keys.go
示例16: TestReplicaGCQueueDropReplicaGCOnScan
// TestReplicaGCQueueDropReplicaOnScan verifies that the range GC queue
// removes a range from a store that no longer should have a replica.
func TestReplicaGCQueueDropReplicaGCOnScan(t *testing.T) {
defer leaktest.AfterTest(t)()
mtc := &multiTestContext{}
defer mtc.Stop()
mtc.Start(t, 3)
// Disable the replica gc queue to prevent direct removal of replica.
mtc.stores[1].SetReplicaGCQueueActive(false)
rangeID := roachpb.RangeID(1)
mtc.replicateRange(rangeID, 1, 2)
mtc.unreplicateRange(rangeID, 1)
// Wait long enough for the direct replica GC to have had a chance and been
// discarded because the queue is disabled.
time.Sleep(10 * time.Millisecond)
if _, err := mtc.stores[1].GetReplica(rangeID); err != nil {
t.Error("unexpected range removal")
}
// Enable the queue.
mtc.stores[1].SetReplicaGCQueueActive(true)
// Increment the clock's timestamp to make the replica GC queue process the range.
mtc.expireLeases()
mtc.manualClock.Increment(int64(storage.ReplicaGCQueueInactivityThreshold + 1))
// Make sure the range is removed from the store.
testutils.SucceedsSoon(t, func() error {
store := mtc.stores[1]
store.ForceReplicaGCScanAndProcess()
if _, err := store.GetReplica(rangeID); !testutils.IsError(err, "range .* was not found") {
return errors.Errorf("expected range removal: %v", err) // NB: errors.Wrapf(nil, ...) returns nil.
}
return nil
})
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:39,代码来源:client_replica_gc_test.go
示例17: executeScriptedActions
// executeScriptedActions performs all scripted actions to the cluster and
// return true if the exit action is encountered.
func (c *Cluster) executeScriptedActions() bool {
var lastEpoch bool
actions := c.script.getActions(c.epoch)
for _, action := range actions {
switch action.operation {
case OpExit:
{
fmt.Fprintf(c.actionWriter, "%d:\tAction:Exit - this will be the last epoch.\n", c.epoch)
lastEpoch = true
}
case OpSplitRange:
{
switch action.variant {
case OpVarValue:
fmt.Fprintf(c.actionWriter, "%d:\tAction:SplitRange - splitting the range %d.\n", c.epoch, action.value)
c.splitRange(roachpb.RangeID(action.value))
case OpVarRandom:
fmt.Fprintf(c.actionWriter, "%d:\tAction:SplitRange - splitting a random range.\n", c.epoch)
c.splitRangeRandom()
case OpVarFirst:
fmt.Fprintf(c.actionWriter, "%d:\tAction:SplitRange - splitting the first range.\n", c.epoch)
c.splitRange(c.rangeIDs[0])
case OpVarLast:
fmt.Fprintf(c.actionWriter, "%d:\tAction:SplitRange - splitting the last range.\n", c.epoch)
c.splitRange(c.rangeIDs[len(c.rangeIDs)-1])
}
}
case OpAddNode:
{
fmt.Fprintf(c.actionWriter, "%d:\tAction:AddNode - Adding a new node with a new store.\n", c.epoch)
c.addNewNodeWithStore()
}
}
}
return lastEpoch
}
开发者ID:hvaara,项目名称:cockroach,代码行数:38,代码来源:cluster.go
示例18: TestStatusSummaries
// TestStatusSummaries verifies that status summaries are written correctly for
// both the Node and stores within the node.
func TestStatusSummaries(t *testing.T) {
defer leaktest.AfterTest(t)()
// ========================================
// Start test server and wait for full initialization.
// ========================================
srv, _, kvDB := serverutils.StartServer(t, base.TestServerArgs{
DisableEventLog: true,
})
defer srv.Stopper().Stop()
ts := srv.(*TestServer)
ctx := context.TODO()
// Retrieve the first store from the Node.
s, err := ts.node.stores.GetStore(roachpb.StoreID(1))
if err != nil {
t.Fatal(err)
}
s.WaitForInit()
content := "junk"
leftKey := "a"
// Scan over all keys to "wake up" all replicas (force a lease holder election).
if _, err := kvDB.Scan(context.TODO(), keys.MetaMax, keys.MaxKey, 0); err != nil {
t.Fatal(err)
}
// Wait for full replication of initial ranges.
initialRanges := ExpectedInitialRangeCount()
util.SucceedsSoon(t, func() error {
for i := 1; i <= int(initialRanges); i++ {
if s.RaftStatus(roachpb.RangeID(i)) == nil {
return errors.Errorf("Store %d replica %d is not present in raft", s.StoreID(), i)
}
}
return nil
})
// ========================================
// Construct an initial expectation for NodeStatus to compare to the first
// status produced by the server.
// ========================================
expectedNodeStatus := &status.NodeStatus{
Desc: ts.node.Descriptor,
StartedAt: 0,
UpdatedAt: 0,
Metrics: map[string]float64{
"exec.success": 0,
"exec.error": 0,
},
}
expectedStoreStatuses := make(map[roachpb.StoreID]status.StoreStatus)
if err := ts.node.stores.VisitStores(func(s *storage.Store) error {
desc, err := s.Descriptor()
if err != nil {
t.Fatal(err)
}
expectedReplicas := 0
if s.StoreID() == roachpb.StoreID(1) {
expectedReplicas = initialRanges
}
stat := status.StoreStatus{
Desc: *desc,
Metrics: map[string]float64{
"replicas": float64(expectedReplicas),
"replicas.leaseholders": float64(expectedReplicas),
"livebytes": 0,
"keybytes": 0,
"valbytes": 0,
"livecount": 0,
"keycount": 0,
"valcount": 0,
},
}
expectedNodeStatus.StoreStatuses = append(expectedNodeStatus.StoreStatuses, stat)
expectedStoreStatuses[s.StoreID()] = stat
return nil
}); err != nil {
t.Fatal(err)
}
// Function to force summaries to be written synchronously, including all
// data currently in the event pipeline. Only one of the stores has
// replicas, so there are no concerns related to quorum writes; if there
// were multiple replicas, more care would need to be taken in the initial
// syncFeed().
forceWriteStatus := func() {
if err := ts.node.computePeriodicMetrics(ctx, 0); err != nil {
t.Fatalf("error publishing store statuses: %s", err)
}
if err := ts.WriteSummaries(); err != nil {
t.Fatalf("error writing summaries: %s", err)
}
}
//.........这里部分代码省略.........
开发者ID:jmptrader,项目名称:cockroach,代码行数:101,代码来源:node_test.go
示例19: Unmarshal
func (m *CollectChecksumRequest) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: CollectChecksumRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: CollectChecksumRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field StoreRequestHeader", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.StoreRequestHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field RangeID", wireType)
}
m.RangeID = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.RangeID |= (github_com_cockroachdb_cockroach_pkg_roachpb.RangeID(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ChecksumID", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthApi
}
//.........这里部分代码省略.........
开发者ID:BramGruneir,项目名称:cockroach,代码行数:101,代码来源:api.pb.go
示例20: Unmarshal
func (m *ReplicatedProposalData) Unmarshal(data []byte) error {
l := len(data)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowProposerKv
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ReplicatedProposalData: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ReplicatedProposalData: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field RangeID", wireType)
}
m.RangeID = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowProposerKv
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
m.RangeID |= (github_com_cockroachdb_cockroach_pkg_roachpb.RangeID(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field OriginReplica", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowProposerKv
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthProposerKv
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.OriginReplica.Unmarshal(data[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Cmd", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowProposerKv
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthProposerKv
}
//.........这里部分代码省略.........
开发者ID:knz,项目名称:cockroach,代码行数:101,代码来源:proposer_kv.pb.go
注:本文中的github.com/cockroachdb/cockroach/pkg/roachpb.RangeID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论