Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CURATOR-430] deletingChildrenIfNeeded maybe cannot delete children completely when multi-client delete concurrently #235

Merged
merged 3 commits into from
Sep 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,13 @@ public static void deleteChildren(ZooKeeper zookeeper, String path, boolean dele
{
PathUtils.validatePath(path);

List<String> children = zookeeper.getChildren(path, null);
List<String> children;
try {
children = zookeeper.getChildren(path, null);
} catch (KeeperException.NoNodeException e) {
// someone else has deleted the node since we checked
return;
}
for ( String child : children )
{
String fullPath = makePath(path, child);
Expand All @@ -333,7 +339,7 @@ public static void deleteChildren(ZooKeeper zookeeper, String path, boolean dele
}
catch ( KeeperException.NoNodeException e )
{
// ignore... someone else has deleted the node it since we checked
// ignore... someone else has deleted the node since we checked
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,57 @@ public void testStopped() throws Exception
// correct
}
}

@Test
public void testDeleteChildrenConcurrently() throws Exception {
final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
CuratorFramework client2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
try {
client.start();
client.getZookeeperClient().blockUntilConnectedOrTimedOut();
client2.start();
client2.getZookeeperClient().blockUntilConnectedOrTimedOut();

int childCount = 5000;
for (int i = 0; i < childCount; i++) {
client.create().creatingParentsIfNeeded().forPath("/parent/child" + i);
}

final CountDownLatch countDownLatch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
client.delete().deletingChildrenIfNeeded().forPath("/parent");
} catch (Exception e) {
if (e instanceof KeeperException.NoNodeException) {
Assert.fail("client delete failed, shouldn't throw NoNodeException", e);
} else {
Assert.fail("unknown exception", e);
}
} finally {
countDownLatch.countDown();
}
}
}).start();

Thread.sleep(20L);
try {
client2.delete().forPath("/parent/child" + (childCount/2));
} catch (Exception e) {
if (e instanceof KeeperException.NoNodeException) {
Assert.fail("client2 delete failed, shouldn't throw NoNodeException", e);
} else {
Assert.fail("unknown exception", e);
}
}

Assert.assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));

Assert.assertNull(client2.checkExists().forPath("/parent"));
} finally {
CloseableUtils.closeQuietly(client);
CloseableUtils.closeQuietly(client2);
}
}
}