use of org.I0Itec.zkclient.exception.ZkInterruptedException 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.ZkInterruptedException in project otter by alibaba.
the class MainstemMonitor method check.
/**
* 检查当前的状态
*/
public boolean check() {
String path = StagePathUtils.getMainStem(getPipelineId());
try {
byte[] bytes = zookeeper.readData(path);
Long nid = ArbitrateConfigUtils.getCurrentNid();
MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
// 更新下为最新值
activeData = eventData;
// 检查下nid是否为自己
boolean result = nid.equals(eventData.getNid());
if (!result) {
logger.warn("mainstem is running in node[{}] , but not in node[{}]", eventData.getNid(), nid);
}
return result;
} catch (ZkNoNodeException e) {
logger.warn("mainstem is not run any in node");
return false;
} catch (ZkInterruptedException e) {
logger.warn("mainstem check is interrupt");
// 清除interrupt标记
Thread.interrupted();
return check();
} catch (ZkException e) {
logger.warn("mainstem check is failed");
return false;
}
}
use of org.I0Itec.zkclient.exception.ZkInterruptedException in project otter by alibaba.
the class NormalTerminProcess method processDelete.
private boolean processDelete(TerminEventData data, boolean noStage, boolean retry) {
Long pipelineId = data.getPipelineId();
Long processId = data.getProcessId();
boolean result = false;
// process节点
// 最后删除一下process节点
String path = StagePathUtils.getProcess(pipelineId, processId);
byte[] bytes = null;
try {
bytes = zookeeper.readData(path);
} catch (ZkNoNodeException e) {
// 说明节点已经被删除了,直接忽略
return false;
}
ProcessNodeEventData nodeData = JsonUtils.unmarshalFromByte(bytes, ProcessNodeEventData.class);
if (nodeData.getStatus().isUsed()) {
if (noStage && nodeData.getMode().isZookeeper()) {
// 针对rpc mode就是没有stage,不需要进行sleep
// 处理一种case:
// 针对两个并发操作,一个已经完成了s/e/t/l模块的所有delete,另一个刚好进来发现没有可delete的
// 这时两个线程就一起进入createTermin操作,存在一些并发问题,针对这种case,需要错开一下
// 不过这种情况可能会有误判,针对s模块没有处理完成,发起了一次rollback/shutdown操作就会碰上,概率比较小,忽略这种误判吧
processDeleteFailed();
// 再重新尝试访问一下process,看下是否已经被删除了
return processDelete(data, false, retry);
}
// 在这段sleep的过程中,process可能还会跑一段,产生新的s/e/t节点,导致process删除失败,从而重复执行了createTermin
if (!retry) {
// modify at 2012-08-14 , 遇到一个并发bug
// 1. 两个process a和b,a先执行完毕删除了process节点,b立马得到触发并在极端的时间内处理完成
// 2. 最后的一个结果b创建的termin要早于a创建的termin,导致termin发送顺序不对
// 这里修改为,先创建termin节点,再删除对应的process,触发下一个process,保证termin创建为顺序
// 同样可以避免删除了process后,termin信号创建失败的问题
// modify at 2012-09-06 , 遇到一个并发bug
// 一个process只完成了s/e模块,然后进行shutdown操作,完成了termin节点创建,但在process delete时,老的process创建了t节点
// 这时会出现process删除失败,从而触发进行一次retry操作,此时retry又会再一次创建了termin信号,导致调度出错
// 所以这里做了一个控制,只有针对非retry模式下才会创建termin信号
// 创建termin节点
result = createTermin(data, pipelineId, processId);
}
}
try {
// 修改为false,已经有另一个线程添加了该节点
result = zookeeper.deleteRecursive(StagePathUtils.getProcess(pipelineId, processId));
if (!result) {
// 做一次重试,可能做manager关闭的时侯,node节点还跑了一段,导致stage节点又创建了一个
doProcess(data, true);
}
} catch (ZkInterruptedException e) {
throw e;
} catch (ZkException e) {
// 做一次重试,可能做manager关闭的时侯,node节点还跑了一段,导致stage节点又创建了一个
doProcess(data, true);
}
return result;
}
use of org.I0Itec.zkclient.exception.ZkInterruptedException in project otter by alibaba.
the class ZkClientx method close.
/**
* Close the client.
*
* @throws ZkInterruptedException
*/
public void close() throws ZkInterruptedException {
if (_connection == null) {
return;
}
LOG.debug("Closing ZkClient...");
getEventLock().lock();
try {
setShutdownTrigger(true);
_eventThread.interrupt();
_eventThread.join(2000);
_connection.close();
_connection = null;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
LOG.debug("Closing ZkClient...done");
}
use of org.I0Itec.zkclient.exception.ZkInterruptedException in project otter by alibaba.
the class ZkClientx method waitForKeeperState.
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit) throws ZkInterruptedException {
if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
}
Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
LOG.debug("Waiting for keeper state " + keeperState);
acquireEventLock();
try {
boolean stillWaiting = true;
while (_currentState != keeperState) {
if (!stillWaiting) {
return false;
}
stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
}
LOG.debug("State is " + _currentState);
return true;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
}
Aggregations