本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/roachpb.NodeID函数的典型用法代码示例。如果您正苦于以下问题:Golang NodeID函数的具体用法?Golang NodeID怎么用?Golang NodeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NodeID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestInfoStoreMostDistant
// TestInfoStoreMostDistant verifies selection of most distant node &
// associated hops.
func TestInfoStoreMostDistant(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes := []roachpb.NodeID{
roachpb.NodeID(1),
roachpb.NodeID(2),
roachpb.NodeID(3),
}
is, stopper := newTestInfoStore()
defer stopper.Stop()
// Add info from each address, with hop count equal to index+1.
for i := 0; i < len(nodes); i++ {
inf := is.newInfo(nil, time.Second)
inf.Hops = uint32(i + 1)
inf.NodeID = nodes[i]
if err := is.addInfo(fmt.Sprintf("b.%d", i), inf); err != nil {
t.Fatal(err)
}
nodeID, hops := is.mostDistant()
if nodeID != inf.NodeID {
t.Errorf("%d: expected node %d; got %d", i, inf.NodeID, nodeID)
}
if hops != inf.Hops {
t.Errorf("%d: expected node %d; got %d", i, inf.Hops, hops)
}
}
}
开发者ID:knz,项目名称:cockroach,代码行数:28,代码来源:infostore_test.go
示例2: TestPreexistingReplicaCheck
func TestPreexistingReplicaCheck(t *testing.T) {
defer leaktest.AfterTest(t)()
var existing []roachpb.ReplicaDescriptor
for i := 2; i < 10; i += 2 {
existing = append(existing, roachpb.ReplicaDescriptor{NodeID: roachpb.NodeID(i)})
}
for i := 1; i < 10; i++ {
if e, a := i%2 != 0, preexistingReplicaCheck(roachpb.NodeID(i), existing); e != a {
t.Errorf("NodeID %d expected to be %t, got %t", i, e, a)
}
}
}
开发者ID:maxlang,项目名称:cockroach,代码行数:13,代码来源:rule_solver_test.go
示例3: allocateNodeID
// allocateNodeID increments the node id generator key to allocate
// a new, unique node id.
func allocateNodeID(ctx context.Context, db *client.DB) (roachpb.NodeID, error) {
r, err := db.Inc(ctx, keys.NodeIDGenerator, 1)
if err != nil {
return 0, errors.Errorf("unable to allocate node ID: %s", err)
}
return roachpb.NodeID(r.ValueInt()), nil
}
开发者ID:knz,项目名称:cockroach,代码行数:9,代码来源:node.go
示例4: TestNodeSetAsSlice
func TestNodeSetAsSlice(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""}))
node0 := roachpb.NodeID(1)
node1 := roachpb.NodeID(2)
nodes.addNode(node0)
nodes.addNode(node1)
nodeArr := nodes.asSlice()
if len(nodeArr) != 2 {
t.Error("expected slice of length 2:", nodeArr)
}
if (nodeArr[0] != node0 && nodeArr[0] != node1) ||
(nodeArr[1] != node1 && nodeArr[1] != node0) {
t.Error("expected slice to contain both node0 and node1:", nodeArr)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:17,代码来源:node_set_test.go
示例5: TestGetNodeLocalities
func TestGetNodeLocalities(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper, g, _, sp, _ := createTestStorePool(
TestTimeUntilStoreDead, false /* deterministic */, false /* defaultNodeLiveness */)
defer stopper.Stop()
sg := gossiputil.NewStoreGossiper(g)
// Creates a node with a locality with the number of tiers passed in. The
// NodeID is the same as the tier count.
createDescWithLocality := func(tierCount int) roachpb.NodeDescriptor {
nodeDescriptor := roachpb.NodeDescriptor{NodeID: roachpb.NodeID(tierCount)}
for i := 1; i <= tierCount; i++ {
value := fmt.Sprintf("%d", i)
nodeDescriptor.Locality.Tiers = append(nodeDescriptor.Locality.Tiers, roachpb.Tier{
Key: value,
Value: value,
})
}
return nodeDescriptor
}
stores := []*roachpb.StoreDescriptor{
{
StoreID: 1,
Node: createDescWithLocality(1),
},
{
StoreID: 2,
Node: createDescWithLocality(2),
},
{
StoreID: 3,
Node: createDescWithLocality(3),
},
{
StoreID: 4,
Node: createDescWithLocality(2),
},
}
sg.GossipStores(stores, t)
var existingReplicas []roachpb.ReplicaDescriptor
for _, store := range stores {
existingReplicas = append(existingReplicas, roachpb.ReplicaDescriptor{NodeID: store.Node.NodeID})
}
localities := sp.getNodeLocalities(existingReplicas)
for _, store := range stores {
locality, ok := localities[store.Node.NodeID]
if !ok {
t.Fatalf("could not find locality for node %d", store.Node.NodeID)
}
if e, a := int(store.Node.NodeID), len(locality.Tiers); e != a {
t.Fatalf("for node %d, expected %d tiers, only got %d", store.Node.NodeID, e, a)
}
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:58,代码来源:store_pool_test.go
示例6: addNewNodeWithStore
// addNewNodeWithStore adds new node with a single store.
func (c *Cluster) addNewNodeWithStore() {
nodeID := roachpb.NodeID(len(c.nodes))
c.nodes[nodeID] = newNode(nodeID, c.gossip)
// Only output if we're running the simulation.
if c.epoch >= 0 {
fmt.Fprintf(c.actionWriter, "%d:\tNode %d added\n", c.epoch, nodeID)
}
c.addStore(nodeID)
}
开发者ID:hvaara,项目名称:cockroach,代码行数:10,代码来源:cluster.go
示例7: TestNodeSetFilter
func TestNodeSetFilter(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes1 := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""}))
node0 := roachpb.NodeID(1)
node1 := roachpb.NodeID(2)
nodes1.addNode(node0)
nodes1.addNode(node1)
nodes2 := makeNodeSet(1, metric.NewGauge(metric.Metadata{Name: ""}))
nodes2.addNode(node1)
filtered := nodes1.filter(func(a roachpb.NodeID) bool {
return !nodes2.hasNode(a)
})
if filtered.len() != 1 || filtered.hasNode(node1) || !filtered.hasNode(node0) {
t.Errorf("expected filter to leave node0: %+v", filtered)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:18,代码来源:node_set_test.go
示例8: TestNodeSetAddAndRemoveNode
func TestNodeSetAddAndRemoveNode(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""}))
node0 := roachpb.NodeID(1)
node1 := roachpb.NodeID(2)
nodes.addNode(node0)
nodes.addNode(node1)
if !nodes.hasNode(node0) || !nodes.hasNode(node1) {
t.Error("failed to locate added nodes")
}
nodes.removeNode(node0)
if nodes.hasNode(node0) || !nodes.hasNode(node1) {
t.Error("failed to remove node0", nodes)
}
nodes.removeNode(node1)
if nodes.hasNode(node0) || nodes.hasNode(node1) {
t.Error("failed to remove node1", nodes)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:19,代码来源:node_set_test.go
示例9: TestNodeSetMaxSize
func TestNodeSetMaxSize(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes := makeNodeSet(1, metric.NewGauge(metric.Metadata{Name: ""}))
if !nodes.hasSpace() {
t.Error("set should have space")
}
nodes.addNode(roachpb.NodeID(1))
if nodes.hasSpace() {
t.Error("set should have no space")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:11,代码来源:node_set_test.go
示例10: NodeIDFromKey
// NodeIDFromKey attempts to extract a NodeID from the provided key.
// The key should have been constructed by MakeNodeIDKey.
// Returns an error if the key is not of the correct type or is not parsable.
func NodeIDFromKey(key string) (roachpb.NodeID, error) {
trimmedKey := strings.TrimPrefix(key, KeyNodeIDPrefix+separator)
if trimmedKey == key {
return 0, errors.Errorf("%q is not a NodeID Key", key)
}
nodeID, err := strconv.ParseInt(trimmedKey, 10, 64)
if err != nil {
return 0, errors.Wrapf(err, "failed parsing NodeID from key %q", key)
}
return roachpb.NodeID(nodeID), nil
}
开发者ID:hvaara,项目名称:cockroach,代码行数:14,代码来源:keys.go
示例11: Start
// Start starts the test cluster by bootstrapping an in-memory store
// (defaults to maximum of 50M). The server is started, launching the
// node RPC server and all HTTP endpoints. Use the value of
// TestServer.Addr after Start() for client connections. Use Stop()
// to shutdown the server after the test completes.
func (ltc *LocalTestCluster) Start(t util.Tester, baseCtx *base.Config, initSender InitSenderFn) {
ambient := log.AmbientContext{Tracer: tracing.NewTracer()}
nc := &base.NodeIDContainer{}
ambient.AddLogTag("n", nc)
nodeID := roachpb.NodeID(1)
nodeDesc := &roachpb.NodeDescriptor{NodeID: nodeID}
ltc.tester = t
ltc.Manual = hlc.NewManualClock(0)
ltc.Clock = hlc.NewClock(ltc.Manual.UnixNano)
ltc.Stopper = stop.NewStopper()
rpcContext := rpc.NewContext(ambient, baseCtx, ltc.Clock, ltc.Stopper)
server := rpc.NewServer(rpcContext) // never started
ltc.Gossip = gossip.New(ambient, nc, rpcContext, server, nil, ltc.Stopper, metric.NewRegistry())
ltc.Eng = engine.NewInMem(roachpb.Attributes{}, 50<<20)
ltc.Stopper.AddCloser(ltc.Eng)
ltc.Stores = storage.NewStores(ambient, ltc.Clock)
ltc.Sender = initSender(nodeDesc, ambient.Tracer, ltc.Clock, ltc.Latency, ltc.Stores, ltc.Stopper,
ltc.Gossip)
if ltc.DBContext == nil {
dbCtx := client.DefaultDBContext()
ltc.DBContext = &dbCtx
}
ltc.DB = client.NewDBWithContext(ltc.Sender, *ltc.DBContext)
transport := storage.NewDummyRaftTransport()
cfg := storage.TestStoreConfig()
if ltc.RangeRetryOptions != nil {
cfg.RangeRetryOptions = *ltc.RangeRetryOptions
}
cfg.AmbientCtx = ambient
cfg.Clock = ltc.Clock
cfg.DB = ltc.DB
cfg.Gossip = ltc.Gossip
cfg.Transport = transport
cfg.MetricsSampleInterval = metric.TestSampleInterval
ltc.Store = storage.NewStore(cfg, ltc.Eng, nodeDesc)
if err := ltc.Store.Bootstrap(roachpb.StoreIdent{NodeID: nodeID, StoreID: 1}); err != nil {
t.Fatalf("unable to start local test cluster: %s", err)
}
ltc.Stores.AddStore(ltc.Store)
if err := ltc.Store.BootstrapRange(nil); err != nil {
t.Fatalf("unable to start local test cluster: %s", err)
}
if err := ltc.Store.Start(context.Background(), ltc.Stopper); err != nil {
t.Fatalf("unable to start local test cluster: %s", err)
}
nc.Set(context.TODO(), nodeDesc.NodeID)
if err := ltc.Gossip.SetNodeDescriptor(nodeDesc); err != nil {
t.Fatalf("unable to set node descriptor: %s", err)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:59,代码来源:local_test_cluster.go
示例12: parseNodeID
func (s *statusServer) parseNodeID(nodeIDParam string) (roachpb.NodeID, bool, error) {
// No parameter provided or set to local.
if len(nodeIDParam) == 0 || localRE.MatchString(nodeIDParam) {
return s.gossip.NodeID.Get(), true, nil
}
id, err := strconv.ParseInt(nodeIDParam, 10, 64)
if err != nil {
return 0, false, fmt.Errorf("node id could not be parsed: %s", err)
}
nodeID := roachpb.NodeID(id)
return nodeID, nodeID == s.gossip.NodeID.Get(), nil
}
开发者ID:knz,项目名称:cockroach,代码行数:13,代码来源:status.go
示例13: TestNodeSetHasNode
func TestNodeSetHasNode(t *testing.T) {
defer leaktest.AfterTest(t)()
nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""}))
node := roachpb.NodeID(1)
if nodes.hasNode(node) {
t.Error("node wasn't added and should not be valid")
}
// Add node and verify it's valid.
nodes.addNode(node)
if !nodes.hasNode(node) {
t.Error("empty node wasn't added and should not be valid")
}
}
开发者ID:knz,项目名称:cockroach,代码行数:13,代码来源:node_set_test.go
示例14: 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
示例15: node
func (t *leaseTest) node(nodeID uint32) *csql.LeaseManager {
mgr := t.nodes[nodeID]
if mgr == nil {
nc := &base.NodeIDContainer{}
nc.Set(context.TODO(), roachpb.NodeID(nodeID))
mgr = csql.NewLeaseManager(
nc, *t.kvDB,
t.server.Clock(),
t.leaseManagerTestingKnobs,
t.server.Stopper(),
&csql.MemoryMetrics{},
)
t.nodes[nodeID] = mgr
}
return mgr
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:16,代码来源:lease_test.go
示例16: TestClientRegisterWithInitNodeID
// TestClientRegisterInitNodeID verifies two client's gossip request with NodeID 0.
func TestClientRegisterWithInitNodeID(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop()
// Create three gossip nodes, and connect to the first with NodeID 0.
var g []*Gossip
var gossipAddr string
for i := 0; i < 3; i++ {
RPCContext := rpc.NewContext(log.AmbientContext{}, &base.Config{Insecure: true}, nil, stopper)
server := rpc.NewServer(RPCContext)
ln, err := netutil.ListenAndServeGRPC(stopper, server, util.IsolatedTestAddr)
if err != nil {
t.Fatal(err)
}
// Connect to the first gossip node.
if gossipAddr == "" {
gossipAddr = ln.Addr().String()
}
var resolvers []resolver.Resolver
resolver, err := resolver.NewResolver(gossipAddr)
if err != nil {
t.Fatal(err)
}
resolvers = append(resolvers, resolver)
// node ID must be non-zero
gnode := NewTest(
roachpb.NodeID(i+1), RPCContext, server, resolvers, stopper, metric.NewRegistry(),
)
g = append(g, gnode)
gnode.Start(ln.Addr())
}
util.SucceedsSoon(t, func() error {
// The first gossip node should have two gossip client address
// in nodeMap if these three gossip nodes registered success.
g[0].mu.Lock()
defer g[0].mu.Unlock()
if a, e := len(g[0].mu.nodeMap), 2; a != e {
return errors.Errorf("expected %s to contain %d nodes, got %d", g[0].mu.nodeMap, e, a)
}
return nil
})
}
开发者ID:knz,项目名称:cockroach,代码行数:48,代码来源:client_test.go
示例17: TestClientNodeID
// TestClientNodeID verifies a client's gossip request with correct NodeID.
func TestClientNodeID(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
disconnected := make(chan *client, 1)
localNodeID := roachpb.NodeID(1)
local, remote := startFakeServerGossips(t, localNodeID, stopper)
// Use an insecure context. We're talking to tcp socket which are not in the certs.
rpcContext := newInsecureRPCContext(stopper)
c := newClient(log.AmbientContext{}, &remote.nodeAddr, makeMetrics())
disconnected <- c
defer func() {
stopper.Stop()
if c != <-disconnected {
t.Errorf("expected client disconnect after remote close")
}
}()
// A gossip client may fail to start if the grpc connection times out which
// can happen under load (such as in CircleCI or using `make stress`). So we
// loop creating clients until success or the test times out.
for {
// Wait for c.gossip to start.
select {
case receivedNodeID := <-remote.nodeIDChan:
if receivedNodeID != localNodeID {
t.Fatalf("client should send NodeID with %v, got %v", localNodeID, receivedNodeID)
}
return
case <-disconnected:
// The client hasn't been started or failed to start, loop and try again.
c.start(local, disconnected, rpcContext, stopper, rpcContext.NewBreaker())
}
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:39,代码来源:client_test.go
示例18: TestGossipCullNetwork
// TestGossipCullNetwork verifies that a client will be culled from
// the network periodically (at cullInterval duration intervals).
func TestGossipCullNetwork(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop()
local := startGossip(1, stopper, t, metric.NewRegistry())
local.SetCullInterval(5 * time.Millisecond)
local.mu.Lock()
for i := 0; i < minPeers; i++ {
peer := startGossip(roachpb.NodeID(i+2), stopper, t, metric.NewRegistry())
local.startClient(peer.GetNodeAddr())
}
local.mu.Unlock()
const slowGossipDuration = time.Minute
if err := util.RetryForDuration(slowGossipDuration, func() error {
if peers := len(local.Outgoing()); peers != minPeers {
return errors.Errorf("%d of %d peers connected", peers, minPeers)
}
return nil
}); err != nil {
t.Fatalf("condition failed to evaluate within %s: %s", slowGossipDuration, err)
}
local.manage()
if err := util.RetryForDuration(slowGossipDuration, func() error {
// Verify that a client is closed within the cull interval.
if peers := len(local.Outgoing()); peers != minPeers-1 {
return errors.Errorf("%d of %d peers connected", peers, minPeers-1)
}
return nil
}); err != nil {
t.Fatalf("condition failed to evaluate within %s: %s", slowGossipDuration, err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:40,代码来源:gossip_test.go
示例19:
// This is a collection of test stores used by a suite of tests.
var (
testStoreUSa15 = roachpb.StoreID(1) // us-a-1-5
testStoreUSa1 = roachpb.StoreID(2) // us-a-1
testStoreUSb = roachpb.StoreID(3) // us-b
testStoreEurope = roachpb.StoreID(4) // eur-a-1-5
testStores = []roachpb.StoreDescriptor{
{
StoreID: testStoreUSa15,
Attrs: roachpb.Attributes{
Attrs: []string{"a"},
},
Node: roachpb.NodeDescriptor{
NodeID: roachpb.NodeID(testStoreUSa15),
Locality: roachpb.Locality{
Tiers: testStoreTierSetup("us", "a", "1", "5"),
},
},
Capacity: testStoreCapacitySetup(1, 99),
},
{
StoreID: testStoreUSa1,
Attrs: roachpb.Attributes{
Attrs: []string{"a", "b"},
},
Node: roachpb.NodeDescriptor{
NodeID: roachpb.NodeID(testStoreUSa1),
Locality: roachpb.Locality{
Tiers: testStoreTierSetup("us", "a", "1", ""),
开发者ID:maxlang,项目名称:cockroach,代码行数:30,代码来源:rule_solver_test.go
示例20: TestStorePoolFindDeadReplicas
func TestStorePoolFindDeadReplicas(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper, g, _, sp, mnl := createTestStorePool(
TestTimeUntilStoreDead, false /* deterministic */, false /* defaultNodeLiveness */)
defer stopper.Stop()
sg := gossiputil.NewStoreGossiper(g)
stores := []*roachpb.StoreDescriptor{
{
StoreID: 1,
Node: roachpb.NodeDescriptor{NodeID: 1},
},
{
StoreID: 2,
Node: roachpb.NodeDescriptor{NodeID: 2},
},
{
StoreID: 3,
Node: roachpb.NodeDescriptor{NodeID: 3},
},
{
StoreID: 4,
Node: roachpb.NodeDescriptor{NodeID: 4},
},
{
StoreID: 5,
Node: roachpb.NodeDescriptor{NodeID: 5},
},
}
replicas := []roachpb.ReplicaDescriptor{
{
NodeID: 1,
StoreID: 1,
ReplicaID: 1,
},
{
NodeID: 2,
StoreID: 2,
ReplicaID: 2,
},
{
NodeID: 3,
StoreID: 3,
ReplicaID: 4,
},
{
NodeID: 4,
StoreID: 5,
ReplicaID: 4,
},
{
NodeID: 5,
StoreID: 5,
ReplicaID: 5,
},
}
sg.GossipStores(stores, t)
for i := 1; i <= 5; i++ {
mnl.setLive(roachpb.NodeID(i), true)
}
deadReplicas := sp.deadReplicas(0, replicas)
if len(deadReplicas) > 0 {
t.Fatalf("expected no dead replicas initially, found %d (%v)", len(deadReplicas), deadReplicas)
}
// Mark nodes 4 & 5 as dead.
mnl.setLive(4, false)
mnl.setLive(5, false)
deadReplicas = sp.deadReplicas(0, replicas)
if a, e := deadReplicas, replicas[3:]; !reflect.DeepEqual(a, e) {
t.Fatalf("findDeadReplicas did not return expected values; got \n%v, expected \n%v", a, e)
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:76,代码来源:store_pool_test.go
注:本文中的github.com/cockroachdb/cockroach/pkg/roachpb.NodeID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论