private String protectedPathInForeground(String adjustedPath, byte[] data) { try { return(pathInForeground(adjustedPath, data)); } catch (Exception e) { ThreadUtils.checkInterrupted(e); if ((e is KeeperException.ConnectionLossException || !(e is KeeperException)) && protectedId != null) { /* * CURATOR-45 + CURATOR-79: we don't know if the create operation was successful or not, * register the znode to be sure it is deleted later. */ new FindAndDeleteProtectedNodeInBackground(client, ZKPaths.getPathAndNode(adjustedPath).getPath(), protectedId).execute(); /* * The current UUID is scheduled to be deleted, it is not safe to use it again. * If this builder is used again later create a new UUID */ protectedId = Guid.NewGuid().ToString(); } throw e; } }
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 static IEnumerable <string> GetParticipantNodes(IZooKeeper client, string basePath, string lockName, ILockInternalsSorter sorter) { var names = GetSortedChildren(client, basePath, lockName, sorter); var transformed = names.Select(x => ZKPaths.MakePath(basePath, x)); return(transformed); }
public LockInternals(IZooKeeper client, ILockInternalsDriver driver, string path, string lockName, int maxLeases) { _driver = driver; _lockName = lockName; _maxLeases = maxLeases; PathUtils.ValidatePath(path); _client = client; _basePath = path; _path = ZKPaths.MakePath(path, lockName); }
internal String unfixForNamespace(String path) { if ((@namespace != null) && (path != null)) { String namespacePath = ZKPaths.makePath(@namespace, null); if (path.StartsWith(namespacePath)) { path = (path.Length > namespacePath.Length) ? path.Substring(namespacePath.Length) : "/"; } } return(path); }
private void DoWork() { foreach (string path in paths) { try { IList <string> children = client.GetChildren().ForPath(path); foreach (string name in children) { string thisPath = ZKPaths.MakePath(path, name); Stat stat = client.CheckExists().ForPath(thisPath); if ((stat != null) && (stat.GetNumChildren() == 0)) { reaper.AddPath(thisPath, mode); } } } catch (Exception e) { log.Error("Could not get children for path: " + path, e); } } }
public string AttemptLock(TimeSpan?timeout, byte[] lockNodeBytes) { var startTime = DateTime.UtcNow; var retryCount = 0; string ourPath = null; var hasTheLock = false; var isDone = false; while (!isDone) { isDone = true; try { ZKPaths.Mkdirs(Client, _path, false); ourPath = Client.Create(_path, lockNodeBytes, Driver.Acl ?? Ids.OPEN_ACL_UNSAFE, CreateMode.EphemeralSequential); hasTheLock = InternalLockLoop(startTime, timeout, ourPath); } catch (KeeperException.NoNodeException) { // gets thrown by StandardLockInternalsDriver when it can't find the lock node // this can happen when the session expires, etc. So, if the retry allows, just try it all again if (RetryPolicy.AllowRetry(retryCount++, DateTime.UtcNow - startTime)) { isDone = false; } else { throw; } } } return(hasTheLock ? ourPath : null); }
public virtual string ToPath() { var dict = new SortedDictionary <int, string>(); foreach (var pro in this.GetType().GetProperties()) { var cusAttrs = pro.GetCustomAttributes(typeof(NodePathOrderAttribute), false); if (cusAttrs != null && cusAttrs.Length > 0) { var val = pro.GetValue(this) ?? string.Empty; dict.Add(((NodePathOrderAttribute)cusAttrs.First()).Order, val.ToString()); } } var ret = "/"; foreach (var item in dict) { ret = ZKPaths.MakePath(ret, item.Value); } return(ret); }
private bool InternalLockLoop(DateTime startTime, TimeSpan?timeToWait, String ourPath) { var haveTheLock = false; var doDelete = false; try { while ((Client.State == ZooKeeper.States.CONNECTED) && !haveTheLock) { var children = GetSortedChildren(); var sequenceNodeName = ourPath.Substring(_basePath.Length + 1); // +1 to include the slash var predicateResults = Driver.GetsTheLock(Client, children, sequenceNodeName, MaxLeases); if (predicateResults.GetsTheLock) { haveTheLock = true; } else { var previousSequencePath = ZKPaths.MakePath(_basePath, predicateResults.PathToWatch); // synchronized(this) { var stat = Client.Exists(previousSequencePath, this); if (stat != null) { if (timeToWait.HasValue) { var remainingTimeToWait = RemainingTime(startTime, timeToWait.Value); if (remainingTimeToWait <= TimeSpan.Zero) { doDelete = true; // timed out - delete our node break; } _watcherEvent.WaitOne(remainingTimeToWait); } else { _watcherEvent.WaitOne(-1); } } } // else it may have been deleted (i.e. lock released). Try to acquire again } } } catch (Exception) { doDelete = true; throw; } finally { if (doDelete) { DeleteOurPath(ourPath); } } return(haveTheLock); }
public void createContainers(String path) { checkExists().creatingParentContainersIfNeeded().forPath(ZKPaths.makePath(path, "foo")); }