You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ma...@apache.org on 2010/02/04 21:33:33 UTC
svn commit: r906642 - in /lucene/solr/branches/cloud/src:
java/org/apache/solr/cloud/SolrZkClient.java
java/org/apache/solr/cloud/ZkController.java
test/org/apache/solr/cloud/ZkControllerTest.java
Author: markrmiller
Date: Thu Feb 4 20:33:33 2010
New Revision: 906642
URL: http://svn.apache.org/viewvc?rev=906642&view=rev
Log:
add pause in case config for collection is not yet set
Modified:
lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/SolrZkClient.java
lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/SolrZkClient.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/SolrZkClient.java?rev=906642&r1=906641&r2=906642&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/SolrZkClient.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/SolrZkClient.java Thu Feb 4 20:33:33 2010
@@ -313,6 +313,24 @@
*/
public void makePath(String path, byte[] data, CreateMode createMode,
Watcher watcher) throws KeeperException, InterruptedException {
+ makePath(path, data, createMode, watcher, false);
+ }
+
+ /**
+ * Creates the path in ZooKeeper, creating each node as necessary.
+ *
+ * e.g. If <code>path=/solr/group/node</code> and none of the nodes, solr,
+ * group, node exist, each will be created.
+ *
+ * @param path
+ * @param data to set on the last zkNode
+ * @param createMode
+ * @param watcher
+ * @throws KeeperException
+ * @throws InterruptedException
+ */
+ public void makePath(String path, byte[] data, CreateMode createMode,
+ Watcher watcher, boolean failOnExists) throws KeeperException, InterruptedException {
if (log.isInfoEnabled()) {
log.info("makePath: " + path + " keeper:" + keeper);
}
@@ -328,7 +346,7 @@
sbPath.append("/" + pathPiece);
String currentPath = sbPath.toString();
Object exists = exists(currentPath, watcher);
- if (exists == null) {
+ if (exists == null || ((i == paths.length -1) && failOnExists)) {
CreateMode mode = CreateMode.PERSISTENT;
if (i == paths.length - 1) {
mode = createMode;
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java?rev=906642&r1=906641&r2=906642&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java Thu Feb 4 20:33:33 2010
@@ -776,6 +776,7 @@
}
public void createCollectionZkNode(String collection) throws KeeperException, InterruptedException, IOException {
+ log.info("Check for collection zkNode:" + collection);
String collectionPath = COLLECTIONS_ZKNODE + "/" + collection;
try {
@@ -789,9 +790,31 @@
String confName = System.getProperty("bootstrap_confname", "configuration1");
log.info("Setting config for collection:" + collection + " to " + confName);
props.put("configName", confName);
+ } else {
+ // check for configName
+ log.info("Looking for collection configName");
+ int retry = 1;
+ for (; retry < 6; retry++) {
+ if (zkClient.exists(COLLECTIONS_ZKNODE + "/" + collection)) {
+ ZkNodeProps collectionProps = new ZkNodeProps();
+ collectionProps.load(zkClient.getData(COLLECTIONS_ZKNODE + "/"
+ + collection, null, null));
+ if (collectionProps.containsKey("configName")) {
+ break;
+ }
+ }
+ log.info("Could not find collection configName - pausing for 2 seconds and trying again - try: " + retry);
+ Thread.sleep(2000);
+ }
+ if (retry == 6) {
+ log.error("Could not find conigName for collection " + collection);
+ throw new ZooKeeperException(
+ SolrException.ErrorCode.SERVER_ERROR,
+ "Could not find conigName for collection " + collection);
+ }
}
- zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection, props.store(), CreateMode.PERSISTENT);
+ zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection, props.store(), CreateMode.PERSISTENT, null, true);
// ping that there is a new collection
zkClient.setData(COLLECTIONS_ZKNODE, (byte[])null);
@@ -801,6 +824,8 @@
throw e;
}
}
+ } else {
+ log.info("Collection zkNode exists");
}
} catch (KeeperException e) {
Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=906642&r1=906641&r2=906642&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java Thu Feb 4 20:33:33 2010
@@ -68,7 +68,8 @@
String shardsPath = "/collections/collection1/shards/shardid1";
zkClient.makePath(shardsPath);
- zkClient.makePath("collections/collection1/config=collection1");
+ // nocommit
+ //zkClient.makePath("collections/collection1/config=collection1");
addShardToZk(zkClient, shardsPath, SHARD1, URL1, "slave");
addShardToZk(zkClient, shardsPath, SHARD2, URL2, "master");