You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2012/09/21 19:22:27 UTC
svn commit: r1388574 [43/45] - in /lucene/dev/branches/LUCENE-2878: ./
dev-tools/ dev-tools/eclipse/ dev-tools/eclipse/dot.settings/
dev-tools/idea/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/
dev-tools/idea/lucene/ dev-tools/idea/lucene/anal...
Modified: lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/solrconfig.xml?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/solrconfig.xml (original)
+++ lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/solrconfig.xml Fri Sep 21 17:21:34 2012
@@ -37,7 +37,7 @@
-->
<luceneMatchVersion>LUCENE_50</luceneMatchVersion>
- <!-- lib directives can be used to instruct Solr to load an Jars
+ <!-- <lib/> directives can be used to instruct Solr to load an Jars
identified and use them to resolve any "plugins" specified in
your solrconfig.xml or schema.xml (ie: Analyzers, Request
Handlers, etc...).
@@ -45,6 +45,12 @@
All directories and paths are resolved relative to the
instanceDir.
+ Please note that <lib/> directives are processed in the order
+ that they appear in your solrconfig.xml file, and are "stacked"
+ on top of each other when building a ClassLoader - so if you have
+ plugin jars with dependencies on other jars, the "lower level"
+ dependency jars should be loaded first.
+
If a "./lib" directory exists in your instanceDir, all files
found in it are included as if you had used the following
syntax...
@@ -55,26 +61,25 @@
<!-- A 'dir' option by itself adds any files found in the directory
to the classpath, this is useful for including all jars in a
directory.
- -->
- <!--
- <lib dir="../add-everything-found-in-this-dir-to-the-classpath" />
- -->
- <!-- When a 'regex' is specified in addition to a 'dir', only the
+ When a 'regex' is specified in addition to a 'dir', only the
files in that directory which completely match the regex
(anchored on both ends) will be included.
+
+ The examples below can be used to load some solr-contribs along
+ with their external dependencies.
-->
- <lib dir="../../../dist/" regex="apache-solr-cell-\d.*\.jar" />
<lib dir="../../../contrib/extraction/lib" regex=".*\.jar" />
+ <lib dir="../../../dist/" regex="apache-solr-cell-\d.*\.jar" />
- <lib dir="../../../dist/" regex="apache-solr-clustering-\d.*\.jar" />
<lib dir="../../../contrib/clustering/lib/" regex=".*\.jar" />
+ <lib dir="../../../dist/" regex="apache-solr-clustering-\d.*\.jar" />
- <lib dir="../../../dist/" regex="apache-solr-langid-\d.*\.jar" />
<lib dir="../../../contrib/langid/lib/" regex=".*\.jar" />
+ <lib dir="../../../dist/" regex="apache-solr-langid-\d.*\.jar" />
- <lib dir="../../../dist/" regex="apache-solr-velocity-\d.*\.jar" />
<lib dir="../../../contrib/velocity/lib" regex=".*\.jar" />
+ <lib dir="../../../dist/" regex="apache-solr-velocity-\d.*\.jar" />
<!-- If a 'dir' option (with or without a regex) is used and nothing
is found that matches, it will be ignored
@@ -82,8 +87,8 @@
<lib dir="/total/crap/dir/ignored" />
<!-- an exact 'path' can be used instead of a 'dir' to specify a
- specific file. This will cause a serious error to be logged if
- it can't be loaded.
+ specific jar file. This will cause a serious error to be logged
+ if it can't be loaded.
-->
<!--
<lib path="../a-jar-that-does-not-exist.jar" />
@@ -954,7 +959,18 @@
</lst>
-->
</requestHandler>
-
+
+ <!-- for back compat with clients using /update/json and /update/csv -->
+ <requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler">
+ <lst name="defaults">
+ <str name="stream.contentType">application/json</str>
+ </lst>
+ </requestHandler>
+ <requestHandler name="/update/csv" class="solr.CSVRequestHandler">
+ <lst name="defaults">
+ <str name="stream.contentType">application/csv</str>
+ </lst>
+ </requestHandler>
<!-- Solr Cell Update Request Handler
@@ -1093,30 +1109,33 @@
http://wiki.apache.org/solr/SolrReplication
- In the example below, remove the <lst name="master"> section if
- this is just a slave and remove the <lst name="slave"> section
- if this is just a master.
+ It is also neccessary for SolrCloud to function (in Cloud mode, the
+ replication handler is used to bulk transfer segments when nodes
+ are added or need to recover).
+
+ https://wiki.apache.org/solr/SolrCloud/
-->
- <!--
- <requestHandler name="/replication" class="solr.ReplicationHandler" >
+ <requestHandler name="/replication" class="solr.ReplicationHandler" >
+ <!--
+ To enable simple master/slave replication, uncomment one of the
+ sections below, depending on wether this solr instance should be
+ the "master" or a "slave". If this instance is a "slave" you will
+ also need to fill in the masterUrl to point to a real machine.
+ -->
+ <!--
<lst name="master">
<str name="replicateAfter">commit</str>
<str name="replicateAfter">startup</str>
<str name="confFiles">schema.xml,stopwords.txt</str>
</lst>
+ -->
+ <!--
<lst name="slave">
- <str name="masterUrl">http://localhost:8983/solr</str>
+ <str name="masterUrl">http://your-master-hostname:8983/solr</str>
<str name="pollInterval">00:00:60</str>
</lst>
- </requestHandler>
- -->
-
- <!-- Solr Replication for SolrCloud Recovery
-
- This is the config need for SolrCloud's recovery replication.
-->
- <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" />
-
+ </requestHandler>
<!-- Search Components
@@ -1430,6 +1449,7 @@
<requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<bool name="terms">true</bool>
+ <bool name="distrib">false</bool>
</lst>
<arr name="components">
<str>terms</str>
Modified: lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/browse.vm
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/browse.vm?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/browse.vm (original)
+++ lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/browse.vm Fri Sep 21 17:21:34 2012
@@ -20,6 +20,13 @@
class="page-count">$page.page_count</span>#end
</div>
+<div class="error">
+ #if(${response.response.error.code})
+ <h1>ERROR ${response.response.error.code}</h1>
+ ${response.response.error.msg}
+ #end
+</div>
+
<div class="results">
#if($response.response.get('grouped'))
#foreach($grouping in $response.response.get('grouped'))
Modified: lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/main.css
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/main.css?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/main.css (original)
+++ lucene/dev/branches/LUCENE-2878/solr/example/solr/collection1/conf/velocity/main.css Fri Sep 21 17:21:34 2012
@@ -196,4 +196,13 @@ li.show {
.group-value{
font-weight: bold;
-}
\ No newline at end of file
+}
+
+.error {
+ color: white;
+ background-color: red;
+ left: 210px;
+ width:80%;
+ position: relative;
+
+}
Modified: lucene/dev/branches/LUCENE-2878/solr/example/solr/solr.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/example/solr/solr.xml?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/example/solr/solr.xml (original)
+++ lucene/dev/branches/LUCENE-2878/solr/example/solr/solr.xml Fri Sep 21 17:21:34 2012
@@ -27,7 +27,7 @@
-->
<!--
- All (relative) paths are relative to the installation path
+ All (relative) paths are relative to the Solr Home Directory
persistent: Save changes made via the API to this file
sharedLib: path to a lib directory that will be shared across all cores
@@ -47,7 +47,7 @@
All of the attributes in cores after defaultCoreName only apply when running in SolrCloud mode.
You can read more about SolrCloud mode at http://wiki.apache.org/solr/SolrCloud
-->
- <cores adminPath="/admin/cores" defaultCoreName="collection1" host="${host:}" hostPort="${jetty.port:}" zkClientTimeout="${zkClientTimeout:15000}">
+ <cores adminPath="/admin/cores" defaultCoreName="collection1" host="${host:}" hostPort="${jetty.port:}" hostContext="${hostContext:}" zkClientTimeout="${zkClientTimeout:15000}">
<core name="collection1" instanceDir="collection1" />
</cores>
</solr>
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/commons-compress-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/commons-compress-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/commons-compress-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/commons-compress-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,5 +1,5 @@
Apache Commons Compress
-Copyright 2002-2011 The Apache Software Foundation
+Copyright 2002-2012 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/fontbox-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/fontbox-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/fontbox-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/fontbox-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,6 +1,6 @@
Apache FontBox
-Copyright 2008-2010 The Apache Software Foundation
+Copyright 2008-2012 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/jempbox-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/jempbox-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/jempbox-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/jempbox-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,6 +1,6 @@
Apache JempBox
-Copyright 2008-2010 The Apache Software Foundation
+Copyright 2008-2012 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/pdfbox-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/pdfbox-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/pdfbox-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/pdfbox-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,10 +1,14 @@
-
Apache PDFBox
-Copyright 2002-2010 The Apache Software Foundation
+Copyright 2011 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
-
-Based on source code contributed to the original PDFBox project.
+Based on source code originally developed in the PDFBox, JempBox and
+FontBox projects.
Copyright (c) 2002-2007, www.pdfbox.org
+Copyright (c) 2006-2007, www.jempbox.org
+
+Based on source code originally developed in the PaDaF project.
+Copyright (c) 2010 Atos Worldline SAS
+
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/tika-core-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/tika-core-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/tika-core-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/tika-core-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,8 +1,15 @@
-
-Apache Tika core
-Copyright 2007-2010 The Apache Software Foundation
+Apache Tika
+Copyright 2011 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+Copyright 1993-2010 University Corporation for Atmospheric Research/Unidata
+This software contains code derived from UCAR/Unidata's NetCDF library.
+
+Tika-server compoment uses CDDL-licensed dependencies: jersey (http://jersey.java.net/) and
+Grizzly (http://grizzly.java.net/)
+
+OpenCSV: Copyright 2005 Bytecode Pty Ltd. Licensed under the Apache License, Version 2.0
+IPTC Photo Metadata descriptions Copyright 2010 International Press Telecommunications Council.
Modified: lucene/dev/branches/LUCENE-2878/solr/licenses/tika-parsers-NOTICE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/licenses/tika-parsers-NOTICE.txt?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/licenses/tika-parsers-NOTICE.txt (original)
+++ lucene/dev/branches/LUCENE-2878/solr/licenses/tika-parsers-NOTICE.txt Fri Sep 21 17:21:34 2012
@@ -1,8 +1,15 @@
-
Apache Tika parsers
-Copyright 2007-2010 The Apache Software Foundation
+Copyright 2011 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+Copyright 1993-2010 University Corporation for Atmospheric Research/Unidata
+This software contains code derived from UCAR/Unidata's NetCDF library.
+
+Tika-server compoment uses CDDL-licensed dependencies: jersey (http://jersey.java.net/) and
+Grizzly (http://grizzly.java.net/)
+
+OpenCSV: Copyright 2005 Bytecode Pty Ltd. Licensed under the Apache License, Version 2.0
+IPTC Photo Metadata descriptions Copyright 2010 International Press Telecommunications Council.
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/build.xml?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/build.xml (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/build.xml Fri Sep 21 17:21:34 2012
@@ -18,41 +18,42 @@
<project name="solr-solrj" default="default">
<description>Solrj - Solr Java Client</description>
- <property name="ivy.retrieve.pattern" value="${common-solr.dir}/lib/[artifact]-[revision].[ext]"/>
-
- <!-- we cannot sync because solr/core and solr/solrj share the same lib/... clean this up! -->
- <property name="ivy.sync" value="false"/>
-
<import file="../common-build.xml"/>
+ <!-- Specialized compile classpath: to only depend on what solrj should depend on (e.g. not lucene) -->
+ <path id="classpath">
+ <fileset dir="${common-solr.dir}/solrj/lib" excludes="${common.classpath.excludes}"/>
+ </path>
+
<!-- Specialized common-solr.test.classpath, to remove the Solr core test output -->
<path id="test.classpath">
<pathelement path="${common-solr.dir}/build/solr-test-framework/classes/java"/>
<pathelement path="${tests.userdir}"/>
<path refid="test.base.classpath"/>
+ <path refid="solr.base.classpath"/>
</path>
+ <!-- Specialized to depend on nothing -->
+ <target name="javadocs" depends="compile-core,define-lucene-javadoc-url">
+ <sequential>
+ <mkdir dir="${javadoc.dir}/${name}"/>
+ <solr-invoke-javadoc>
+ <solrsources>
+ <packageset dir="${src.dir}"/>
+ </solrsources>
+ </solr-invoke-javadoc>
+ <solr-jarify basedir="${javadoc.dir}/${name}" destfile="${build.dir}/${final.name}-javadoc.jar"/>
+ </sequential>
+ </target>
+
<target name="dist" depends="common-solr.dist">
<mkdir dir="${dist}/solrj-lib" />
<copy todir="${dist}/solrj-lib">
- <fileset dir="${common-solr.dir}/lib">
- <include name="commons-codec-*.jar"/>
- <include name="commons-io-*.jar"/>
- <include name="httpcore*.jar"/>
- <include name="httpclient*.jar"/>
- <include name="httpmime*.jar"/>
- <include name="*stax-*.jar" />
- <include name="wstx-*.jar" />
- <include name="jcl-over-slf4j-*.jar" />
- <include name="slf4j-api-*.jar" />
+ <fileset dir="${common-solr.dir}/solrj/lib">
+ <include name="*.jar"/>
</fileset>
</copy>
</target>
- <target name="javadocs" depends="common-solr.javadocs">
- <mkdir dir="${dest}/docs/api/solrj"/>
- <copy todir="${dest}/docs/api/solrj">
- <fileset dir="${javadoc.dir}"/>
- </copy>
- </target>
+ <target name="dist-maven" depends="dist-maven-src-java"/>
</project>
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java Fri Sep 21 17:21:34 2012
@@ -88,7 +88,7 @@ public class DocumentObjectBinder {
} else {
doc.setField(field.name, field.get(obj), 1.0f);
}
- }
+ }
return doc;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryRequestWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryRequestWriter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryRequestWriter.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryRequestWriter.java Fri Sep 21 17:21:34 2012
@@ -104,7 +104,7 @@ public class BinaryRequestWriter extends
}
/*
- * A hack to get access to the protected internal buffer and avoid an additional copy
+ * A hack to get access to the protected internal buffer and avoid an additional copy
*/
class BAOS extends ByteArrayOutputStream {
byte[] getbuf() {
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java Fri Sep 21 17:21:34 2012
@@ -208,7 +208,7 @@ public class CloudSolrServer extends Sol
Map<String,ZkNodeProps> nodes = new HashMap<String,ZkNodeProps>();
List<String> urlList = new ArrayList<String>();
for (Slice slice : slices.values()) {
- for (ZkNodeProps nodeProps : slice.getShards().values()) {
+ for (ZkNodeProps nodeProps : slice.getReplicasMap().values()) {
ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
String node = coreNodeProps.getNodeName();
if (!liveNodes.contains(coreNodeProps.getNodeName())
@@ -242,14 +242,16 @@ public class CloudSolrServer extends Sol
theUrlList.addAll(urlList);
}
Collections.shuffle(theUrlList, rand);
- if (replicas != null) {
+ if (sendToLeaders) {
ArrayList<String> theReplicas = new ArrayList<String>(replicasList.size());
theReplicas.addAll(replicasList);
Collections.shuffle(theReplicas, rand);
-
+ // System.out.println("leaders:" + theUrlList);
+ // System.out.println("replicas:" + theReplicas);
theUrlList.addAll(theReplicas);
}
- //System.out.println("########################## MAKING REQUEST TO " + theUrlList);
+
+ // System.out.println("########################## MAKING REQUEST TO " + theUrlList);
LBHttpSolrServer.Req req = new LBHttpSolrServer.Req(request, theUrlList);
LBHttpSolrServer.Rsp rsp = lbServer.request(req);
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java Fri Sep 21 17:21:34 2012
@@ -78,9 +78,18 @@ public class HttpClientUtil {
static final DefaultHttpRequestRetryHandler NO_RETRY = new DefaultHttpRequestRetryHandler(
0, false);
+ private static HttpClientConfigurer configurer = new HttpClientConfigurer();
+
private HttpClientUtil(){}
/**
+ * Replace the {@link HttpClientConfigurer} class used in configuring the http
+ * clients with a custom implementation.
+ */
+ public static void setConfigurer(HttpClientConfigurer newConfigurer) {
+ configurer = newConfigurer;
+ }
+ /**
* Creates new http client by using the provided configuration.
*
* @param params
@@ -103,38 +112,7 @@ public class HttpClientUtil {
*/
public static void configureClient(final DefaultHttpClient httpClient,
SolrParams config) {
-
- if (config.get(PROP_MAX_CONNECTIONS) != null) {
- setMaxConnections(httpClient, config.getInt(PROP_MAX_CONNECTIONS));
- }
-
- if (config.get(PROP_MAX_CONNECTIONS_PER_HOST) != null) {
- setMaxConnectionsPerHost(httpClient, config.getInt(PROP_MAX_CONNECTIONS_PER_HOST));
- }
-
- if (config.get(PROP_CONNECTION_TIMEOUT) != null) {
- setConnectionTimeout(httpClient, config.getInt(PROP_CONNECTION_TIMEOUT));
- }
-
- if (config.get(PROP_SO_TIMEOUT) != null) {
- setSoTimeout(httpClient, config.getInt(PROP_SO_TIMEOUT));
- }
-
- if (config.get(PROP_USE_RETRY) != null) {
- setUseRetry(httpClient, config.getBool(PROP_USE_RETRY));
- }
-
- if (config.get(PROP_FOLLOW_REDIRECTS) != null) {
- setFollowRedirects(httpClient, config.getBool(PROP_FOLLOW_REDIRECTS));
- }
-
- final String basicAuthUser = config.get(PROP_BASIC_AUTH_USER);
- final String basicAuthPass = config.get(PROP_BASIC_AUTH_PASS);
- setBasicAuth(httpClient, basicAuthUser, basicAuthPass);
-
- if (config.get(PROP_ALLOW_COMPRESSION) != null) {
- setAllowCompression(httpClient, config.getBool(PROP_ALLOW_COMPRESSION));
- }
+ configurer.configure(httpClient, config);
}
/**
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java Fri Sep 21 17:21:34 2012
@@ -120,8 +120,9 @@ public class CoreAdminRequest extends So
protected String coreNodeName;
protected String state;
protected Boolean checkLive;
- protected Integer pauseFor;
+ protected Boolean onlyIfLeader;
+
public WaitForState() {
action = CoreAdminAction.PREPRECOVERY;
}
@@ -158,12 +159,12 @@ public class CoreAdminRequest extends So
this.checkLive = checkLive;
}
- public Integer getPauseFor() {
- return pauseFor;
+ public boolean isOnlyIfLeader() {
+ return onlyIfLeader;
}
- public void setPauseFor(Integer pauseFor) {
- this.pauseFor = pauseFor;
+ public void setOnlyIfLeader(boolean onlyIfLeader) {
+ this.onlyIfLeader = onlyIfLeader;
}
@Override
@@ -192,8 +193,8 @@ public class CoreAdminRequest extends So
params.set( "checkLive", checkLive);
}
- if (pauseFor != null) {
- params.set( "pauseFor", pauseFor);
+ if (onlyIfLeader != null) {
+ params.set( "onlyIfLeader", onlyIfLeader);
}
return params;
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/LukeRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/LukeRequest.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/LukeRequest.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/request/LukeRequest.java Fri Sep 21 17:21:34 2012
@@ -108,7 +108,7 @@ public class LukeRequest extends SolrReq
params.add( "numTerms", numTerms+"" );
}
if (showSchema) {
- params.add("show", "schema");
+ params.add("show", "schema");
}
return params;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java Fri Sep 21 17:21:34 2012
@@ -443,7 +443,7 @@ public class QueryResponse extends SolrR
return _facetPivot;
}
- /** get
+ /** get
*
* @param name the name of the
* @return the FacetField by name or null if it does not exist
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java Fri Sep 21 17:21:34 2012
@@ -45,41 +45,41 @@ public class SpellCheckResponse {
String n = sugg.getName(i);
if ("correctlySpelled".equals(n)) {
correctlySpelled = (Boolean) sugg.getVal(i);
- } else if ("collationInternalRank".equals(n)){
- //continue;
- } else if ("collation".equals(n)) {
- List<Object> collationInfo = sugg.getAll(n);
- collations = new ArrayList<Collation>(collationInfo.size());
- for (Object o : collationInfo) {
- if (o instanceof String) {
- collations.add(new Collation()
- .setCollationQueryString((String) o));
- } else if (o instanceof NamedList) {
+ } else if ("collationInternalRank".equals(n)){
+ //continue;
+ } else if ("collation".equals(n)) {
+ List<Object> collationInfo = sugg.getAll(n);
+ collations = new ArrayList<Collation>(collationInfo.size());
+ for (Object o : collationInfo) {
+ if (o instanceof String) {
+ collations.add(new Collation()
+ .setCollationQueryString((String) o));
+ } else if (o instanceof NamedList) {
@SuppressWarnings("unchecked")
- NamedList<Object> expandedCollation = (NamedList<Object>) o;
- String collationQuery
+ NamedList<Object> expandedCollation = (NamedList<Object>) o;
+ String collationQuery
= (String) expandedCollation.get("collationQuery");
- int hits = (Integer) expandedCollation.get("hits");
+ int hits = (Integer) expandedCollation.get("hits");
@SuppressWarnings("unchecked")
- NamedList<String> misspellingsAndCorrections
+ NamedList<String> misspellingsAndCorrections
= (NamedList<String>) expandedCollation.get("misspellingsAndCorrections");
- Collation collation = new Collation();
- collation.setCollationQueryString(collationQuery);
- collation.setNumberOfHits(hits);
-
- for (int ii = 0; ii < misspellingsAndCorrections.size(); ii++) {
- String misspelling = misspellingsAndCorrections.getName(ii);
- String correction = misspellingsAndCorrections.getVal(ii);
- collation.addMisspellingsAndCorrection(new Correction(
- misspelling, correction));
- }
- collations.add(collation);
- } else {
- throw new AssertionError(
- "Should get Lists of Strings or List of NamedLists here.");
- }
- }
+ Collation collation = new Collation();
+ collation.setCollationQueryString(collationQuery);
+ collation.setNumberOfHits(hits);
+
+ for (int ii = 0; ii < misspellingsAndCorrections.size(); ii++) {
+ String misspelling = misspellingsAndCorrections.getName(ii);
+ String correction = misspellingsAndCorrections.getVal(ii);
+ collation.addMisspellingsAndCorrection(new Correction(
+ misspelling, correction));
+ }
+ collations.add(collation);
+ } else {
+ throw new AssertionError(
+ "Should get Lists of Strings or List of NamedLists here.");
+ }
+ }
} else {
@SuppressWarnings("unchecked")
Suggestion s = new Suggestion(n, (NamedList<Object>) sugg.getVal(i));
@@ -129,7 +129,7 @@ public class SpellCheckResponse {
* @return all collations
*/
public List<Collation> getCollatedResults() {
- return collations;
+ return collations;
}
public static class Suggestion {
@@ -219,62 +219,62 @@ public class SpellCheckResponse {
}
- public class Collation {
- private String collationQueryString;
- private List<Correction> misspellingsAndCorrections = new ArrayList<Correction>();
- private long numberOfHits;
-
- public long getNumberOfHits() {
- return numberOfHits;
- }
-
- public void setNumberOfHits(long numberOfHits) {
- this.numberOfHits = numberOfHits;
- }
-
- public String getCollationQueryString() {
- return collationQueryString;
- }
-
- public Collation setCollationQueryString(String collationQueryString) {
- this.collationQueryString = collationQueryString;
- return this;
- }
-
- public List<Correction> getMisspellingsAndCorrections() {
- return misspellingsAndCorrections;
- }
-
- public Collation addMisspellingsAndCorrection(Correction correction) {
- this.misspellingsAndCorrections.add(correction);
- return this;
- }
-
- }
-
- public class Correction {
- private String original;
- private String correction;
-
- public Correction(String original, String correction) {
- this.original = original;
- this.correction = correction;
- }
-
- public String getOriginal() {
- return original;
- }
-
- public void setOriginal(String original) {
- this.original = original;
- }
-
- public String getCorrection() {
- return correction;
- }
-
- public void setCorrection(String correction) {
- this.correction = correction;
- }
- }
+ public class Collation {
+ private String collationQueryString;
+ private List<Correction> misspellingsAndCorrections = new ArrayList<Correction>();
+ private long numberOfHits;
+
+ public long getNumberOfHits() {
+ return numberOfHits;
+ }
+
+ public void setNumberOfHits(long numberOfHits) {
+ this.numberOfHits = numberOfHits;
+ }
+
+ public String getCollationQueryString() {
+ return collationQueryString;
+ }
+
+ public Collation setCollationQueryString(String collationQueryString) {
+ this.collationQueryString = collationQueryString;
+ return this;
+ }
+
+ public List<Correction> getMisspellingsAndCorrections() {
+ return misspellingsAndCorrections;
+ }
+
+ public Collation addMisspellingsAndCorrection(Correction correction) {
+ this.misspellingsAndCorrections.add(correction);
+ return this;
+ }
+
+ }
+
+ public class Correction {
+ private String original;
+ private String correction;
+
+ public Correction(String original, String correction) {
+ this.original = original;
+ this.correction = correction;
+ }
+
+ public String getOriginal() {
+ return original;
+ }
+
+ public void setOriginal(String original) {
+ this.original = original;
+ }
+
+ public String getCorrection() {
+ return correction;
+ }
+
+ public void setCorrection(String correction) {
+ this.correction = correction;
+ }
+ }
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java Fri Sep 21 17:21:34 2012
@@ -105,15 +105,24 @@ public class SolrDocument implements Map
}
/**
- * This will add a field to the document. If fields already exist with this name
- * it will append the collection
+ * This will add a field to the document. If fields already exist with this
+ * name it will append value to the collection. If the value is Collection,
+ * each value will be added independently.
*/
@SuppressWarnings("unchecked")
public void addField(String name, Object value)
{
Object existing = _fields.get(name);
if (existing == null) {
- this.setField( name, value );
+ if( value instanceof Collection ) {
+ Collection<Object> c = new ArrayList<Object>( 3 );
+ for ( Object o : (Collection<Object>)value ) {
+ c.add(o);
+ }
+ this.setField( name, c );
+ } else {
+ this.setField( name, value );
+ }
return;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Fri Sep 21 17:21:34 2012
@@ -126,8 +126,10 @@ public class SolrInputDocument implement
}
/**
- * Adds a field with the given name, value and boost. If a field with the name already exists, then it is updated to
- * the new value and boost.
+ * Adds a field with the given name, value and boost. If a field with the
+ * name already exists, then the given value is appended to the value of that
+ * field, with the new boost. If the value is a collection, then each of its
+ * values will be added to the field.
*
* @param name Name of the field to add
* @param value Value of the field
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java Fri Sep 21 17:21:34 2012
@@ -41,7 +41,9 @@ public class SolrInputField implements I
//---------------------------------------------------------------
/**
- * Set the value for a field. Arrays will be converted to a collection.
+ * Set the value for a field. Arrays will be converted to a collection. If
+ * a collection is given, then that collection will be used as the backing
+ * collection for the values.
*/
public void setValue(Object v, float b) {
boost = b;
@@ -60,13 +62,22 @@ public class SolrInputField implements I
}
/**
- * Add values to a field. if the added value is a collection, each value
- * will be added individually
+ * Add values to a field. If the added value is a collection, each value
+ * will be added individually.
*/
@SuppressWarnings("unchecked")
public void addValue(Object v, float b) {
if( value == null ) {
- setValue(v, b);
+ if ( v instanceof Collection ) {
+ Collection<Object> c = new ArrayList<Object>( 3 );
+ for ( Object o : (Collection<Object>)v ) {
+ c.add( o );
+ }
+ setValue(c, b);
+ } else {
+ setValue(v, b);
+ }
+
return;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Fri Sep 21 17:21:34 2012
@@ -92,9 +92,9 @@ public class ClusterState implements JSO
Set<Entry<String,Slice>> slices = state.entrySet();
for (Entry<String,Slice> sliceEntry : slices) {
Slice slice = sliceEntry.getValue();
- Map<String,ZkNodeProps> shards = slice.getShards();
- Set<Entry<String,ZkNodeProps>> shardsEntries = shards.entrySet();
- for (Entry<String,ZkNodeProps> shardEntry : shardsEntries) {
+ Map<String,Replica> shards = slice.getReplicasMap();
+ Set<Entry<String,Replica>> shardsEntries = shards.entrySet();
+ for (Entry<String,Replica> shardEntry : shardsEntries) {
ZkNodeProps props = shardEntry.getValue();
if (props.containsKey(ZkStateReader.LEADER_PROP)) {
Map<String,ZkNodeProps> leadersForCollection = leaders.get(collection.getKey());
@@ -122,11 +122,11 @@ public class ClusterState implements JSO
/**
* Get shard properties or null if shard is not found.
*/
- public ZkNodeProps getShardProps(final String collection, final String coreNodeName) {
+ public Replica getShardProps(final String collection, final String coreNodeName) {
Map<String, Slice> slices = getSlices(collection);
for(Slice slice: slices.values()) {
- if(slice.getShards().get(coreNodeName)!=null) {
- return slice.getShards().get(coreNodeName);
+ if(slice.getReplicasMap().get(coreNodeName)!=null) {
+ return slice.getReplicasMap().get(coreNodeName);
}
}
return null;
@@ -185,7 +185,7 @@ public class ClusterState implements JSO
public String getShardId(String coreNodeName) {
for (Entry<String, Map<String, Slice>> states: collectionStates.entrySet()){
for(Entry<String, Slice> slices: states.getValue().entrySet()) {
- for(Entry<String, ZkNodeProps> shards: slices.getValue().getShards().entrySet()){
+ for(Entry<String, Replica> shards: slices.getValue().getReplicasMap().entrySet()){
if(coreNodeName.equals(shards.getKey())) {
return slices.getKey();
}
@@ -226,7 +226,7 @@ public class ClusterState implements JSO
shardList.addAll(shards);
Collections.sort(shardList);
- ranges = hp.partitionRange(shards.size());
+ ranges = hp.partitionRange(shards.size(), Integer.MIN_VALUE, Integer.MAX_VALUE);
rangeInfo.ranges = ranges;
rangeInfo.shardList = shardList;
@@ -243,7 +243,7 @@ public class ClusterState implements JSO
int cnt = 0;
for (Range range : rangInfo.ranges) {
- if (hash < range.max) {
+ if (range.includes(hash)) {
return rangInfo.shardList.get(cnt);
}
cnt++;
@@ -286,21 +286,17 @@ public class ClusterState implements JSO
if (bytes == null || bytes.length == 0) {
return new ClusterState(version, liveNodes, Collections.<String, Map<String,Slice>>emptyMap());
}
-
+ // System.out.println("########## Loading ClusterState:" + new String(bytes));
LinkedHashMap<String, Object> stateMap = (LinkedHashMap<String, Object>) ZkStateReader.fromJSON(bytes);
HashMap<String,Map<String, Slice>> state = new HashMap<String,Map<String,Slice>>();
for(String collectionName: stateMap.keySet()){
Map<String, Object> collection = (Map<String, Object>)stateMap.get(collectionName);
Map<String, Slice> slices = new LinkedHashMap<String,Slice>();
- for(String sliceName: collection.keySet()) {
- Map<String, Map<String, String>> sliceMap = (Map<String, Map<String, String>>)collection.get(sliceName);
- Map<String, ZkNodeProps> shards = new LinkedHashMap<String,ZkNodeProps>();
- for(String shardName: sliceMap.keySet()) {
- shards.put(shardName, new ZkNodeProps(sliceMap.get(shardName)));
- }
- Slice slice = new Slice(sliceName, shards);
- slices.put(sliceName, slice);
+
+ for (Entry<String,Object> sliceEntry : collection.entrySet()) {
+ Slice slice = new Slice(sliceEntry.getKey(), null, (Map<String,Object>)sliceEntry.getValue());
+ slices.put(slice.getName(), slice);
}
state.put(collectionName, slices);
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java Fri Sep 21 17:21:34 2012
@@ -21,7 +21,6 @@ import java.util.concurrent.CountDownLat
import java.util.concurrent.TimeoutException;
import org.apache.solr.common.SolrException;
-import org.apache.zookeeper.SolrZooKeeper;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -38,6 +37,8 @@ class ConnectionManager implements Watch
private boolean connected;
private final ZkClientConnectionStrategy connectionStrategy;
+
+ private Object connectionUpdateLock = new Object();
private String zkServerAddress;
@@ -71,32 +72,46 @@ class ConnectionManager implements Watch
+ " path:" + event.getPath() + " type:" + event.getType());
}
- checkClosed();
+ if (isClosed) {
+ log.info("Client->ZooKeeper status change trigger but we are already closed");
+ return;
+ }
state = event.getState();
if (state == KeeperState.SyncConnected) {
connected = true;
clientConnected.countDown();
+ connectionStrategy.connected();
} else if (state == KeeperState.Expired) {
connected = false;
- log.info("Attempting to reconnect to recover relationship with ZooKeeper...");
-
+ log.info("Our previous ZooKeeper session was expired. Attempting to reconnect to recover relationship with ZooKeeper...");
+
try {
connectionStrategy.reconnect(zkServerAddress, zkClientTimeout, this,
new ZkClientConnectionStrategy.ZkUpdate() {
@Override
- public void update(SolrZooKeeper keeper) throws TimeoutException {
- synchronized (connectionStrategy) {
- checkClosed();
+ public void update(SolrZooKeeper keeper) {
+ // if keeper does not replace oldKeeper we must be sure to close it
+ synchronized (connectionUpdateLock) {
try {
waitForConnected(SolrZkClient.DEFAULT_CLIENT_CONNECT_TIMEOUT);
- checkClosed();
+ } catch (Exception e1) {
+ closeKeeper(keeper);
+ throw new RuntimeException(e1);
+ }
+ log.info("Connection with ZooKeeper reestablished.");
+ try {
client.updateKeeper(keeper);
} catch (InterruptedException e) {
+ closeKeeper(keeper);
+ Thread.currentThread().interrupt();
// we must have been asked to stop
- throw new RuntimeException("Giving up on connecting - we were interrupted");
+ throw new RuntimeException(e);
+ } catch(Throwable t) {
+ closeKeeper(keeper);
+ throw new RuntimeException(t);
}
- checkClosed();
+
if (onReconnect != null) {
onReconnect.command();
}
@@ -113,7 +128,9 @@ class ConnectionManager implements Watch
}
log.info("Connected:" + connected);
} else if (state == KeeperState.Disconnected) {
+ log.info("zkClient has disconnected");
connected = false;
+ connectionStrategy.disconnected();
} else {
connected = false;
}
@@ -135,24 +152,26 @@ class ConnectionManager implements Watch
}
public synchronized void waitForConnected(long waitForConnection)
- throws InterruptedException, TimeoutException {
+ throws TimeoutException {
+ log.info("Waiting for client to connect to ZooKeeper");
long expire = System.currentTimeMillis() + waitForConnection;
- long left = waitForConnection;
+ long left = 1;
while (!connected && left > 0) {
- wait(left);
- checkClosed();
+ if (isClosed) {
+ break;
+ }
+ try {
+ wait(500);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
left = expire - System.currentTimeMillis();
}
if (!connected) {
throw new TimeoutException("Could not connect to ZooKeeper " + zkServerAddress + " within " + waitForConnection + " ms");
}
- }
-
- private synchronized void checkClosed() {
- if (isClosed) {
- log.info("Not acting because I am closed");
- return;
- }
+ log.info("Client is connected to ZooKeeper");
}
public synchronized void waitForDisconnected(long timeout)
@@ -167,4 +186,16 @@ class ConnectionManager implements Watch
throw new TimeoutException("Did not disconnect");
}
}
+
+ private void closeKeeper(SolrZooKeeper keeper) {
+ try {
+ keeper.close();
+ } catch (InterruptedException e) {
+ // Restore the interrupted status
+ Thread.currentThread().interrupt();
+ log.error("", e);
+ throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
+ "", e);
+ }
+ }
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java Fri Sep 21 17:21:34 2012
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.concurrent.TimeoutException;
import org.apache.solr.common.SolrException;
-import org.apache.zookeeper.SolrZooKeeper;
import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java Fri Sep 21 17:21:34 2012
@@ -17,47 +17,104 @@ package org.apache.solr.common.cloud;
* limitations under the License.
*/
+import org.apache.noggit.JSONWriter;
+
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
* Class to partition int range into n ranges.
- *
+ *
*/
public class HashPartitioner {
-
- public static class Range {
- public long min;
- public long max;
-
- public Range(long min, long max) {
+
+ // Hash ranges can't currently "wrap" - i.e. max must be greater or equal to min.
+ // TODO: ranges may not be all contiguous in the future (either that or we will
+ // need an extra class to model a collection of ranges)
+ public static class Range implements JSONWriter.Writable {
+ public int min; // inclusive
+ public int max; // inclusive
+
+ public Range(int min, int max) {
+ assert min <= max;
this.min = min;
this.max = max;
}
+
+ public boolean includes(int hash) {
+ return hash >= min && hash <= max;
+ }
+
+ public String toString() {
+ return Integer.toHexString(min) + '-' + Integer.toHexString(max);
+ }
+
+
+ @Override
+ public int hashCode() {
+ // difficult numbers to hash... only the highest bits will tend to differ.
+ // ranges will only overlap during a split, so we can just hash the lower range.
+ return (min>>28) + (min>>25) + (min>>21) + min;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj.getClass() != getClass()) return false;
+ Range other = (Range)obj;
+ return this.min == other.min && this.max == other.max;
+ }
+
+ @Override
+ public void write(JSONWriter writer) {
+ writer.write(toString());
+ }
+ }
+
+ public Range fromString(String range) {
+ int middle = range.indexOf('-');
+ String minS = range.substring(0, middle);
+ String maxS = range.substring(middle+1);
+ long min = Long.parseLong(minS, 16); // use long to prevent the parsing routines from potentially worrying about overflow
+ long max = Long.parseLong(maxS, 16);
+ return new Range((int)min, (int)max);
+ }
+
+ public Range fullRange() {
+ return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
+ }
+
+ public List<Range> partitionRange(int partitions, Range range) {
+ return partitionRange(partitions, range.min, range.max);
}
-
+
/**
- * works up to 65537 before requested num of ranges is one short
- *
+ *
* @param partitions
* @return Range for each partition
*/
- public List<Range> partitionRange(int partitions) {
- // some hokey code to partition the int space
- long range = Integer.MAX_VALUE + (Math.abs((long) Integer.MIN_VALUE));
- long srange = range / partitions;
-
+ public List<Range> partitionRange(int partitions, int min, int max) {
+ assert max >= min;
+ if (partitions == 0) return Collections.EMPTY_LIST;
+ long range = (long)max - (long)min;
+ long srange = Math.max(1, range / partitions);
+
List<Range> ranges = new ArrayList<Range>(partitions);
-
- long end = 0;
- long start = Integer.MIN_VALUE;
-
- while (end < Integer.MAX_VALUE) {
+
+ long start = min;
+ long end = start;
+
+ while (end < max) {
end = start + srange;
- ranges.add(new Range(start, end));
+ // make last range always end exactly on MAX_VALUE
+ if (ranges.size() == partitions - 1) {
+ end = max;
+ }
+ ranges.add(new Range((int)start, (int)end));
start = end + 1L;
}
-
+
return ranges;
}
+
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java Fri Sep 21 17:21:34 2012
@@ -17,48 +17,81 @@ package org.apache.solr.common.cloud;
* limitations under the License.
*/
+import org.apache.noggit.JSONUtil;
import org.apache.noggit.JSONWriter;
-import java.util.Collections;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
- * A Slice contains immutable information about all shards that share the same
- * shard id (shard leader and replicas).
+ * A Slice contains immutable information about a logical shard (all replicas that share the same shard id).
*/
-public class Slice implements JSONWriter.Writable {
- private final Map<String,ZkNodeProps> shards;
+public class Slice extends ZkNodeProps {
+ public static String REPLICAS = "replicas";
+ public static String RANGE = "range";
+ public static String LEADER = "leader"; // FUTURE: do we want to record the leader as a slice property in the JSON (as opposed to isLeader as a replica property?)
+
private final String name;
+ private final HashPartitioner.Range range;
+ private final Integer replicationFactor;
+ private final Map<String,Replica> replicas;
+ private final Replica leader;
- public Slice(String name, Map<String,ZkNodeProps> shards) {
- this.shards = shards;
- this.name = name;
- }
-
/**
- * Get properties for all shards in this slice.
- *
- * @return map containing coreNodeName as the key, see
- * {@link ZkStateReader#getCoreNodeName(String, String)}, ZKNodeProps
- * as the value.
+ * @param name The name of the slice
+ * @param replicas The replicas of the slice. This is used directly and a copy is not made. If null, replicas will be constructed from props.
+ * @param props The properties of the slice - a shallow copy will always be made.
*/
- public Map<String,ZkNodeProps> getShards() {
- return Collections.unmodifiableMap(shards);
+ public Slice(String name, Map<String,Replica> replicas, Map<String,Object> props) {
+ super( props==null ? new LinkedHashMap<String,Object>(2) : new LinkedHashMap<String,Object>(props));
+ this.name = name;
+
+ Object rangeObj = propMap.get(RANGE);
+ HashPartitioner.Range tmpRange = null;
+ if (rangeObj instanceof HashPartitioner.Range) {
+ tmpRange = (HashPartitioner.Range)rangeObj;
+ } else if (rangeObj != null) {
+ HashPartitioner hp = new HashPartitioner();
+ tmpRange = hp.fromString(rangeObj.toString());
+ }
+ range = tmpRange;
+
+ replicationFactor = null; // future
+
+ // add the replicas *after* the other properties (for aesthetics, so it's easy to find slice properties in the JSON output)
+ this.replicas = replicas != null ? replicas : makeReplicas((Map<String,Object>)propMap.get(REPLICAS));
+ propMap.put(REPLICAS, this.replicas);
+
+ leader = findLeader();
}
- /**
- * Get a copy of the shards data this object holds.
- */
- public Map<String,ZkNodeProps> getShardsCopy() {
- Map<String,ZkNodeProps> shards = new HashMap<String,ZkNodeProps>();
- for (Map.Entry<String,ZkNodeProps> entry : this.shards.entrySet()) {
- ZkNodeProps zkProps = new ZkNodeProps(entry.getValue());
- shards.put(entry.getKey(), zkProps);
+
+ private Map<String,Replica> makeReplicas(Map<String,Object> genericReplicas) {
+ if (genericReplicas == null) return new HashMap<String,Replica>(1);
+ Map<String,Replica> result = new LinkedHashMap<String, Replica>(genericReplicas.size());
+ for (Map.Entry<String,Object> entry : genericReplicas.entrySet()) {
+ String name = entry.getKey();
+ Object val = entry.getValue();
+ Replica r;
+ if (val instanceof Replica) {
+ r = (Replica)val;
+ } else {
+ r = new Replica(name, (Map<String,Object>)val);
+ }
+ result.put(name, r);
+ }
+ return result;
+ }
+
+ private Replica findLeader() {
+ for (Replica replica : replicas.values()) {
+ if (replica.getStr(LEADER) != null) return replica;
}
- return shards;
+ return null;
}
-
+
/**
* Return slice name (shard id).
*/
@@ -66,13 +99,35 @@ public class Slice implements JSONWriter
return name;
}
+ /**
+ * Gets the list of replicas for this slice.
+ */
+ public Collection<Replica> getReplicas() {
+ return replicas.values();
+ }
+
+ /**
+ * Get the map of coreNodeName to replicas for this slice.
+ */
+ public Map<String, Replica> getReplicasMap() {
+ return replicas;
+ }
+
+ public Map<String,Replica> getReplicasCopy() {
+ return new LinkedHashMap<String,Replica>(replicas);
+ }
+
+ public Replica getLeader() {
+ return leader;
+ }
+
@Override
public String toString() {
- return "Slice [shards=" + shards + ", name=" + name + "]";
+ return name + ':' + JSONUtil.toJSON(propMap);
}
@Override
public void write(JSONWriter jsonWriter) {
- jsonWriter.write(shards);
+ jsonWriter.write(propMap);
}
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java Fri Sep 21 17:21:34 2012
@@ -39,7 +39,6 @@ import org.apache.solr.common.cloud.ZkCl
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.SolrZooKeeper;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
@@ -74,19 +73,17 @@ public class SolrZkClient {
private ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor();
private volatile boolean isClosed = false;
+ private ZkClientConnectionStrategy zkClientConnectionStrategy;
/**
* @param zkServerAddress
* @param zkClientTimeout
- * @throws InterruptedException
- * @throws TimeoutException
- * @throws IOException
*/
- public SolrZkClient(String zkServerAddress, int zkClientTimeout) throws InterruptedException, TimeoutException, IOException {
+ public SolrZkClient(String zkServerAddress, int zkClientTimeout) {
this(zkServerAddress, zkClientTimeout, new DefaultConnectionStrategy(), null);
}
- public SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, OnReconnect onReonnect) throws InterruptedException, TimeoutException, IOException {
+ public SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, OnReconnect onReonnect) {
this(zkServerAddress, zkClientTimeout, new DefaultConnectionStrategy(), onReonnect, zkClientConnectTimeout);
}
@@ -95,13 +92,9 @@ public class SolrZkClient {
* @param zkClientTimeout
* @param strat
* @param onReconnect
- * @throws InterruptedException
- * @throws TimeoutException
- * @throws IOException
*/
public SolrZkClient(String zkServerAddress, int zkClientTimeout,
- ZkClientConnectionStrategy strat, final OnReconnect onReconnect) throws InterruptedException,
- TimeoutException, IOException {
+ ZkClientConnectionStrategy strat, final OnReconnect onReconnect) {
this(zkServerAddress, zkClientTimeout, strat, onReconnect, DEFAULT_CLIENT_CONNECT_TIMEOUT);
}
@@ -111,38 +104,47 @@ public class SolrZkClient {
* @param strat
* @param onReconnect
* @param clientConnectTimeout
- * @throws InterruptedException
- * @throws TimeoutException
- * @throws IOException
*/
public SolrZkClient(String zkServerAddress, int zkClientTimeout,
- ZkClientConnectionStrategy strat, final OnReconnect onReconnect, int clientConnectTimeout) throws InterruptedException,
- TimeoutException, IOException {
+ ZkClientConnectionStrategy strat, final OnReconnect onReconnect, int clientConnectTimeout) {
+ this.zkClientConnectionStrategy = strat;
connManager = new ConnectionManager("ZooKeeperConnection Watcher:"
+ zkServerAddress, this, zkServerAddress, zkClientTimeout, strat, onReconnect);
- strat.connect(zkServerAddress, zkClientTimeout, connManager,
- new ZkUpdate() {
- @Override
- public void update(SolrZooKeeper zooKeeper) {
- SolrZooKeeper oldKeeper = keeper;
- keeper = zooKeeper;
- if (oldKeeper != null) {
+ try {
+ strat.connect(zkServerAddress, zkClientTimeout, connManager,
+ new ZkUpdate() {
+ @Override
+ public void update(SolrZooKeeper zooKeeper) {
+ SolrZooKeeper oldKeeper = keeper;
+ keeper = zooKeeper;
try {
- oldKeeper.close();
- } catch (InterruptedException e) {
- // Restore the interrupted status
- Thread.currentThread().interrupt();
- log.error("", e);
- throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
- "", e);
+ closeKeeper(oldKeeper);
+ } finally {
+ if (isClosed) {
+ // we may have been closed
+ closeKeeper(SolrZkClient.this.keeper);
+ }
}
}
- }
- });
- connManager.waitForConnected(clientConnectTimeout);
+ });
+ } catch (Throwable e) {
+ connManager.close();
+ throw new RuntimeException();
+ }
+
+ try {
+ connManager.waitForConnected(clientConnectTimeout);
+ } catch (Throwable e) {
+ connManager.close();
+ throw new RuntimeException();
+ }
numOpens.incrementAndGet();
}
+ public ZkClientConnectionStrategy getZkClientConnectionStrategy() {
+ return zkClientConnectionStrategy;
+ }
+
/**
* @return true if client is connected
*/
@@ -648,14 +650,11 @@ public class SolrZkClient {
return prettyPrint(input, 2);
}
- /**
- * @throws InterruptedException
- */
- public void close() throws InterruptedException {
+ public void close() {
if (isClosed) return; // it's okay if we over close - same as solrcore
isClosed = true;
try {
- keeper.close();
+ closeKeeper(keeper);
} finally {
connManager.close();
}
@@ -678,11 +677,27 @@ public class SolrZkClient {
if (oldKeeper != null) {
oldKeeper.close();
}
+ // we might have been closed already
+ if (isClosed) this.keeper.close();
}
public SolrZooKeeper getSolrZooKeeper() {
return keeper;
}
+
+ private void closeKeeper(SolrZooKeeper keeper) {
+ if (keeper != null) {
+ try {
+ keeper.close();
+ } catch (InterruptedException e) {
+ // Restore the interrupted status
+ Thread.currentThread().interrupt();
+ log.error("", e);
+ throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "",
+ e);
+ }
+ }
+ }
// yeah, it's recursive :(
public void clean(String path) throws InterruptedException, KeeperException {
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java Fri Sep 21 17:21:34 2012
@@ -18,18 +18,64 @@ package org.apache.solr.common.cloud;
*/
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeoutException;
-import org.apache.zookeeper.SolrZooKeeper;
+import org.apache.solr.common.SolrException;
import org.apache.zookeeper.Watcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
public abstract class ZkClientConnectionStrategy {
+ private static Logger log = LoggerFactory.getLogger(ZkClientConnectionStrategy.class);
+
+ private List<DisconnectedListener> disconnectedListeners = new ArrayList<DisconnectedListener>();
+ private List<ConnectedListener> connectedListeners = new ArrayList<ConnectedListener>();
+
public abstract void connect(String zkServerAddress, int zkClientTimeout, Watcher watcher, ZkUpdate updater) throws IOException, InterruptedException, TimeoutException;
public abstract void reconnect(String serverAddress, int zkClientTimeout, Watcher watcher, ZkUpdate updater) throws IOException, InterruptedException, TimeoutException;
+ public synchronized void disconnected() {
+ for (DisconnectedListener listener : disconnectedListeners) {
+ try {
+ listener.disconnected();
+ } catch (Throwable t) {
+ SolrException.log(log, "", t);
+ }
+ }
+ }
+
+ public synchronized void connected() {
+ for (ConnectedListener listener : connectedListeners) {
+ try {
+ listener.connected();
+ } catch (Throwable t) {
+ SolrException.log(log, "", t);
+ }
+ }
+ }
+
+ public interface DisconnectedListener {
+ public void disconnected();
+ };
+
+ public interface ConnectedListener {
+ public void connected();
+ };
+
+
+ public synchronized void addDisconnectedListener(DisconnectedListener listener) {
+ disconnectedListeners.add(listener);
+ }
+
+ public synchronized void addConnectedListener(ConnectedListener listener) {
+ connectedListeners.add(listener);
+ }
+
public static abstract class ZkUpdate {
public abstract void update(SolrZooKeeper zooKeeper) throws InterruptedException, TimeoutException, IOException;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java Fri Sep 21 17:21:34 2012
@@ -73,9 +73,9 @@ public class ZkCmdExecutor {
Thread.currentThread().interrupt();
throw new InterruptedException();
}
- if (Thread.currentThread() instanceof SafeStopThread) {
- if (((SafeStopThread) Thread.currentThread()).isClosed()) {
- throw new RuntimeException("Interrupted");
+ if (Thread.currentThread() instanceof ClosableThread) {
+ if (((ClosableThread) Thread.currentThread()).isClosed()) {
+ throw exception;
}
}
retryDelay(i);
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java Fri Sep 21 17:21:34 2012
@@ -24,40 +24,36 @@ public class ZkCoreNodeProps {
this.nodeProps = nodeProps;
}
- // may return null
public String getCoreUrl() {
- return getCoreUrl(nodeProps.get(ZkStateReader.BASE_URL_PROP), nodeProps.get(ZkStateReader.CORE_NAME_PROP));
+ return getCoreUrl(nodeProps.getStr(ZkStateReader.BASE_URL_PROP), nodeProps.getStr(ZkStateReader.CORE_NAME_PROP));
}
public String getNodeName() {
- return nodeProps.get(ZkStateReader.NODE_NAME_PROP);
+ return nodeProps.getStr(ZkStateReader.NODE_NAME_PROP);
}
public String getState() {
- return nodeProps.get(ZkStateReader.STATE_PROP);
+ return nodeProps.getStr(ZkStateReader.STATE_PROP);
}
public String getBaseUrl() {
- return nodeProps.get(ZkStateReader.BASE_URL_PROP);
+ return nodeProps.getStr(ZkStateReader.BASE_URL_PROP);
}
public String getCoreName() {
- return nodeProps.get(ZkStateReader.CORE_NAME_PROP);
+ return nodeProps.getStr(ZkStateReader.CORE_NAME_PROP);
}
public static String getCoreUrl(ZkNodeProps nodeProps) {
- return getCoreUrl(nodeProps.get(ZkStateReader.BASE_URL_PROP), nodeProps.get(ZkStateReader.CORE_NAME_PROP));
+ return getCoreUrl(nodeProps.getStr(ZkStateReader.BASE_URL_PROP), nodeProps.getStr(ZkStateReader.CORE_NAME_PROP));
}
public static String getCoreUrl(String baseUrl, String coreName) {
StringBuilder sb = new StringBuilder();
- if (baseUrl == null) return null;
- if (coreName == null) return null;
sb.append(baseUrl);
if (!baseUrl.endsWith("/")) sb.append("/");
- sb.append(coreName == null ? "" : coreName);
+ sb.append(coreName);
if (!(sb.substring(sb.length() - 1).equals("/"))) sb.append("/");
-
return sb.toString();
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java Fri Sep 21 17:21:34 2012
@@ -17,51 +17,55 @@ package org.apache.solr.common.cloud;
* limitations under the License.
*/
+import org.apache.noggit.JSONUtil;
+import org.apache.noggit.JSONWriter;
+
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
-
-import org.apache.noggit.JSONWriter;
+import java.util.Set;
/**
- * ZkNodeProps contains immutable properties for a shard/solr core.
+ * ZkNodeProps contains generic immutable properties.
*/
public class ZkNodeProps implements JSONWriter.Writable {
- private final Map<String,String> propMap;
+ protected final Map<String,Object> propMap;
/**
* Construct ZKNodeProps from map.
*/
- public ZkNodeProps(Map<String,String> propMap) {
- this.propMap = new HashMap<String,String>();
- this.propMap.putAll(propMap);
+ public ZkNodeProps(Map<String,Object> propMap) {
+ this.propMap = propMap;
}
-
- /**
- * Construct ZKNodeProps from information of an existingZKNodeProps.
- */
- public ZkNodeProps(ZkNodeProps zkNodeProps) {
- this.propMap = new HashMap<String,String>();
- this.propMap.putAll(zkNodeProps.propMap);
- }
-
+
+
/**
* Constructor that populates the from array of Strings in form key1, value1,
* key2, value2, ..., keyN, valueN
*/
public ZkNodeProps(String... keyVals) {
- if (keyVals.length % 2 != 0) {
+ this( makeMap((Object[])keyVals) );
+ }
+
+ public static ZkNodeProps fromKeyVals(Object... keyVals) {
+ return new ZkNodeProps( makeMap(keyVals) );
+ }
+
+ public static Map<String,Object> makeMap(Object... keyVals) {
+ if ((keyVals.length & 0x01) != 0) {
throw new IllegalArgumentException("arguments should be key,value");
}
- propMap = new HashMap<String,String>();
+ Map<String,Object> propMap = new HashMap<String,Object>(keyVals.length>>1);
for (int i = 0; i < keyVals.length; i+=2) {
- propMap.put(keyVals[i], keyVals[i+1]);
+ propMap.put(keyVals[i].toString(), keyVals[i+1]);
}
+ return propMap;
}
-
+
+
/**
* Get property keys.
*/
@@ -72,15 +76,20 @@ public class ZkNodeProps implements JSON
/**
* Get all properties as map.
*/
- public Map<String,String> getProperties() {
+ public Map<String, Object> getProperties() {
return Collections.unmodifiableMap(propMap);
}
+ /** Returns a shallow writable copy of the properties */
+ public Map<String,Object> shallowCopy() {
+ return new LinkedHashMap<String, Object>(propMap);
+ }
+
/**
- * Create ZkNodeProps from json string that is typically stored in zookeeper.
+ * Create Replica from json string that is typically stored in zookeeper.
*/
public static ZkNodeProps load(byte[] bytes) {
- Map<String, String> props = (Map<String, String>) ZkStateReader.fromJSON(bytes);
+ Map<String, Object> props = (Map<String, Object>) ZkStateReader.fromJSON(bytes);
return new ZkNodeProps(props);
}
@@ -90,20 +99,28 @@ public class ZkNodeProps implements JSON
}
/**
- * Get property value.
+ * Get a string property value.
*/
- public String get(String key) {
+ public String getStr(String key) {
+ Object o = propMap.get(key);
+ return o == null ? null : o.toString();
+ }
+
+ public Object get(String key) {
return propMap.get(key);
}
@Override
public String toString() {
+ return JSONUtil.toJSON(this);
+ /***
StringBuilder sb = new StringBuilder();
- Set<Entry<String,String>> entries = propMap.entrySet();
- for(Entry<String,String> entry : entries) {
+ Set<Entry<String,Object>> entries = propMap.entrySet();
+ for(Entry<String,Object> entry : entries) {
sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
}
return sb.toString();
+ ***/
}
/**
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Fri Sep 21 17:21:34 2012
@@ -141,7 +141,7 @@ public class ZkStateReader {
public void command() {
try {
- ZkStateReader.this.createClusterStateWatchersAndUpdate();
+ ZkStateReader.this.createClusterStateWatchersAndUpdate();
} catch (KeeperException e) {
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
@@ -373,31 +373,16 @@ public class ZkStateReader {
public void close() {
if (closeClient) {
- try {
- zkClient.close();
- } catch (InterruptedException e) {
- // Restore the interrupted status
- Thread.currentThread().interrupt();
- log.error("", e);
- throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "",
- e);
- }
+ zkClient.close();
}
}
abstract class RunnableWatcher implements Runnable {
- Watcher watcher;
- public RunnableWatcher(Watcher watcher){
- this.watcher = watcher;
- }
+ Watcher watcher;
+ public RunnableWatcher(Watcher watcher){
+ this.watcher = watcher;
+ }
- }
-
- /**
- * Get shard leader url.
- */
- public String getLeaderUrl(String collection, String shard) throws InterruptedException, KeeperException {
- return getLeaderUrl(collection, shard, 1000);
}
public String getLeaderUrl(String collection, String shard, int timeout)
@@ -425,7 +410,7 @@ public class ZkStateReader {
}
Thread.sleep(50);
}
- throw new RuntimeException("No registered leader was found, collection:" + collection + " slice:" + shard);
+ throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No registered leader was found, collection:" + collection + " slice:" + shard);
}
/**
@@ -473,10 +458,10 @@ public class ZkStateReader {
throw new ZooKeeperException(ErrorCode.BAD_REQUEST, "Could not find shardId in zk: " + shardId);
}
- Map<String,ZkNodeProps> shardMap = replicas.getShards();
+ Map<String,Replica> shardMap = replicas.getReplicasMap();
List<ZkCoreNodeProps> nodes = new ArrayList<ZkCoreNodeProps>(shardMap.size());
String filterNodeName = thisNodeName + "_" + coreName;
- for (Entry<String,ZkNodeProps> entry : shardMap.entrySet()) {
+ for (Entry<String,Replica> entry : shardMap.entrySet()) {
ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
String coreNodeName = nodeProps.getNodeName() + "_" + nodeProps.getCoreName();
if (clusterState.liveNodesContain(nodeProps.getNodeName()) && !coreNodeName.equals(filterNodeName)) {
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java Fri Sep 21 17:21:34 2012
@@ -92,7 +92,8 @@ public interface CoreAdminParams
SWAP,
RENAME,
MERGEINDEXES,
- PREPRECOVERY,
+ SPLIT,
+ PREPRECOVERY,
REQUESTRECOVERY,
REQUESTSYNCSHARD;
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java Fri Sep 21 17:21:34 2012
@@ -76,6 +76,7 @@ public abstract class ContentStreamBase
sourceInfo = "url";
}
+ @Override
public InputStream getStream() throws IOException {
URLConnection conn = this.url.openConnection();
@@ -102,37 +103,33 @@ public abstract class ContentStreamBase
sourceInfo = file.toURI().toString();
}
+ @Override
public String getContentType() {
if(contentType==null) {
+ InputStream stream = null;
try {
- char first = (char)new FileInputStream( file ).read();
+ stream = new FileInputStream(file);
+ char first = (char)stream.read();
if(first == '<') {
return "application/xml";
}
if(first == '{') {
return "application/json";
}
+ } catch(Exception ex) {
+ } finally {
+ if (stream != null) try {
+ stream.close();
+ } catch (IOException ioe) {}
}
- catch(Exception ex) {}
}
return contentType;
}
+ @Override
public InputStream getStream() throws IOException {
return new FileInputStream( file );
}
-
- /**
- * If an charset is defined (by the contentType) use that, otherwise
- * use a UTF-8 reader
- */
- @Override
- public Reader getReader() throws IOException {
- String charset = getCharsetFromContentType( contentType );
- return charset == null
- ? new InputStreamReader(getStream(), "UTF-8")
- : new InputStreamReader( getStream(), charset );
- }
}
@@ -152,6 +149,7 @@ public abstract class ContentStreamBase
sourceInfo = "string";
}
+ @Override
public String getContentType() {
if(contentType==null && str.length() > 0) {
char first = str.charAt(0);
@@ -166,6 +164,7 @@ public abstract class ContentStreamBase
return contentType;
}
+ @Override
public InputStream getStream() throws IOException {
return new ByteArrayInputStream( str.getBytes(DEFAULT_CHARSET) );
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/FastOutputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/FastOutputStream.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/FastOutputStream.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/FastOutputStream.java Fri Sep 21 17:21:34 2012
@@ -57,8 +57,8 @@ public class FastOutputStream extends Ou
public void write(byte b) throws IOException {
if (pos >= buf.length) {
- flush(buf, 0, buf.length);
written += pos;
+ flush(buf, 0, buf.length);
pos=0;
}
buf[pos++] = b;
@@ -66,29 +66,40 @@ public class FastOutputStream extends Ou
@Override
public void write(byte arr[], int off, int len) throws IOException {
- int space = buf.length - pos;
- if (len < space) {
- System.arraycopy(arr, off, buf, pos, len);
- pos += len;
- } else if (len<buf.length) {
- // if the data to write is small enough, buffer it.
+
+ for(;;) {
+ int space = buf.length - pos;
+
+ if (len <= space) {
+ System.arraycopy(arr, off, buf, pos, len);
+ pos += len;
+ return;
+ } else if (len > buf.length) {
+ if (pos>0) {
+ flush(buf,0,pos); // flush
+ written += pos;
+ pos=0;
+ }
+ // don't buffer, just write to sink
+ flush(arr, off, len);
+ written += len;
+ return;
+ }
+
+ // buffer is too big to fit in the free space, but
+ // not big enough to warrant writing on its own.
+ // write whatever we can fit, then flush and iterate.
+
System.arraycopy(arr, off, buf, pos, space);
+ written += buf.length; // important to do this first, since buf.length can change after a flush!
flush(buf, 0, buf.length);
- written += buf.length;
- pos = len-space;
- System.arraycopy(arr, off+space, buf, 0, pos);
- } else {
- if (pos>0) {
- flush(buf,0,pos); // flush
- written += pos;
- pos=0;
- }
- // don't buffer, just write to sink
- flush(arr, off, len);
- written += len;
+ pos = 0;
+ off += space;
+ len -= space;
}
}
+
/** reserve at least len bytes at the end of the buffer.
* Invalid if len > buffer.length
* @param len
@@ -182,8 +193,8 @@ public class FastOutputStream extends Ou
*/
public void flushBuffer() throws IOException {
if (pos > 0) {
- flush(buf, 0, pos);
written += pos;
+ flush(buf, 0, pos);
pos=0;
}
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java Fri Sep 21 17:21:34 2012
@@ -367,12 +367,12 @@ public class NamedList<T> implements Clo
@Override
public String toString()
{
- return getKey()+"="+getValue();
+ return getKey()+"="+getValue();
}
- public T setValue(T value) {
+ public T setValue(T value) {
return list.setVal(index, value);
- }
+ }
};
return nv;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java Fri Sep 21 17:21:34 2012
@@ -41,7 +41,7 @@ public class SolrExampleBinaryTest exten
{
try {
// setup the server...
- String url = "http://localhost:"+port+context;
+ String url = "http://127.0.0.1:"+port+context;
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);