zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] swallez commented on a change in pull request #1091: ZOOKEEPER-3546: Delete empty containers with cversion == 0 after a grace period
Date Tue, 17 Sep 2019 11:58:49 GMT
swallez 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_r325126124
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/ContainerManager.java
 ##########
 @@ -139,14 +140,22 @@ protected long getMinIntervalMs() {
         Set<String> candidates = new HashSet<String>();
         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:
   Yes, we do it outside of the `getChildren().isEmpty()` test. Children may have been added
since the container was added to that collection, so we need to make sure that containers
with children don't stay in it forever.
   
   ```java
   boolean wasNewWithNoChildren = noChildrenAtLastCheck.remove(containerPath);
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message