Skip to content

Commit 3121b0d

Browse files
committed
ZOOKEEPER-4915: Default znode.container.maxNeverUsedIntervalMs to 5 minutes
This will delete container nodes that never had any children after approximately 5 minutes. > Given this property, you should be prepared to get `KeeperException.NoNodeException` > when creating children inside of this container node Container nodes are supposed to be deleted after all children deleted, so from client's perspective this change has no harm. And also, it leaves no unused nodes in data tree.
1 parent 02e93c2 commit 3121b0d

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,9 @@ Both subsystems need to have sufficient amount of threads to achieve peak read t
21462146
maximum interval in milliseconds that a container that has never had
21472147
any children is retained. Should be long enough for your client to
21482148
create the container, do any needed work and then create children.
2149-
Default is "0" which is used to indicate that containers
2150-
that have never had any children are never deleted.
2149+
Default is "300000"(a.k.a. 5 minutes) since 3.10.0, for earlier versions,
2150+
it is "0" which is used to indicate that containers that have never had
2151+
any children are never deleted.
21512152

21522153
<a name="sc_debug_observability_config"></a>
21532154

zookeeper-server/src/main/java/org/apache/zookeeper/server/ContainerManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ public class ContainerManager {
5050
private final Timer timer;
5151
private final AtomicReference<TimerTask> task = new AtomicReference<>(null);
5252

53+
/**
54+
* @param zkDb the ZK database
55+
* @param requestProcessor request processor - used to inject delete
56+
* container requests
57+
*/
58+
public ContainerManager(ZKDatabase zkDb, RequestProcessor requestProcessor) {
59+
this(
60+
zkDb, requestProcessor,
61+
Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)),
62+
Integer.getInteger("znode.container.maxPerMinute", 10000),
63+
Long.getLong("znode.container.maxNeverUsedIntervalMs", TimeUnit.MINUTES.toMillis(5))
64+
);
65+
}
66+
5367
/**
5468
* @param zkDb the ZK database
5569
* @param requestProcessor request processor - used to inject delete

zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServerMain.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.IOException;
2222
import java.util.concurrent.CountDownLatch;
23-
import java.util.concurrent.TimeUnit;
2423
import javax.management.JMException;
2524
import org.apache.yetus.audience.InterfaceAudience;
2625
import org.apache.zookeeper.audit.ZKAuditProvider;
@@ -168,13 +167,7 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
168167
secureCnxnFactory.startup(zkServer, needStartZKServer);
169168
}
170169

171-
containerManager = new ContainerManager(
172-
zkServer.getZKDatabase(),
173-
zkServer.firstProcessor,
174-
Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)),
175-
Integer.getInteger("znode.container.maxPerMinute", 10000),
176-
Long.getLong("znode.container.maxNeverUsedIntervalMs", 0)
177-
);
170+
containerManager = new ContainerManager(zkServer.getZKDatabase(), zkServer.firstProcessor);
178171
containerManager.start();
179172
ZKAuditProvider.addZKStartStopAuditLog();
180173

zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.zookeeper.server.quorum;
2020

2121
import java.io.IOException;
22-
import java.util.concurrent.TimeUnit;
2322
import java.util.function.Function;
2423
import javax.management.JMException;
2524
import org.apache.zookeeper.KeeperException.SessionExpiredException;
@@ -78,13 +77,7 @@ protected void setupRequestProcessors() {
7877
}
7978

8079
private synchronized void setupContainerManager() {
81-
containerManager = new ContainerManager(
82-
getZKDatabase(),
83-
prepRequestProcessor,
84-
Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)),
85-
Integer.getInteger("znode.container.maxPerMinute", 10000),
86-
Long.getLong("znode.container.maxNeverUsedIntervalMs", 0)
87-
);
80+
containerManager = new ContainerManager(getZKDatabase(), prepRequestProcessor);
8881
}
8982

9083
@Override

0 commit comments

Comments
 (0)