// FindSlaves gets IP addresses for all currently connected slaves. func FindSlaves(mysqld MysqlDaemon) ([]string, error) { qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW PROCESSLIST") if err != nil { return nil, err } addrs := make([]string, 0, 32) for _, row := range qr.Rows { // Check for prefix, since it could be "Binlog Dump GTID". if strings.HasPrefix(row[colCommand].String(), binlogDumpCommand) { host := row[colClientAddr].String() if host == "localhost" { // If we have a local binlog streamer, it will // show up as being connected // from 'localhost' through the local // socket. Ignore it. continue } host, _, err = netutil.SplitHostPort(host) if err != nil { return nil, fmt.Errorf("FindSlaves: malformed addr %v", err) } addrs = append(addrs, host) } } return addrs, nil }
func (tablet *Tablet) Hostname() string { host, _, err := netutil.SplitHostPort(tablet.Addr) if err != nil { panic(err) // should not happen, Addr was checked at creation } return host }
// NewReplicationStatus creates a ReplicationStatus pointing to masterAddr. func NewReplicationStatus(masterAddr string) (*ReplicationStatus, error) { host, port, err := netutil.SplitHostPort(masterAddr) if err != nil { return nil, fmt.Errorf("invalid masterAddr: %q, %v", masterAddr, err) } return &ReplicationStatus{MasterConnectRetry: 10, MasterHost: host, MasterPort: port}, nil }
func EndPointForTablet(tablet *topo.Tablet) (*topo.EndPoint, error) { host, port, err := netutil.SplitHostPort(tablet.Addr) if err != nil { return nil, err } entry := topo.NewAddr(tablet.Uid, host) entry.NamedPortMap["_vtocc"] = port if tablet.SecureAddr != "" { host, port, err = netutil.SplitHostPort(tablet.SecureAddr) if err != nil { return nil, err } entry.NamedPortMap["_vts"] = port } host, port, err = netutil.SplitHostPort(tablet.MysqlAddr) if err != nil { return nil, err } entry.NamedPortMap["_mysql"] = port return entry, nil }
func NewTablet(cell string, uid uint32, parent TabletAlias, vtAddr, mysqlAddr, keyspace, shardId string, tabletType TabletType) (*Tablet, error) { state := STATE_READ_ONLY if tabletType == TYPE_MASTER { state = STATE_READ_WRITE if parent.Uid != NO_TABLET { return nil, fmt.Errorf("master cannot have parent: %v", parent.Uid) } } // check the values for vtAddr and mysqlAddr are correct _, _, err := netutil.SplitHostPort(vtAddr) if err != nil { return nil, err } _, _, err = netutil.SplitHostPort(mysqlAddr) if err != nil { return nil, err } // These value will get resolved on tablet server startup. secureAddr := "" mysqlIpAddr := "" return &Tablet{cell, uid, parent, vtAddr, secureAddr, mysqlAddr, mysqlIpAddr, keyspace, shardId, tabletType, state, "", key.KeyRange{}}, nil }
// FindSlaves gets IP addresses for all currently connected slaves. func FindSlaves(mysqld MysqlDaemon) ([]string, error) { qr, err := mysqld.FetchSuperQuery("SHOW PROCESSLIST") if err != nil { return nil, err } addrs := make([]string, 0, 32) for _, row := range qr.Rows { // Check for prefix, since it could be "Binlog Dump GTID". if strings.HasPrefix(row[colCommand].String(), binlogDumpCommand) { host, _, err := netutil.SplitHostPort(row[colClientAddr].String()) if err != nil { return nil, fmt.Errorf("FindSlaves: malformed addr %v", err) } addrs = append(addrs, host) } } return addrs, nil }
func (conn *Conn) dial() (err error) { // build the endpoint in the right format host, port, err := netutil.SplitHostPort(conn.dbi.Host) if err != nil { return err } endPoint := topo.EndPoint{ Host: host, NamedPortMap: map[string]int{ "_vtocc": port, }, } // and dial tabletConn, err := tabletconn.GetDialer()(nil, endPoint, conn.keyspace(), conn.shard()) if err != nil { return err } conn.tabletConn = tabletConn return }