use of org.apache.zookeeper.KeeperException.BadVersionException in project Saturn by vipshop.
the class ExecutorCleanService method updateJobConfigPreferListContentToRemoveDeletedExecutor.
/**
* delete $Jobs/job/config/preferList content about xxx
*/
private String updateJobConfigPreferListContentToRemoveDeletedExecutor(String jobName, String executorName) throws KeeperException.ConnectionLossException, InterruptedException {
try {
String jobConfigPreferListNodePath = SaturnExecutorsNode.getJobConfigPreferListNodePath(jobName);
Stat stat = new Stat();
byte[] jobConfigPreferListNodeBytes = curatorFramework.getData().storingStatIn(stat).forPath(jobConfigPreferListNodePath);
if (jobConfigPreferListNodeBytes == null || jobConfigPreferListNodeBytes.length == 0) {
return null;
}
// build the new prefer list string
StringBuilder sb = new StringBuilder();
String[] split = new String(jobConfigPreferListNodeBytes, "UTF-8").split(",");
boolean found = false;
for (String tmp : split) {
String tmpTrim = tmp.trim();
if (!tmpTrim.equals(executorName)) {
if (sb.length() > 0) {
sb.append(',');
}
sb.append(tmpTrim);
} else {
found = true;
}
}
curatorFramework.setData().withVersion(stat.getVersion()).forPath(jobConfigPreferListNodePath, sb.toString().getBytes("UTF-8"));
return found ? sb.toString() : null;
} catch (NoNodeException | BadVersionException e) {
// NOSONAR
// ignore
} catch (KeeperException.ConnectionLossException | InterruptedException e) {
throw e;
} catch (Exception e) {
log.error("Clean the executor, updateJobConfigPreferListContentToRemoveDeletedExecutor(" + jobName + ", " + executorName + ") error", e);
}
return null;
}
use of org.apache.zookeeper.KeeperException.BadVersionException in project accumulo by apache.
the class ZooReaderWriterTest method testMutateWithRetryOnSetData.
@Test
public void testMutateWithRetryOnSetData() throws Exception {
final String path = "/foo";
final byte[] value = { 0 };
final byte[] mutatedBytes = { 1 };
Mutator mutator = currentValue -> mutatedBytes;
zrw = createMockBuilder(ZooReaderWriter.class).addMockedMethods("getRetryFactory", "getZooKeeper").createMock();
expect(zrw.getRetryFactory()).andReturn(retryFactory).anyTimes();
expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
Stat stat = new Stat();
zk.create(path, value, ZooUtil.PUBLIC, CreateMode.PERSISTENT);
expectLastCall().andThrow(new NodeExistsException()).once();
expect(zk.getData(path, null, stat)).andReturn(new byte[] { 3 }).times(2);
// BadVersionException should retry
expect(zk.setData(path, mutatedBytes, 0)).andThrow(new ConnectionLossException());
expect(retry.canRetry()).andReturn(true);
retry.useRetry();
expectLastCall();
retry.waitForNextAttempt();
expectLastCall();
// Let 2nd setData succeed
expect(zk.setData(path, mutatedBytes, 0)).andReturn(null);
replay(zk, zrw, retryFactory, retry);
assertArrayEquals(new byte[] { 1 }, zrw.mutateOrCreate(path, value, mutator));
verify(zk, zrw, retryFactory, retry);
}
Aggregations