示例#1
0
        /// <summary>
        /// Delete a path and all of its sub nodes
        /// yeah, it's recursive :(
        /// </summary>
        /// <param name="zkClient"></param>
        /// <param name="path"></param>
        /// <param name="filter">For node to be deleted</param>
        /// <returns></returns>
        public static async Task clean(SolrZkClient zkClient, string path, CancellationToken token, Predicate <string> filter = null)
        {
            var paths = new List <string>();

            await traverseZkTree(zkClient, path, VISIT_ORDER.VISIT_POST, znode =>
            {
                if (!znode.Equals("/") && (filter?.Invoke(znode) ?? true))
                {
                    paths.Add(znode);
                }
            });

            foreach (var subpath in paths.OrderByDescending(s => s.Length))
            {
                if (!subpath.Equals("/"))
                {
                    try
                    {
                        token.ThrowIfCancellationRequested();
                        await zkClient.delete(subpath, -1, true);
                    }
                    catch (Exception ex)
                    {
                        if (ex is KeeperException.NotEmptyException || ex is KeeperException.NoNodeException)
                        {
                            //expected
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }