本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/roachpb.RangeID函数的典型用法代码示例。如果您正苦于以下问题:Golang RangeID函数的具体用法?Golang RangeID怎么用?Golang RangeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RangeID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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")})
}
示例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")
}
}
示例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
}
示例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
}
示例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
}
示例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
})
}
示例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")
}
}
示例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))
}
示例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")
}
}
示例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")
}
}
示例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)
}
}
示例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
}
}
示例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)
}
}
示例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
}