use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.
the class SelectZooKeeperArbitrateEvent method single.
/**
* <pre>
* 算法:
* 1. 创建对应的selected节点,标志selected已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getSelectStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkException e) {
throw new ArbitrateException("Select_single", e.getMessage(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.
the class TransformZooKeeperArbitrateEvent method single.
/**
* <pre>
* 算法:
* 1. 创建对应的transformed节点,标志transform已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getTransformStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] transform ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] transform ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkException e) {
throw new ArbitrateException("transform_single", e.getMessage(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.
the class ExtractZooKeeperArbitrateEvent method single.
/**
* <pre>
* 算法:
* 1. 创建对应的extracted节点,标志extract已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getExtractStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] extract ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] extract ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkInterruptedException e) {
// ignore
} catch (ZkException e) {
throw new ArbitrateException("Extract_single", e.getMessage(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.
the class MainstemMonitor method initMainstem.
public void initMainstem() {
if (isStop()) {
return;
}
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class);
ChannelStatus status = permitMonitor.getChannelPermit(true);
if (status.isStop()) {
// 如果已经关闭则退出
return;
}
Long nid = ArbitrateConfigUtils.getCurrentNid();
String path = StagePathUtils.getMainStem(getPipelineId());
MainStemEventData data = new MainStemEventData();
data.setStatus(MainStemEventData.Status.TAKEING);
data.setPipelineId(getPipelineId());
// 设置当前的nid
data.setNid(nid);
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data);
try {
mutex.set(false);
zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
activeData = data;
// 触发一下事件
processActiveEnter();
mutex.set(true);
} catch (ZkNodeExistsException e) {
bytes = zookeeper.readData(path, true);
if (bytes == null) {
// 如果不存在节点,立即尝试一次
initMainstem();
} else {
activeData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
if (nid.equals(activeData.getNid())) {
// reload时会重复创建,如果是自己就触发一下
mutex.set(true);
}
}
}
}
use of org.I0Itec.zkclient.exception.ZkNodeExistsException in project otter by alibaba.
the class ChannelArbitrateEvent method init.
/**
* 初始化对应的channel节点,同步调用
*/
public void init(Long channelId) {
String path = ManagePathUtils.getChannelByChannelId(channelId);
// 初始化的数据对象
byte[] data = JsonUtils.marshalToByte(ChannelStatus.STOP);
try {
zookeeper.create(path, data, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkNoNodeException e) {
//创建父节点
zookeeper.createPersistent(path, data, true);
} catch (ZkException e) {
throw new ArbitrateException("Channel_init", channelId.toString(), e);
}
}
Aggregations