Exemple #1
0
// IPAddr returns the IP address for this instance
func (mysqld *Mysqld) IPAddr() string {
	addr, err := netutil.ResolveIpAddr(mysqld.Addr())
	if err != nil {
		panic(err) // should never happen
	}
	return addr
}
Exemple #2
0
// resolveZkAddr takes a comma-separated list of host:post addresses,
// and resolves the host to replace it with the IP address.
// If a resolution fails, the host is skipped.
// If no host can be resolved, an error is returned.
// This is different fromt he zookeeper C library, that insists on resolving
// *all* hosts before it starts.
func resolveZkAddr(zkAddr string) (string, error) {
	parts := strings.Split(zkAddr, ",")
	resolved := make([]string, 0, len(parts))
	for _, part := range parts {
		if r, err := netutil.ResolveIpAddr(part); err != nil {
			log.Infof("cannot resolve %v, will not use it: %v", part, err)
		} else {
			resolved = append(resolved, r)
		}
	}
	if len(resolved) == 0 {
		return "", fmt.Errorf("no valid address found in %v", zkAddr)
	}
	return strings.Join(resolved, ","), nil
}
Exemple #3
0
// bindAddr: the address for the query service advertised by this agent
func (agent *ActionAgent) Start(bindAddr, secureAddr, mysqlAddr string) error {
	var err error
	if err = agent.readTablet(); err != nil {
		return err
	}

	if err = agent.resolvePaths(); err != nil {
		return err
	}

	bindAddr, err = netutil.ResolveAddr(bindAddr)
	if err != nil {
		return err
	}
	if secureAddr != "" {
		secureAddr, err = netutil.ResolveAddr(secureAddr)
		if err != nil {
			return err
		}
	}
	mysqlAddr, err = netutil.ResolveAddr(mysqlAddr)
	if err != nil {
		return err
	}
	mysqlIpAddr, err := netutil.ResolveIpAddr(mysqlAddr)
	if err != nil {
		return err
	}

	// Update bind addr for mysql and query service in the tablet node.
	f := func(tablet *topo.Tablet) error {
		tablet.Addr = bindAddr
		tablet.SecureAddr = secureAddr
		tablet.MysqlAddr = mysqlAddr
		tablet.MysqlIpAddr = mysqlIpAddr
		return nil
	}
	if err := agent.ts.UpdateTabletFields(agent.Tablet().Alias(), f); err != nil {
		return err
	}

	// Reread in case there were changes
	if err := agent.readTablet(); err != nil {
		return err
	}

	hostname, err := os.Hostname()
	if err != nil {
		return fmt.Errorf("agent.Start: cannot get hostname: %v", err)
	}
	data := fmt.Sprintf("host:%v\npid:%v\n", hostname, os.Getpid())

	if err := agent.ts.CreateTabletPidNode(agent.tabletAlias, data, agent.done); err != nil {
		return err
	}

	if err = agent.verifyTopology(); err != nil {
		return err
	}

	if err = agent.verifyServingAddrs(); err != nil {
		return err
	}

	oldTablet := &topo.Tablet{}
	agent.runChangeCallbacks(oldTablet, "Start")

	go agent.actionEventLoop()
	return nil
}