mirror of https://github.com/apache/lucene.git
SOLR-9346: Always close ZkStateReader
This commit is contained in:
parent
22d24969f5
commit
90e9c76851
|
@ -16,6 +16,15 @@
|
|||
*/
|
||||
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 org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.cloud.ZkController;
|
||||
|
@ -35,15 +44,6 @@ import org.apache.zookeeper.KeeperException;
|
|||
import org.slf4j.Logger;
|
||||
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.
|
||||
*/
|
||||
|
@ -78,8 +78,7 @@ final class ZooKeeperInspector {
|
|||
}
|
||||
SolrZkClient zkClient = getZkClient(zkHost);
|
||||
|
||||
try {
|
||||
ZkStateReader zkStateReader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader zkStateReader = new ZkStateReader(zkClient)) {
|
||||
try {
|
||||
// first check for alias
|
||||
collection = checkForAlias(zkClient, collection);
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
*/
|
||||
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.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
@ -36,12 +42,6 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
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.
|
||||
*/
|
||||
|
@ -254,6 +254,7 @@ public class ChaosMonkeyShardSplitTest extends ShardSplitTest {
|
|||
address.replaceAll("/", "_"));
|
||||
overseerElector.setup(ec);
|
||||
overseerElector.joinElection(ec, false);
|
||||
reader.close();
|
||||
return zkClient;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
|
|||
if (!zkClient.isClosed()) {
|
||||
zkClient.close();
|
||||
}
|
||||
zkStateReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
}
|
||||
deleteNode(ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName);
|
||||
zkStateReader.close();
|
||||
zkClient.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
|
||||
ZkController.createClusterZkNodes(zkClient);
|
||||
|
||||
ZkStateReader reader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
|
||||
reader.createClusterStateWatchersAndUpdate();
|
||||
|
||||
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
|
||||
|
@ -103,7 +103,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
clusterState = writer.enqueueUpdate(clusterState, c3, null);
|
||||
|
||||
// simulate three state changes in c3, all should be batched
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
assertFalse(writer.maybeFlushBefore(c3));
|
||||
assertFalse(writer.maybeFlushAfter(c3));
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
assertFalse(writer.maybeFlushAfter(c3));
|
||||
assertTrue("different stateFormat, should be flushed", writer.maybeFlushBefore(c2));
|
||||
assertFalse(writer.maybeFlushAfter(c2));
|
||||
}
|
||||
|
||||
} finally {
|
||||
IOUtils.close(zkClient);
|
||||
|
@ -140,7 +141,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
|
||||
ZkController.createClusterZkNodes(zkClient);
|
||||
|
||||
ZkStateReader reader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
|
||||
reader.createClusterStateWatchersAndUpdate();
|
||||
|
||||
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
|
||||
|
@ -158,6 +159,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
assertNotNull(map.get("c1"));
|
||||
boolean exists = zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true);
|
||||
assertFalse(exists);
|
||||
}
|
||||
|
||||
} finally {
|
||||
IOUtils.close(zkClient);
|
||||
|
@ -181,7 +183,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
|
||||
ZkController.createClusterZkNodes(zkClient);
|
||||
|
||||
ZkStateReader reader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
|
||||
reader.createClusterStateWatchersAndUpdate();
|
||||
|
||||
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
|
||||
|
@ -199,6 +201,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
assertNull(map.get("c1"));
|
||||
map = (Map) Utils.fromJSON(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true));
|
||||
assertNotNull(map.get("c1"));
|
||||
}
|
||||
|
||||
} finally {
|
||||
IOUtils.close(zkClient);
|
||||
|
@ -224,7 +227,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
|
||||
ZkController.createClusterZkNodes(zkClient);
|
||||
|
||||
ZkStateReader reader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
|
||||
reader.createClusterStateWatchersAndUpdate();
|
||||
|
||||
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
|
||||
|
@ -276,11 +279,12 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
}
|
||||
} finally {
|
||||
IOUtils.close(zkClient);
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testExternalModificationToStateFormat2() throws Exception {
|
||||
|
@ -298,7 +302,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
|
||||
ZkController.createClusterZkNodes(zkClient);
|
||||
|
||||
ZkStateReader reader = new ZkStateReader(zkClient);
|
||||
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
|
||||
reader.createClusterStateWatchersAndUpdate();
|
||||
|
||||
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
|
||||
|
@ -361,6 +365,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
|
|||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
IOUtils.close(zkClient);
|
||||
server.shutdown();
|
||||
|
|
Loading…
Reference in New Issue