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/17 18:41:40 UTC
svn commit: r911106 - in
/lucene/solr/branches/cloud/src/java/org/apache/solr:
cloud/ZkSolrResourceLoader.java core/SolrCore.java
core/SolrResourceLoader.java handler/admin/ShowFileRequestHandler.java
Author: markrmiller
Date: Wed Feb 17 17:41:39 2010
New Revision: 911106
URL: http://svn.apache.org/viewvc?rev=911106&view=rev
Log:
work on SolrResourceLoader#getConfigDir nocommit issue
Modified:
lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java
lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java
lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrResourceLoader.java
lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java?rev=911106&r1=911105&r2=911106&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java Wed Feb 17 17:41:39 2010
@@ -18,10 +18,15 @@
*/
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import java.util.Properties;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.core.SolrResourceLoader;
+import org.apache.zookeeper.KeeperException;
/**
* ResourceLoader that works with ZooKeeper.
@@ -29,14 +34,14 @@
*/
public class ZkSolrResourceLoader extends SolrResourceLoader {
- private String collection;
+ private final String collectionZkPath;
private ZkController zkController;
public ZkSolrResourceLoader(String instanceDir, String collection,
ZkController zooKeeperController) {
super(instanceDir);
this.zkController = zooKeeperController;
- this.collection = collection;
+ collectionZkPath = ZkController.CONFIGS_ZKNODE + "/" + collection;
}
/**
@@ -50,8 +55,8 @@
public ZkSolrResourceLoader(String instanceDir, String collection, ClassLoader parent,
Properties coreProperties, ZkController zooKeeperController) {
super(instanceDir, parent, coreProperties);
- this.collection = collection;
this.zkController = zooKeeperController;
+ collectionZkPath = ZkController.CONFIGS_ZKNODE + "/" + collection;
}
/**
@@ -65,10 +70,10 @@
*/
public InputStream openResource(String resource) {
InputStream is = null;
- String file = getConfigDir() + "/" + resource; //nocommit: getConfigDir no longer makes sense here
+ String file = collectionZkPath + "/" + resource; //nocommit: getConfigDir no longer makes sense here
try {
if (zkController.pathExists(file)) {
- byte[] bytes = zkController.getZkClient().getData(getConfigDir() + "/" + resource, null, null);
+ byte[] bytes = zkController.getZkClient().getData(collectionZkPath + "/" + resource, null, null);
return new ByteArrayInputStream(bytes);
}
} catch (Exception e) {
@@ -82,14 +87,34 @@
}
if (is == null) {
throw new RuntimeException("Can't find resource '" + resource
- + "' in classpath or '" + getConfigDir() + "', cwd="
+ + "' in classpath or '" + collectionZkPath + "', cwd="
+ System.getProperty("user.dir"));
}
return is;
}
- // nocommit: deal with code that uses this call to load the file itself (elevation?)
public String getConfigDir() {
- return "/configs/" + collection;
+ throw new ZooKeeperException(
+ ErrorCode.SERVER_ERROR,
+ "ZkSolrResourceLoader does not support getConfigDir() - likely, what you are trying to do is not supported in ZooKeeper mode");
}
+
+ public String[] listConfigDir() {
+ List<String> list;
+ try {
+ list = zkController.getZkClient().getChildren(collectionZkPath, null);
+ } catch (InterruptedException e) {
+ // Restore the interrupted status
+ Thread.currentThread().interrupt();
+ log.error("", e);
+ throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
+ "", e);
+ } catch (KeeperException e) {
+ log.error("", e);
+ throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
+ "", e);
+ }
+ return list.toArray(new String[0]);
+ }
+
}
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java?rev=911106&r1=911105&r2=911106&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java Wed Feb 17 17:41:39 2010
@@ -1550,12 +1550,10 @@
// Hide everything...
Set<String> hide = new HashSet<String>();
- File configdir = new File( solrConfig.getResourceLoader().getConfigDir() );
- if( configdir.exists() && configdir.isDirectory() ) {
- for( String file : configdir.list() ) {
- hide.add( file.toUpperCase() );
- }
- }
+
+ for (String file : resourceLoader.listConfigDir()) {
+ hide.add(file.toUpperCase());
+ }
// except the "gettable" list
StringTokenizer st = new StringTokenizer( gettable );
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrResourceLoader.java?rev=911106&r1=911105&r2=911106&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrResourceLoader.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrResourceLoader.java Wed Feb 17 17:41:39 2010
@@ -204,6 +204,15 @@
return instanceDir + "conf/";
}
+ public String[] listConfigDir() {
+ File configdir = new File(getConfigDir());
+ if( configdir.exists() && configdir.isDirectory() ) {
+ return configdir.list();
+ } else {
+ return new String[0];
+ }
+ }
+
public String getDataDir() {
return dataDir;
}
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java?rev=911106&r1=911105&r2=911106&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java Wed Feb 17 17:41:39 2010
@@ -71,6 +71,8 @@
* http://localhost:8983/solr/admin/file?file=schema.xml&contentType=text/plain
* </pre>
*
+ * TODO: make this work with Solr in ZooKeeper mode
+ *
* @version $Id$
* @since solr 1.3
*/