-
Notifications
You must be signed in to change notification settings - Fork 242
Create a custom ContainerManager for purging the TTL based znodes #3038
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,4 +150,13 @@ public void shutdown() { | |
| public ZkClient getZkClient() { | ||
| return _zkClient; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ZooKeeper server instance. | ||
| * @return The ZooKeeper server instance | ||
| */ | ||
| public ZooKeeperServer getZooKeeperServer() { | ||
| return _zk; | ||
| } | ||
|
Comment on lines
+158
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you using Helix style to format it? It looked wired. For the place you touched, we should fix it. Maybe it was not handled before.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @junkaixue , What do we mean by "helix style" here? I had earlier formatted the method in same way just as the getZkClient method above this. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,16 +22,22 @@ | |
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.lang.management.ManagementFactory; | ||
| import java.lang.reflect.Field; | ||
| import java.util.Map; | ||
|
|
||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| import javax.management.MBeanServerConnection; | ||
| import javax.management.ObjectName; | ||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.helix.zookeeper.constant.TestConstants; | ||
| import org.apache.helix.zookeeper.zkclient.IDefaultNameSpace; | ||
| import org.apache.helix.zookeeper.zkclient.ZkServer; | ||
| import org.apache.zookeeper.server.ContainerManager; | ||
| import org.apache.zookeeper.server.DataNode; | ||
| import org.apache.zookeeper.server.RequestProcessor; | ||
| import org.apache.zookeeper.server.ZooKeeperServer; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
|
|
@@ -60,8 +66,18 @@ public class ZkTestBase { | |
| */ | ||
| // The following maps hold ZK connect string as keys | ||
| protected static final Map<String, ZkServer> _zkServerMap = new ConcurrentHashMap<>(); | ||
| protected static final Map<ZkServer, ContainerManager> _zkServerContainerManagerMap = new ConcurrentHashMap<>(); | ||
| protected static AtomicLong _fakeElapsed = new AtomicLong(0); | ||
| protected static int _numZk = 1; // Initial value | ||
|
|
||
| /** | ||
| * Advances the fake elapsed time used by the ContainerManager | ||
| * @param additionalTime time to add in milliseconds | ||
| */ | ||
| public static void advanceFakeElapsedTime(long additionalTime) { | ||
| _fakeElapsed.addAndGet(additionalTime); | ||
| } | ||
|
|
||
| @BeforeSuite | ||
| public void beforeSuite() throws IOException { | ||
| // Due to ZOOKEEPER-2693 fix, we need to specify whitelist for execute zk commends | ||
|
|
@@ -91,6 +107,9 @@ public void afterSuite() throws IOException { | |
| } | ||
| } | ||
|
|
||
| // Shut down ContainerManagers | ||
| _zkServerContainerManagerMap.values().forEach(ContainerManager::stop); | ||
|
|
||
| // Shut down all ZkServers | ||
| _zkServerMap.values().forEach(ZkServer::shutdown); | ||
| } | ||
|
|
@@ -115,6 +134,36 @@ private void setupZooKeepers() { | |
| for (int i = 0; i < _numZk; i++) { | ||
| String zkAddress = ZK_PREFIX + (ZK_START_PORT + i); | ||
| _zkServerMap.computeIfAbsent(zkAddress, ZkTestBase::startZkServer); | ||
| _zkServerContainerManagerMap.computeIfAbsent(_zkServerMap.get(zkAddress), ZkTestBase::createContainerManager); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a ContainerManager with custom elapsed time functionality for a ZkServer | ||
| */ | ||
| private static ContainerManager createContainerManager(ZkServer zkServer) { | ||
LZD-PratyushBhatt marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function has been repeated. Better make it as Util or in base class.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One is in helix-core module and other is in zookeeper-api. And in zookeeper-api I dont see any packaging of test classes being done. So if we make this common then we will need to modify pom.xml in some places. |
||
| try { | ||
| ZooKeeperServer zooKeeperServer = zkServer.getZooKeeperServer(); | ||
|
|
||
| Field firstProcessorField = ZooKeeperServer.class.getDeclaredField("firstProcessor"); | ||
| firstProcessorField.setAccessible(true); | ||
| RequestProcessor firstProcessor = (RequestProcessor) firstProcessorField.get(zooKeeperServer); | ||
|
|
||
| // Create a ContainerManager with a custom elapsed time logic | ||
| return new ContainerManager( | ||
| zooKeeperServer.getZKDatabase(), | ||
| firstProcessor, | ||
| 10, // Check interval in ms | ||
| 100, // Max containers to check per interval | ||
| 10 // the max time in milliseconds that a container that has never had any children is retained | ||
| ) { | ||
| @Override | ||
| protected long getElapsed(DataNode node) { | ||
| return _fakeElapsed.get(); | ||
| } | ||
| }; | ||
| } catch (NoSuchFieldException | IllegalAccessException e) { | ||
| throw new RuntimeException("Failed to access firstProcessor field in ZooKeeperServer", e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.