예제 #1
0
func checkOfficialize(t *testing.T, network, oldAddrString, newAddrString, expAddrString string) {
	unresolvedAddr := util.NewUnresolvedAddr(network, oldAddrString)
	resolvedAddr := util.NewUnresolvedAddr(network, newAddrString)

	if err := officializeAddr(unresolvedAddr, resolvedAddr); err != nil {
		t.Fatal(err)
	}

	if retAddrString := unresolvedAddr.String(); retAddrString != expAddrString {
		t.Errorf("officializeAddr(%s, %s) was %s; expected %s", oldAddrString, newAddrString, retAddrString, expAddrString)
	}
}
예제 #2
0
파일: server.go 프로젝트: fndaily/cockroach
// Start starts the server on the specified port, starts gossip and
// initializes the node using the engines from the server's context.
func (s *Server) Start() error {
	tlsConfig, err := s.ctx.GetServerTLSConfig()
	if err != nil {
		return err
	}

	unresolvedAddr := util.NewUnresolvedAddr("tcp", s.ctx.Addr)
	ln, err := util.ListenAndServe(s.stopper, s, unresolvedAddr, tlsConfig)
	if err != nil {
		return err
	}
	s.listener = ln // Only used in tests.

	if err := officializeAddr(unresolvedAddr, ln.Addr()); err != nil {
		return err
	}

	s.rpcContext.SetLocalServer(s.rpc, unresolvedAddr.String())

	s.grpc = grpc.NewServer()
	s.gossip.Start(s.grpc, unresolvedAddr)

	if err := s.node.start(s.rpc, unresolvedAddr, s.ctx.Engines, s.ctx.NodeAttributes); err != nil {
		return err
	}

	// Begin recording runtime statistics.
	runtime := status.NewRuntimeStatRecorder(s.node.Descriptor.NodeID, s.clock)
	s.tsDB.PollSource(runtime, s.ctx.MetricsFrequency, ts.Resolution10s, s.stopper)

	// Begin recording time series data collected by the status monitor.
	s.recorder = status.NewNodeStatusRecorder(s.node.status, s.clock)
	s.tsDB.PollSource(s.recorder, s.ctx.MetricsFrequency, ts.Resolution10s, s.stopper)

	// Begin recording status summaries.
	s.startWriteSummaries()

	s.sqlServer.SetNodeID(s.node.Descriptor.NodeID)
	// Create and start the schema change manager only after a NodeID
	// has been assigned.
	s.schemaChangeManager = sql.NewSchemaChangeManager(*s.db, s.gossip, s.leaseMgr)
	s.schemaChangeManager.Start(s.stopper)

	s.status = newStatusServer(s.db, s.gossip, s.registry, s.ctx)

	log.Infof("starting %s server at %s", s.ctx.HTTPRequestScheme(), unresolvedAddr)
	s.initHTTP()

	return s.pgServer.Start(util.NewUnresolvedAddr("tcp", s.ctx.PGAddr))
}
예제 #3
0
func (tr *testResolver) GetAddress() (net.Addr, error) {
	defer func() { tr.numTries++ }()
	if tr.numTries < tr.numFails {
		return nil, errors.New("bad address")
	}
	return util.NewUnresolvedAddr("tcp", tr.addr), nil
}
예제 #4
0
파일: server.go 프로젝트: mrtracy/cockroach
func officialAddr(unresolvedAddr string, resolvedAddr net.Addr) (*util.UnresolvedAddr, error) {
	unresolvedHost, unresolvedPort, err := net.SplitHostPort(unresolvedAddr)
	if err != nil {
		return nil, err
	}

	resolvedHost, resolvedPort, err := net.SplitHostPort(resolvedAddr.String())
	if err != nil {
		return nil, err
	}

	var host string
	if unresolvedHost != "" {
		// A host was provided, use it.
		host = unresolvedHost
	} else {
		// A host was not provided. Ask the system, and fall back to the listener.
		if hostname, err := os.Hostname(); err == nil {
			host = hostname
		} else {
			host = resolvedHost
		}
	}

	var port string
	if unresolvedPort != "0" {
		// A port was provided, use it.
		port = unresolvedPort
	} else {
		// A port was not provided, but the system assigned one.
		port = resolvedPort
	}

	return util.NewUnresolvedAddr(resolvedAddr.Network(), net.JoinHostPort(host, port)), nil
}
예제 #5
0
func (tr *testResolver) GetAddress() (net.Addr, error) {
	// Fail 3 times...
	tr.tries++
	if tr.tries < 3 {
		return nil, errors.New("bad address")
	}
	return util.NewUnresolvedAddr("tcp", tr.addr), nil
}
예제 #6
0
func resolveAddress(network, address string) (net.Addr, error) {
	if network == "tcp" {
		_, err := net.ResolveTCPAddr("tcp", address)
		if err != nil {
			return nil, err
		}
		return util.NewUnresolvedAddr("tcp", address), nil
	}
	return nil, util.Errorf("unknown address type: %q", network)
}
예제 #7
0
// TestClientCloseBeforeConnect verifies that the client goroutine
// does not leak if the client is closed before connecting.
func TestClientCloseBeforeConnect(t *testing.T) {
	defer leaktest.AfterTest(t)()

	c := NewClient(
		util.NewUnresolvedAddr("tcp", ":1337"),
		&Context{Stopper: stop.NewStopper()},
	)

	c.Close()
}
예제 #8
0
// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "tcp":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, errors.Errorf("unknown address type: %q", sr.typ)
}
예제 #9
0
파일: socket.go 프로젝트: cuongdo/cockroach
// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "unix":
		addr, err := net.ResolveUnixAddr("unix", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return addr, nil
	case "tcp":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, util.Errorf("unknown address type: %q", sr.typ)
}
예제 #10
0
// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "unix":
		addr, err := net.ResolveUnixAddr("unix", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return addr, nil
	case "tcp", "lb":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		if sr.typ == "tcp" {
			// "tcp" resolvers point to a single host. "lb" have an unknown of number of backends.
			sr.exhausted = true
		}
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, util.Errorf("unknown address type: %q", sr.typ)
}
예제 #11
0
	"github.com/cockroachdb/cockroach/util/leaktest"
)

var testRangeDescriptor = roachpb.RangeDescriptor{
	RangeID:  1,
	StartKey: roachpb.RKey("a"),
	EndKey:   roachpb.RKey("z"),
	Replicas: []roachpb.ReplicaDescriptor{
		{
			NodeID:  1,
			StoreID: 1,
		},
	},
}

var testAddress = util.NewUnresolvedAddr("tcp", "node1")

func makeTestGossip(t *testing.T) (*gossip.Gossip, func()) {
	n := simulation.NewNetwork(1)
	g := n.Nodes[0].Gossip

	if err := g.AddInfo(gossip.KeySentinel, nil, time.Hour); err != nil {
		t.Fatal(err)
	}
	if err := g.AddInfoProto(gossip.KeyFirstRangeDescriptor, &testRangeDescriptor, time.Hour); err != nil {
		t.Fatal(err)
	}
	nodeIDKey := gossip.MakeNodeIDKey(1)
	if err := g.AddInfoProto(nodeIDKey, &roachpb.NodeDescriptor{
		NodeID:  1,
		Address: *testAddress,