// start starts the node by registering the storage instance for the // RPC service "Node" and initializing stores for each specified // engine. Launches periodic store gossiping in a goroutine. func (n *Node) start(rpcServer *rpc.Server, addr net.Addr, engines []engine.Engine, attrs roachpb.Attributes, stopper *stop.Stopper) error { n.initDescriptor(addr, attrs) const method = "Node.Batch" if err := rpcServer.Register(method, n.executeCmd, &roachpb.BatchRequest{}); err != nil { log.Fatalf("unable to register node service with RPC server: %s", err) } // Start status monitor. n.status.StartMonitorFeed(n.ctx.EventFeed) // Initialize stores, including bootstrapping new ones. if err := n.initStores(engines, stopper); err != nil { return err } n.startedAt = n.ctx.Clock.Now().WallTime // Initialize publisher for Node Events. This requires the NodeID, which is // initialized by initStores(); because of this, some Store initialization // events will precede the StartNodeEvent on the feed. n.feed = status.NewNodeEventFeed(n.Descriptor.NodeID, n.ctx.EventFeed) n.feed.StartNode(n.Descriptor, n.startedAt) n.startPublishStatuses(stopper) n.startGossip(stopper) log.Infoc(n.context(), "Started node with %v engine(s) and attributes %v", engines, attrs.Attrs) return nil }
// start initializes the infostore with the rpc server address and // then begins processing connecting clients in an infinite select // loop via goroutine. Periodically, clients connected and awaiting // the next round of gossip are awoken via the conditional variable. func (s *server) start(rpcServer *rpc.Server, stopper *stop.Stopper) { addr := rpcServer.Addr() s.is.NodeAddr = util.MakeUnresolvedAddr(addr.Network(), addr.String()) if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &Request{}); err != nil { log.Fatalf("unable to register gossip service with RPC server: %s", err) } rpcServer.AddCloseCallback(s.onClose) updateCallback := func(_ string, _ roachpb.Value) { // Wakeup all pending clients. s.ready.Broadcast() } unregister := s.is.registerCallback(".*", updateCallback) stopper.RunWorker(func() { // Periodically wakeup blocked client gossip requests. for { select { case <-stopper.ShouldStop(): s.stop(unregister) return } } }) }
func newFakeGossipServer(rpcServer *rpc.Server, stopper *stop.Stopper) (*fakeGossipServer, error) { s := &fakeGossipServer{ nodeIDChan: make(chan roachpb.NodeID, 1), } if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &Request{}); err != nil { return nil, util.Errorf("unable to register gossip service with RPC server: %s", err) } return s, nil }
// start starts the node by registering the storage instance for the // RPC service "Node" and initializing stores for each specified // engine. Launches periodic store gossiping in a goroutine. func (n *Node) start(rpcServer *rpc.Server, engines []engine.Engine, attrs proto.Attributes, stopper *stop.Stopper) error { n.initDescriptor(rpcServer.Addr(), attrs) requests := []proto.Request{ &proto.BatchRequest{}, &proto.GetRequest{}, &proto.PutRequest{}, &proto.ConditionalPutRequest{}, &proto.IncrementRequest{}, &proto.DeleteRequest{}, &proto.DeleteRangeRequest{}, &proto.ScanRequest{}, &proto.ReverseScanRequest{}, &proto.EndTransactionRequest{}, &proto.AdminSplitRequest{}, &proto.AdminMergeRequest{}, &proto.HeartbeatTxnRequest{}, &proto.GCRequest{}, &proto.PushTxnRequest{}, &proto.RangeLookupRequest{}, &proto.ResolveIntentRequest{}, &proto.ResolveIntentRangeRequest{}, &proto.MergeRequest{}, &proto.TruncateLogRequest{}, &proto.LeaderLeaseRequest{}, } for _, r := range requests { if err := rpcServer.Register("Node."+r.Method().String(), n.executeCmd, r); err != nil { log.Fatalf("unable to register node service with RPC server: %s", err) } } // Start status monitor. n.status.StartMonitorFeed(n.ctx.EventFeed) // Initialize stores, including bootstrapping new ones. if err := n.initStores(engines, stopper); err != nil { return err } n.startedAt = n.ctx.Clock.Now().WallTime // Initialize publisher for Node Events. This requires the NodeID, which is // initialized by initStores(); because of this, some Store initialization // events will precede the StartNodeEvent on the feed. n.feed = status.NewNodeEventFeed(n.Descriptor.NodeID, n.ctx.EventFeed) n.feed.StartNode(n.Descriptor, n.startedAt) n.startPublishStatuses(stopper) n.startGossip(stopper) log.Infoc(n.context(), "Started node with %v engine(s) and attributes %v", engines, attrs.Attrs) return nil }
// start starts the node by registering the storage instance for the // RPC service "Node" and initializing stores for each specified // engine. Launches periodic store gossiping in a goroutine. func (n *Node) start(rpcServer *rpc.Server, addr net.Addr, engines []engine.Engine, attrs roachpb.Attributes) error { n.initDescriptor(addr, attrs) // Start status monitor. n.status.StartMonitorFeed(n.ctx.EventFeed) // Initialize stores, including bootstrapping new ones. if err := n.initStores(engines, n.stopper); err != nil { if err == errNeedsBootstrap { // This node has no initialized stores and no way to connect to // an existing cluster, so we bootstrap it. clusterID, err := bootstrapCluster(engines) if err != nil { return err } log.Infof("**** cluster %s has been created", clusterID) log.Infof("**** add additional nodes by specifying --join=%s", addr) // Make sure we add the node as a resolver. selfResolver, err := resolver.NewResolverFromAddress(addr) if err != nil { return err } n.ctx.Gossip.SetResolvers([]resolver.Resolver{selfResolver}) // After bootstrapping, try again to initialize the stores. if err := n.initStores(engines, n.stopper); err != nil { return err } } else { return err } } n.startedAt = n.ctx.Clock.Now().WallTime // Initialize publisher for Node Events. This requires the NodeID, which is // initialized by initStores(); because of this, some Store initialization // events will precede the StartNodeEvent on the feed. n.feed = status.NewNodeEventFeed(n.Descriptor.NodeID, n.ctx.EventFeed) n.feed.StartNode(n.Descriptor, n.startedAt) n.startPublishStatuses(n.stopper) n.startGossip(n.stopper) // Register the RPC methods we support last as doing so allows RPCs to be // received which may access state initialized above without locks. const method = "Node.Batch" if err := rpcServer.Register(method, n.executeCmd, &roachpb.BatchRequest{}); err != nil { log.Fatalf("unable to register node service with RPC server: %s", err) } log.Infoc(n.context(), "Started node with %v engine(s) and attributes %v", engines, attrs.Attrs) return nil }
// RegisterRPC registers the RPC endpoints. func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error { for i, reqType := range allExternalMethods { if reqType == nil { continue } method := proto.Method(i) if err := rpcServer.Register(fmt.Sprintf("Server.%s", method), s.executeCmd, reqType); err != nil { return err } } return nil }
// start initializes the infostore with the rpc server address and // then begins processing connecting clients in an infinite select // loop via goroutine. Periodically, clients connected and awaiting // the next round of gossip are awoken via the conditional variable. func (s *server) start(rpcServer *rpc.Server, stopper *stop.Stopper) { s.is.NodeAddr = rpcServer.Addr() if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &proto.GossipRequest{}); err != nil { log.Fatalf("unable to register gossip service with RPC server: %s", err) } rpcServer.AddCloseCallback(s.onClose) stopper.RunWorker(func() { // Periodically wakeup blocked client gossip requests. for { select { case <-time.After(s.jitteredGossipInterval()): // Wakeup all blocked gossip requests. s.ready.Broadcast() case <-stopper.ShouldStop(): s.stop() return } } }) }
// start initializes the infostore with the rpc server address and // then begins processing connecting clients in an infinite select // loop via goroutine. Periodically, clients connected and awaiting // the next round of gossip are awoken via the conditional variable. func (s *server) start(rpcServer *rpc.Server, addr net.Addr) { s.is.NodeAddr = util.MakeUnresolvedAddr(addr.Network(), addr.String()) if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &Request{}); err != nil { log.Fatalf("unable to register gossip service with RPC server: %s", err) } rpcServer.AddOpenCallback(s.onOpen) rpcServer.AddCloseCallback(s.onClose) updateCallback := func(_ string, _ roachpb.Value) { // Wakeup all pending clients. s.ready.Broadcast() } unregister := s.is.registerCallback(".*", updateCallback) s.stopper.RunWorker(func() { <-s.stopper.ShouldStop() s.mu.Lock() defer s.mu.Unlock() unregister() s.ready.Broadcast() // wake up clients }) }
// RegisterRPC registers the RPC endpoints. func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error { requests := []proto.Request{ &proto.GetRequest{}, &proto.PutRequest{}, &proto.ConditionalPutRequest{}, &proto.IncrementRequest{}, &proto.DeleteRequest{}, &proto.DeleteRangeRequest{}, &proto.ScanRequest{}, &proto.EndTransactionRequest{}, &proto.BatchRequest{}, &proto.AdminSplitRequest{}, &proto.AdminMergeRequest{}, } for _, r := range requests { if err := rpcServer.Register("Server."+r.Method().String(), s.executeCmd, r); err != nil { return err } } return nil }
// RegisterRPC registers the RPC endpoints. func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error { const method = "Server.Batch" return rpcServer.Register(method, s.executeCmd, &roachpb.BatchRequest{}) }