You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2012/01/06 22:13:03 UTC
svn commit: r1228412 - in /lucene/dev/branches/solrcloud/solr:
core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java
solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java
solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java
Author: markrmiller
Date: Fri Jan 6 21:13:02 2012
New Revision: 1228412
URL: http://svn.apache.org/viewvc?rev=1228412&view=rev
Log:
retry on connection loss when setting up tests
Modified:
lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java
lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java
lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java
Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java?rev=1228412&r1=1228411&r2=1228412&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/AbstractZkTestCase.java Fri Jan 6 21:13:02 2012
@@ -18,16 +18,20 @@ package org.apache.solr.cloud;
*/
import java.io.File;
+import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkCmdExecutor;
import org.apache.solr.common.cloud.ZkNodeProps;
+import org.apache.solr.common.cloud.ZkOperation;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.SolrConfig;
import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@@ -76,33 +80,72 @@ public abstract class AbstractZkTestCase
zkClient.close();
zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);
+ final ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(zkClient);
Map<String,String> props = new HashMap<String,String>();
props.put("configName", "conf1");
- ZkNodeProps zkProps = new ZkNodeProps(props);
- zkClient.makePath("/collections/collection1", ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT);
- zkClient.makePath("/collections/collection1/shards", CreateMode.PERSISTENT);
-
- zkClient.makePath("/collections/control_collection", ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT);
- zkClient.makePath("/collections/control_collection/shards", CreateMode.PERSISTENT);
-
- putConfig(zkClient, config);
- putConfig(zkClient, schema);
- putConfig(zkClient, "solrconfig.xml");
- putConfig(zkClient, "stopwords.txt");
- putConfig(zkClient, "protwords.txt");
- putConfig(zkClient, "mapping-ISOLatin1Accent.txt");
- putConfig(zkClient, "old_synonyms.txt");
- putConfig(zkClient, "synonyms.txt");
+ final ZkNodeProps zkProps = new ZkNodeProps(props);
+
+ zkCmdExecutor.retryOperation(new ZkOperation() {
+ @Override
+ public Object execute() throws KeeperException, InterruptedException {
+ zkCmdExecutor.getZkClient().makePath("/collections/collection1", ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT);
+ return null;
+ }
+ });
+
+ zkCmdExecutor.retryOperation(new ZkOperation() {
+ @Override
+ public Object execute() throws KeeperException, InterruptedException {
+ zkCmdExecutor.getZkClient().makePath("/collections/collection1/shards", CreateMode.PERSISTENT);
+ return null;
+ }
+ });
+
+ zkCmdExecutor.retryOperation(new ZkOperation() {
+ @Override
+ public Object execute() throws KeeperException, InterruptedException {
+ zkCmdExecutor.getZkClient().makePath("/collections/control_collection", ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT);
+ return null;
+ }
+ });
+
+ zkCmdExecutor.retryOperation(new ZkOperation() {
+ @Override
+ public Object execute() throws KeeperException, InterruptedException {
+ zkCmdExecutor.getZkClient().makePath("/collections/control_collection/shards", CreateMode.PERSISTENT);
+ return null;
+ }
+ });
+
+
+ putConfig(zkCmdExecutor, config);
+ putConfig(zkCmdExecutor, schema);
+ putConfig(zkCmdExecutor, "solrconfig.xml");
+ putConfig(zkCmdExecutor, "stopwords.txt");
+ putConfig(zkCmdExecutor, "protwords.txt");
+ putConfig(zkCmdExecutor, "mapping-ISOLatin1Accent.txt");
+ putConfig(zkCmdExecutor, "old_synonyms.txt");
+ putConfig(zkCmdExecutor, "synonyms.txt");
zkClient.close();
}
- private static void putConfig(SolrZkClient zkClient, String name)
+ private static void putConfig(final ZkCmdExecutor zkCmdExecutor, final String name)
throws Exception {
-
- zkClient.makePath("/configs/conf1/" + name, getFile("solr"
- + File.separator + "conf" + File.separator + name), false);
+ zkCmdExecutor.retryOperation(new ZkOperation() {
+ @Override
+ public Object execute() throws KeeperException, InterruptedException {
+ try {
+ zkCmdExecutor.getZkClient().makePath("/configs/conf1/" + name, getFile("solr"
+ + File.separator + "conf" + File.separator + name), false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+ });
+
}
@Override
Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java?rev=1228412&r1=1228411&r2=1228412&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java (original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java Fri Jan 6 21:13:02 2012
@@ -17,6 +17,7 @@ package org.apache.solr.common.cloud;
* limitations under the License.
*/
+import java.io.IOException;
import java.util.List;
import org.apache.log4j.Logger;
@@ -29,13 +30,13 @@ import org.apache.zookeeper.data.ACL;
public class ZkCmdExecutor {
private static final Logger LOG = Logger.getLogger(ZkCmdExecutor.class);
- protected final SolrZkClient solrZkClient;
+ protected final SolrZkClient zkClient;
private long retryDelay = 1000L;
private int retryCount = 15;
private List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
public ZkCmdExecutor(SolrZkClient solrZkClient) {
- this.solrZkClient = solrZkClient;
+ this.zkClient = solrZkClient;
}
/**
@@ -80,6 +81,7 @@ public class ZkCmdExecutor {
* Perform the given operation, retrying if the connection fails
*
* @return object. it needs to be cast to the callee's expected return type.
+ * @throws IOException
*/
@SuppressWarnings("unchecked")
public <T> T retryOperation(ZkOperation operation)
@@ -103,6 +105,7 @@ public class ZkCmdExecutor {
* flags
*
* @param path
+ * @throws IOException
*/
protected void ensurePathExists(String path) {
ensureExists(path, null, acl, CreateMode.PERSISTENT);
@@ -114,16 +117,17 @@ public class ZkCmdExecutor {
* @param path
* @param acl
* @param flags
+ * @throws IOException
*/
protected void ensureExists(final String path, final byte[] data,
final List<ACL> acl, final CreateMode flags) {
try {
retryOperation(new ZkOperation() {
public Object execute() throws KeeperException, InterruptedException {
- if (solrZkClient.exists(path)) {
+ if (zkClient.exists(path)) {
return true;
}
- solrZkClient.create(path, data, acl, flags);
+ zkClient.create(path, data, acl, flags);
return true;
}
});
@@ -149,4 +153,8 @@ public class ZkCmdExecutor {
}
}
}
+
+ public SolrZkClient getZkClient() {
+ return zkClient;
+ }
}
Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java?rev=1228412&r1=1228411&r2=1228412&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java (original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/ZkOperation.java Fri Jan 6 21:13:02 2012
@@ -17,6 +17,8 @@
*/
package org.apache.solr.common.cloud;
+import java.io.IOException;
+
import org.apache.zookeeper.KeeperException;
/**
@@ -24,8 +26,8 @@ import org.apache.zookeeper.KeeperExcept
* {@link org.apache.solr.common.cloud.ZkCmdExecutor.lock.ProtocolSupport} class
*
*/
-public interface ZkOperation {
-
+public abstract class ZkOperation {
+
/**
* Performs the operation - which may be involved multiple times if the connection
* to ZooKeeper closes during this operation
@@ -33,6 +35,7 @@ public interface ZkOperation {
* @return the result of the operation or null
* @throws KeeperException
* @throws InterruptedException
+ * @throws IOException
*/
- public Object execute() throws KeeperException, InterruptedException;
+ public abstract Object execute() throws KeeperException, InterruptedException;
}