コード例 #1
0
ファイル: server.go プロジェクト: mbertschler/cockroach
// 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
			}
		}
	})
}
コード例 #2
0
ファイル: server.go プロジェクト: Zemnmez/cockroach
// newServer creates and returns a server struct.
func newServer(rpcServer *rpc.Server, interval time.Duration) *server {
	s := &server{
		interval:      interval,
		is:            newInfoStore(rpcServer.Addr()),
		incoming:      newAddrSet(MaxPeers),
		clientAddrMap: make(map[string]net.Addr),
	}
	rpcServer.RegisterName("Gossip", s)
	rpcServer.AddCloseCallback(s.onClose)
	s.ready = sync.NewCond(&s.mu)
	return s
}
コード例 #3
0
ファイル: server.go プロジェクト: GavinHwa/cockroach
// 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) {
	s.is.NodeAddr = rpcServer.Addr()
	rpcServer.RegisterName("Gossip", s)
	rpcServer.AddCloseCallback(s.onClose)

	go func() {
		// Periodically wakeup blocked client gossip requests.
		gossipTimeout := time.Tick(s.jitteredGossipInterval())
		for {
			select {
			case <-gossipTimeout:
				// Wakeup all blocked gossip requests.
				s.ready.Broadcast()
			}
		}
	}()
}
コード例 #4
0
ファイル: server.go プロジェクト: josephwinston/cockroach
// 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) {
	s.is.NodeAddr = rpcServer.Addr()
	if err := rpcServer.RegisterName("Gossip", s); err != nil {
		log.Fatalf("unable to register gossip service with RPC server: %s", err)
	}
	rpcServer.AddCloseCallback(s.onClose)

	go func() {
		// Periodically wakeup blocked client gossip requests.
		gossipTimeout := time.Tick(s.jitteredGossipInterval())
		for {
			select {
			case <-gossipTimeout:
				// Wakeup all blocked gossip requests.
				s.ready.Broadcast()
			}
		}
	}()
}
コード例 #5
0
ファイル: server.go プロジェクト: Gardenya/cockroach
// 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.RegisterName("Gossip", s); 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
			}
		}
	})
}
コード例 #6
0
ファイル: server.go プロジェクト: codeVerySlow/cockroach
// 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
	})
}