Exemplo n.º 1
0
// init and get root region server addr and master addr
func (c *client) init() error {
	zkclient, _, err := zk.Connect(c.zkHosts, time.Second*30)
	if err != nil {
		return err
	}
	c.zkClient = zkclient

	res, _, _, err := c.zkClient.GetW(c.zkRoot + zkRootRegionPath)
	if err != nil {
		return err
	}
	c.rootServerName, err = c.decodeMeta(res)
	if err != nil {
		return err
	}
	log.Debug("connect root region server...", c.rootServerName)
	conn, err := newConnection(serverNameToAddr(c.rootServerName), false)
	if err != nil {
		return err
	}
	// set buffered regionserver conn
	c.cachedConns[serverNameToAddr(c.rootServerName)] = conn

	res, _, _, err = c.zkClient.GetW(c.zkRoot + zkMasterAddrPath)
	if err != nil {
		return err
	}
	c.masterServerName, err = c.decodeMeta(res)
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
Arquivo: zk.go Projeto: jinhy/zkhelper
func ConnectToZkWithTimeout(zkAddr string, recvTime time.Duration) (Conn, error) {
	zkConn, _, err := zk.Connect(strings.Split(zkAddr, ","), recvTime)
	if err != nil {
		return nil, err
	}

	return &MyZkConn{Conn: zkConn}, nil
}
Exemplo n.º 3
0
Arquivo: zk.go Projeto: jinhy/zkhelper
func ConnectToZk(zkAddr string) (Conn, error) {
	zkConn, _, err := zk.Connect(strings.Split(zkAddr, ","), 3*time.Second)
	if err != nil {
		return nil, err
	}

	return &MyZkConn{Conn: zkConn}, nil
}
Exemplo n.º 4
0
// init and get root region server addr and master addr
func (c *client) init() error {
	zkclient, _, err := zk.Connect(c.zkHosts, time.Second*30)
	if err != nil {
		return errors.Trace(err)
	}
	c.zkClient = zkclient

	res, _, _, err := c.zkClient.GetW(c.zkRoot + zkRootRegionPath)
	if err != nil {
		return errors.Trace(err)
	}

	c.rootServerName, err = c.decodeMeta(res)
	if err != nil {
		return errors.Trace(err)
	}

	log.Debug("connect root region server...", c.rootServerName)
	serverAddr := serverNameToAddr(c.rootServerName)
	conn, err := newConnection(serverAddr, ClientService)
	if err != nil {
		return errors.Trace(err)
	}

	// Set buffered regionserver conn.
	cachedKey := cachedConnKey(serverAddr, ClientService)
	c.cachedConns[cachedKey] = conn

	res, _, _, err = c.zkClient.GetW(c.zkRoot + zkMasterAddrPath)
	if err != nil {
		return errors.Trace(err)
	}

	c.masterServerName, err = c.decodeMeta(res)
	if err != nil {
		return errors.Trace(err)
	}

	return nil
}