public ICollection <CuratorTransactionResult> commit() { CheckAlreadyCommited(); isCommitted = true; AtomicBoolean firstTime = new AtomicBoolean(true); List <OpResult> resultList = RetryLoop.callWithRetry ( client.getZookeeperClient(), CallableUtils.FromFunc(() => doOperation(firstTime))); if (resultList.Count != transaction.metadataSize()) { throw new InvalidOperationException(String.Format("Result size ({0}) doesn't match input size ({1})", resultList.Count, transaction.metadataSize())); } var builder = new ReadOnlyCollectionBuilder <CuratorTransactionResult>(); for (int i = 0; i < resultList.Count; ++i) { OpResult opResult = resultList[i]; CuratorMultiTransactionRecord.TypeAndPath metadata = transaction.getMetadata(i); CuratorTransactionResult curatorResult = makeCuratorResult(opResult, metadata); builder.Add(curatorResult); } return(builder.ToReadOnlyCollection()); }
internal String fixForNamespace(String path, bool isSequential) { if (ensurePathNeeded.get()) { try { CuratorZookeeperClient zookeeperClient = client.getZookeeperClient(); RetryLoop.callWithRetry ( zookeeperClient, CallableUtils.FromFunc <object>(() => { ZKPaths.mkdirs(zookeeperClient.getZooKeeper(), ZKPaths.makePath("/", @namespace), true, client.getAclProvider(), true); return(null); }) ); ensurePathNeeded.set(false); } catch (Exception e) { ThreadUtils.checkInterrupted(e); client.logError("Ensure path threw exception", e); } } return(ZKPaths.fixForNamespace(@namespace, path, isSequential)); }
public void ensure(CuratorZookeeperClient client, string path, bool makeLastNode) { lock (this) { if (!isSet) { RetryLoop.callWithRetry ( client, CallableUtils.FromFunc <object>(() => { ZKPaths.mkdirs(client.getZooKeeper(), path, makeLastNode, _ensurePath.aclProvider, _ensurePath.asContainers()); _ensurePath.helper.Set(doNothingHelper); isSet = true; return(null); }) ); } } }
public void testBasic() { CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts, DefaultSessionTimeout, DefaultConnectionTimeout, null, new RetryOneTime(1)); SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL); retryLoop.start(); try { client.start(); try { while (retryLoop.shouldContinue()) { try { RetryLoop.callWithRetry ( client, CallableUtils.FromFunc <object>(() => { Task <Stat> existsTask = client.getZooKeeper().existsAsync("/foo/bar", false); existsTask.Wait(); Assert.Null(existsTask.Result); KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout); client.getZooKeeper(); client.blockUntilConnectedOrTimedOut(); existsTask = client.getZooKeeper().existsAsync("/foo/bar", false); existsTask.Wait(); Assert.Null(existsTask.Result); return(null); } )); } catch (Exception e) { retryLoop.takeException(e); } } Assert.Fail(); } catch (SessionFailRetryLoop.SessionFailedException dummy) { // correct } } finally { retryLoop.Dispose(); CloseableUtils.closeQuietly(client); } }
private Stat pathInForeground(string path, byte[] data) { TimeTrace trace = client.getZookeeperClient().startTracer("SetDataBuilderImpl-Foreground"); Stat resultStat = RetryLoop.callWithRetry ( client.getZookeeperClient(), CallableUtils.FromFunc(() => { Task <Stat> task = client.getZooKeeper().setDataAsync(path, data, version); task.Wait(); return(task.Result); }) ); trace.commit(); return(resultStat); }
public byte[] forPath(String path) { String localPath = client.fixForNamespace(path); TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Foreground"); byte[] responseData = RetryLoop.callWithRetry ( client.getZookeeperClient(), CallableUtils.FromFunc(() => { var dataAsync = client.getZooKeeper().getDataAsync(localPath, false); dataAsync.Wait(); responseStat = dataAsync.Result.Stat; return(dataAsync.Result.Data); }) ); trace.commit(); return(decompress ? client.getCompressionProvider().decompress(path, responseData) : responseData); }
public void testRetryStatic() { CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts, DefaultSessionTimeout, DefaultConnectionTimeout, null, new RetryOneTime(1)); SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.RETRY); retryLoop.start(); try { client.start(); AtomicBoolean secondWasDone = new AtomicBoolean(false); AtomicBoolean firstTime = new AtomicBoolean(true); SessionFailRetryLoop.callWithRetry ( client, SessionFailRetryLoop.Mode.RETRY, CallableUtils.FromFunc <object>(() => { RetryLoop.callWithRetry( client, CallableUtils.FromFunc <object>(() => { Task <Stat> existsTask; if (firstTime.compareAndSet(true, false)) { existsTask = client.getZooKeeper().existsAsync("/foo/bar", false); existsTask.Wait(); Assert.Null(existsTask.Result); KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout); client.getZooKeeper(); client.blockUntilConnectedOrTimedOut(); } existsTask = client.getZooKeeper().existsAsync("/foo/bar", false); existsTask.Wait(); Assert.Null(existsTask.Result); return(null); } )); RetryLoop.callWithRetry ( client, CallableUtils.FromFunc <object>(() => { Assert.False(firstTime.get()); Task <Stat> existsTask = client.getZooKeeper().existsAsync("/foo/bar", false); existsTask.Wait(); Assert.Null(existsTask.Result); secondWasDone.set(true); return(null); } )); return(null); } )); Assert.True(secondWasDone.get()); } finally { retryLoop.Dispose(); CloseableUtils.closeQuietly(client); } }
public void testExpiredSession() { // WARN: test requires that this must be address of one ZK host, // not a connection string to many nodes Barrier expiresBarrier = new Barrier(2); Watcher watcher = new ExpiredWatcher(expiresBarrier); CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts, DefaultSessionTimeout, DefaultConnectionTimeout, watcher, new RetryOneTime(2)); client.start(); try { AtomicBoolean firstTime = new AtomicBoolean(true); RetryLoop.callWithRetry( client, CallableUtils.FromFunc <object>(() => { if (firstTime.compareAndSet(true, false)) { try { Task <string> createTask = client.getZooKeeper() .createAsync("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); createTask.Wait(); } catch (AggregateException e) { if (e.InnerException is KeeperException.NodeExistsException) { // ignore } else { throw e; } } KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout * 3); Assert.True(expiresBarrier.SignalAndWait(DefaultSessionTimeout)); } ZooKeeper zooKeeper = client.getZooKeeper(); client.blockUntilConnectedOrTimedOut(); Task <Stat> task = zooKeeper.existsAsync("/foo", false); task.Wait(); Stat stat = task.Result; Assert.NotNull(stat); Assert.Greater(stat.getCzxid(), 0); return(null); }) ); } finally { client.Dispose(); } }