Search in sources :

Example 6 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project canal by alibaba.

the class ZooKeeperMetaManager method subscribe.

public void subscribe(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils.getClientIdNodePath(clientIdentity.getDestination(), clientIdentity.getClientId());
    try {
        zkClientx.createPersistent(path, true);
    } catch (ZkNodeExistsException e) {
    // ignore
    }
    if (clientIdentity.hasFilter()) {
        String filterPath = ZookeeperPathUtils.getFilterPath(clientIdentity.getDestination(), clientIdentity.getClientId());
        byte[] bytes = null;
        try {
            bytes = clientIdentity.getFilter().getBytes(ENCODE);
        } catch (UnsupportedEncodingException e) {
            throw new CanalMetaManagerException(e);
        }
        try {
            zkClientx.createPersistent(filterPath, bytes);
        } catch (ZkNodeExistsException e) {
            // ignore
            zkClientx.writeData(filterPath, bytes);
        }
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CanalMetaManagerException(com.alibaba.otter.canal.meta.exception.CanalMetaManagerException)

Example 7 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project canal by alibaba.

the class ClientRunningMonitor method initRunning.

// 改动记录:
// 1,在方法上加synchronized关键字,保证同步顺序执行;
// 2,判断Zk上已经存在的activeData是否是本机,是的话把mutex重置为true,否则会导致死锁
// 3,增加异常处理,保证出现异常时,running节点能被删除,否则会导致死锁
public synchronized void initRunning() {
    if (!isStart()) {
        return;
    }
    String path = ZookeeperPathUtils.getDestinationClientRunning(this.destination, clientData.getClientId());
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(clientData);
    try {
        mutex.set(false);
        zkClient.create(path, bytes, CreateMode.EPHEMERAL);
        // 触发一下事件
        processActiveEnter();
        activeData = clientData;
        mutex.set(true);
    } catch (ZkNodeExistsException e) {
        bytes = zkClient.readData(path, true);
        if (bytes == null) {
            // 如果不存在节点,立即尝试一次
            initRunning();
        } else {
            activeData = JsonUtils.unmarshalFromByte(bytes, ClientRunningData.class);
            // 如果发现已经存在,判断一下是否自己,避免活锁
            if (activeData.getAddress().contains(":") && isMine(activeData.getAddress())) {
                mutex.set(true);
            }
        }
    } catch (ZkNoNodeException e) {
        zkClient.createPersistent(ZookeeperPathUtils.getClientIdNodePath(this.destination, clientData.getClientId()), // 尝试创建父节点
        true);
        initRunning();
    } catch (Throwable t) {
        logger.error(MessageFormat.format("There is an error when execute initRunning method, with destination [{0}].", destination), t);
        // 出现任何异常尝试release
        releaseRunning();
        throw new CanalClientException("something goes wrong in initRunning method. ", t);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) CanalClientException(com.alibaba.otter.canal.protocol.exception.CanalClientException)

Example 8 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.

the class NormalTerminProcess method createTermin.

private boolean createTermin(TerminEventData data, Long pipelineId, Long processId) {
    // 1. 创建end节点
    String path = StagePathUtils.getTermin(pipelineId, processId);
    data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(data);
    try {
        zookeeper.create(path, bytes, CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
        // ignore
        return false;
    } catch (ZkException e) {
        throw new ArbitrateException("Termin_single", e);
    }
    return true;
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 9 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.

the class PipelineArbitrateEvent method init.

/**
     * 初始化对应的pipeline节点,同步调用
     */
public void init(Long channelId, Long pipelineId) {
    String path = ManagePathUtils.getPipeline(channelId, pipelineId);
    String processRootPath = ManagePathUtils.getProcessRoot(channelId, pipelineId);
    String terminRootPath = ManagePathUtils.getTerminRoot(channelId, pipelineId);
    String remedyRootPath = ManagePathUtils.getRemedyRoot(channelId, pipelineId);
    String lockRootPath = ManagePathUtils.getLockRoot(channelId, pipelineId);
    String loadLockPath = lockRootPath + "/" + ArbitrateConstants.NODE_LOCK_LOAD;
    try {
        //创建父节点
        zookeeper.createPersistent(path, true);
        zookeeper.create(processRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(terminRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(remedyRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(lockRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(loadLockPath, new byte[0], CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("Pipeline_init", pipelineId.toString(), e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 10 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.

the class SystemArbitrateEvent method init.

/**
     * 初始化对应的系统节点,同步调用
     */
public void init() {
    String rootPath = ManagePathUtils.getRoot();
    String channelRootPath = ManagePathUtils.getChannelRoot();
    String nodeRootPath = ManagePathUtils.getNodeRoot();
    try {
        zookeeper.create(rootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(channelRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(nodeRootPath, new byte[0], CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("system_init", e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Aggregations

ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)11 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)7 ZkException (org.I0Itec.zkclient.exception.ZkException)7 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 CanalMetaManagerException (com.alibaba.otter.canal.meta.exception.CanalMetaManagerException)1 CanalClientException (com.alibaba.otter.canal.protocol.exception.CanalClientException)1 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)1 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ZkClient (org.I0Itec.zkclient.ZkClient)1 ZkConnection (org.I0Itec.zkclient.ZkConnection)1 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)1 SamzaException (org.apache.samza.SamzaException)1 Before (org.junit.Before)1