Ejemplo n.º 1
0
// Bootstrap starts communication for this Ringpop instance.
//
// When Bootstrap is called, this Ringpop instance will attempt to contact
// other instances from a seed list provided either in the BootstrapOptions or
// as a JSON file.
//
// If no seed hosts are provided, a single-node cluster will be created.
func (rp *Ringpop) Bootstrap(userBootstrapOpts *swim.BootstrapOptions) ([]string, error) {
	if rp.getState() < initialized {
		err := rp.init()
		if err != nil {
			return nil, err
		}
	}

	identity, err := rp.identity()
	if err != nil {
		return nil, err
	}

	// If the user has provided a list of hosts (and not a bootstrap file),
	// check we're in the bootstrap host list and add ourselves if we're not
	// there. If the host list is empty, this will create a single-node
	// cluster.
	bootstrapOpts := *userBootstrapOpts
	if len(bootstrapOpts.File) == 0 && !util.StringInSlice(bootstrapOpts.Hosts, identity) {
		bootstrapOpts.Hosts = append(bootstrapOpts.Hosts, identity)
	}

	joined, err := rp.node.Bootstrap(&bootstrapOpts)
	if err != nil {
		rp.logger.WithField("error", err).Info("bootstrap failed")
		rp.setState(initialized)
		return nil, err
	}

	rp.setState(ready)

	rp.logger.WithField("joined", joined).Info("bootstrap complete")
	return joined, nil
}
Ejemplo n.º 2
0
// potential nodes are nodes that can be joined that are not the local node
func (j *joinSender) CollectPotentialNodes(nodesJoined []string) []string {
	if nodesJoined == nil {
		nodesJoined = make([]string, 0)
	}

	var potentialNodes []string

	for _, hostports := range j.bootstrapHostsMap {
		for _, hostport := range hostports {
			if j.node.address != hostport && !util.StringInSlice(nodesJoined, hostport) {
				potentialNodes = append(potentialNodes, hostport)
			}
		}
	}

	return potentialNodes
}