[GitHub] [zookeeper] eolivelli commented on a change in pull request #1091: ZOOKEEPER-3546: Delete empty containers with cversion == 0 after a grace period

2019-09-17 Thread GitBox
eolivelli commented on a change in pull request #1091: ZOOKEEPER-3546: Delete 
empty containers with cversion == 0 after a grace period
URL: https://github.com/apache/zookeeper/pull/1091#discussion_r325115877
 
 

 ##
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/ContainerManager.java
 ##
 @@ -139,14 +140,22 @@ protected long getMinIntervalMs() {
 Set candidates = new HashSet();
 for (String containerPath : zkDb.getDataTree().getContainers()) {
 DataNode node = zkDb.getDataTree().getNode(containerPath);
-/*
-cversion > 0: keep newly created containers from being deleted
-before any children have been added. If you were to create the
-container just before a container cleaning period the container
-would be immediately be deleted.
- */
-if ((node != null) && (node.stat.getCversion() > 0) && 
(node.getChildren().isEmpty())) {
-candidates.add(containerPath);
+boolean wasNewWithNoChildren = 
noChildrenAtLastCheck.remove(containerPath);
+
+if (node != null && node.getChildren().isEmpty()) {
+if (node.stat.getCversion() == 0) {
+// Give newly created containers a grace period and avoid 
deleting
+// them before any children could be added. If you were to 
create the
+// container just before a container cleaning period the 
container
+// would be immediately be deleted.
+if (wasNewWithNoChildren) {
+candidates.add(containerPath);
+} else {
+noChildrenAtLastCheck.add(containerPath);
 
 Review comment:
   At a first glance we are only adding elements and never clearing the 
collection


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [zookeeper] eolivelli commented on a change in pull request #1091: ZOOKEEPER-3546: Delete empty containers with cversion == 0 after a grace period

2019-09-17 Thread GitBox
eolivelli commented on a change in pull request #1091: ZOOKEEPER-3546: Delete 
empty containers with cversion == 0 after a grace period
URL: https://github.com/apache/zookeeper/pull/1091#discussion_r325116122
 
 

 ##
 File path: 
zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateContainerTest.java
 ##
 @@ -237,6 +237,22 @@ public Void call() throws Exception {
 assertEquals(queue.poll(5, TimeUnit.SECONDS), "/four");
 }
 
+@Test(timeout = 3)
+public void testContainerWithNoChildGracePeriod() throws KeeperException, 
InterruptedException {
+zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, 
CreateMode.CONTAINER);
+
+ContainerManager containerManager = new 
ContainerManager(serverFactory.getZooKeeperServer().getZKDatabase(), 
serverFactory.getZooKeeperServer().firstProcessor, 1, 100);
+containerManager.checkContainers();
+Thread.sleep(1000);
+
+assertNotNull("Container should still be there", zk.exists("/foo", 
false));
+
+containerManager.checkContainers();
 
 Review comment:
   Can we avoid this sleep?
   This test may turn into a flaky one


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services