SOLR-9346: Always close ZkStateReader

This commit is contained in:
Alan Woodward 2016-07-27 16:45:59 +01:00
parent 22d24969f5
commit 90e9c76851
5 changed files with 195 additions and 188 deletions

View File

@ -16,6 +16,15 @@
*/ */
package org.apache.solr.hadoop; package org.apache.solr.hadoop;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.google.common.io.Files; import com.google.common.io.Files;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.solr.cloud.ZkController; import org.apache.solr.cloud.ZkController;
@ -35,15 +44,6 @@ import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/** /**
* Extracts SolrCloud information from ZooKeeper. * Extracts SolrCloud information from ZooKeeper.
*/ */
@ -78,8 +78,7 @@ final class ZooKeeperInspector {
} }
SolrZkClient zkClient = getZkClient(zkHost); SolrZkClient zkClient = getZkClient(zkHost);
try { try (ZkStateReader zkStateReader = new ZkStateReader(zkClient)) {
ZkStateReader zkStateReader = new ZkStateReader(zkClient);
try { try {
// first check for alias // first check for alias
collection = checkForAlias(zkClient, collection); collection = checkForAlias(zkClient, collection);

View File

@ -16,6 +16,12 @@
*/ */
package org.apache.solr.cloud; package org.apache.solr.cloud;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
@ -36,12 +42,6 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Test split phase that occurs when a Collection API split call is made. * Test split phase that occurs when a Collection API split call is made.
*/ */
@ -254,6 +254,7 @@ public class ChaosMonkeyShardSplitTest extends ShardSplitTest {
address.replaceAll("/", "_")); address.replaceAll("/", "_"));
overseerElector.setup(ec); overseerElector.setup(ec);
overseerElector.joinElection(ec, false); overseerElector.joinElection(ec, false);
reader.close();
return zkClient; return zkClient;
} }

View File

@ -118,6 +118,7 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
if (!zkClient.isClosed()) { if (!zkClient.isClosed()) {
zkClient.close(); zkClient.close();
} }
zkStateReader.close();
} }
} }

View File

@ -130,6 +130,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
} }
} }
deleteNode(ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName); deleteNode(ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName);
zkStateReader.close();
zkClient.close(); zkClient.close();
} }

View File

@ -57,7 +57,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT); zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient); ZkController.createClusterZkNodes(zkClient);
ZkStateReader reader = new ZkStateReader(zkClient); try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate(); reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats()); ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
@ -118,6 +118,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
assertFalse(writer.maybeFlushAfter(c3)); assertFalse(writer.maybeFlushAfter(c3));
assertTrue("different stateFormat, should be flushed", writer.maybeFlushBefore(c2)); assertTrue("different stateFormat, should be flushed", writer.maybeFlushBefore(c2));
assertFalse(writer.maybeFlushAfter(c2)); assertFalse(writer.maybeFlushAfter(c2));
}
} finally { } finally {
IOUtils.close(zkClient); IOUtils.close(zkClient);
@ -140,7 +141,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT); zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient); ZkController.createClusterZkNodes(zkClient);
ZkStateReader reader = new ZkStateReader(zkClient); try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate(); reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats()); ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
@ -158,6 +159,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
assertNotNull(map.get("c1")); assertNotNull(map.get("c1"));
boolean exists = zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true); boolean exists = zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true);
assertFalse(exists); assertFalse(exists);
}
} finally { } finally {
IOUtils.close(zkClient); IOUtils.close(zkClient);
@ -181,7 +183,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT); zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient); ZkController.createClusterZkNodes(zkClient);
ZkStateReader reader = new ZkStateReader(zkClient); try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate(); reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats()); ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
@ -199,6 +201,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
assertNull(map.get("c1")); assertNull(map.get("c1"));
map = (Map) Utils.fromJSON(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true)); map = (Map) Utils.fromJSON(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true));
assertNotNull(map.get("c1")); assertNotNull(map.get("c1"));
}
} finally { } finally {
IOUtils.close(zkClient); IOUtils.close(zkClient);
@ -224,7 +227,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT); zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient); ZkController.createClusterZkNodes(zkClient);
ZkStateReader reader = new ZkStateReader(zkClient); try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate(); reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats()); ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
@ -276,11 +279,12 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// expected // expected
} }
}
} finally { } finally {
IOUtils.close(zkClient); IOUtils.close(zkClient);
server.shutdown(); server.shutdown();
} }
} }
public void testExternalModificationToStateFormat2() throws Exception { public void testExternalModificationToStateFormat2() throws Exception {
@ -298,7 +302,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT); zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient); ZkController.createClusterZkNodes(zkClient);
ZkStateReader reader = new ZkStateReader(zkClient); try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate(); reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats()); ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
@ -361,6 +365,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// expected // expected
} }
}
} finally { } finally {
IOUtils.close(zkClient); IOUtils.close(zkClient);
server.shutdown(); server.shutdown();