Commit c4996872 authored by Flavio Paiva Junqueira's avatar Flavio Paiva Junqueira
Browse files

ZOOKEEPER-1852. ServerCnxnFactory instance is not properly cleanedup (Rakesh R via fpj)



git-svn-id: https://svn.apache.org/repos/asf/zookeeper/branches/branch-3.4@1554979 13f79535-47bb-0310-9956-ffa450edef68
parent a53304ea
......@@ -209,6 +209,9 @@ BUGFIXES:
socket on 4 letter word requests (Rakesh R, Germán Blanco
via fpj)
ZOOKEEPER-1852. ServerCnxnFactory instance is not properly
cleanedup (Rakesh R via fpj)
IMPROVEMENTS:
......
......@@ -324,20 +324,25 @@ public abstract class ClientBase extends ZKTestCase {
return Integer.parseInt(portstr);
}
public static ServerCnxnFactory createNewServerInstance(File dataDir,
ServerCnxnFactory factory, String hostPort, int maxCnxns)
throws IOException, InterruptedException
{
public static void startServerInstance(File dataDir,
ServerCnxnFactory factory, String hostPort) throws IOException,
InterruptedException {
final int port = getPort(hostPort);
LOG.info("STARTING server instance 127.0.0.1:{}", port);
ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
final int PORT = getPort(hostPort);
if (factory == null) {
factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
}
factory.startup(zks);
Assert.assertTrue("waiting for server up",
ClientBase.waitForServerUp("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
"127.0.0.1:" + port, CONNECTION_TIMEOUT));
}
public static ServerCnxnFactory createNewServerInstance(
ServerCnxnFactory factory, String hostPort, int maxCnxns)
throws IOException, InterruptedException {
final int port = getPort(hostPort);
LOG.info("CREATING server instance 127.0.0.1:{}", port);
if (factory == null) {
factory = ServerCnxnFactory.createFactory(port, maxCnxns);
}
return factory;
}
......@@ -345,15 +350,18 @@ public abstract class ClientBase extends ZKTestCase {
String hostPort)
{
if (factory != null) {
ZKDatabase zkDb;
ZKDatabase zkDb = null;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
if (zs != null) {
zkDb = zs.getZKDatabase();
}
}
factory.shutdown();
try {
zkDb.close();
if (zkDb != null) {
zkDb.close();
}
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
......@@ -411,7 +419,9 @@ public abstract class ClientBase extends ZKTestCase {
protected void startServer() throws Exception {
LOG.info("STARTING server");
serverFactory = createNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns);
serverFactory = createNewServerInstance(serverFactory, hostPort,
maxCnxns);
startServerInstance(tmpDir, serverFactory, hostPort);
// ensure that only server and data bean are registered
JMXEnv.ensureOnly("InMemoryDataTree", "StandaloneServer_port");
}
......
......@@ -128,7 +128,10 @@ public class TruncateTest extends ZKTestCase {
public void testTruncate() throws IOException, InterruptedException, KeeperException {
// Prime the server that is going to come in late with 50 txns
String hostPort = "127.0.0.1:" + baseHostPort;
ServerCnxnFactory factory = ClientBase.createNewServerInstance(dataDir1, null, hostPort, 100);
int maxCnxns = 100;
ServerCnxnFactory factory = ClientBase.createNewServerInstance(null,
hostPort, maxCnxns);
ClientBase.startServerInstance(dataDir1, factory, hostPort);
ClientBase.shutdownServerInstance(factory, hostPort);
// standalone starts with 0 epoch while quorum starts with 1
......@@ -136,7 +139,8 @@ public class TruncateTest extends ZKTestCase {
File newfile = new File(new File(dataDir1, "version-2"), "snapshot.100000000");
origfile.renameTo(newfile);
factory = ClientBase.createNewServerInstance(dataDir1, null, hostPort, 100);
factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns);
ClientBase.startServerInstance(dataDir1, factory, hostPort);
ZooKeeper zk = new ZooKeeper(hostPort, 15000, nullWatcher);
for(int i = 0; i < 50; i++) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment