You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2011/12/15 05:23:20 UTC
svn commit: r1214620 - in /lucene/dev/branches/solrcloud/solr:
core/src/java/org/apache/solr/update/processor/
solrj/src/java/org/apache/solr/client/solrj/impl/
solrj/src/java/org/apache/solr/common/cloud/
Author: markrmiller
Date: Thu Dec 15 04:23:20 2011
New Revision: 1214620
URL: http://svn.apache.org/viewvc?rev=1214620&view=rev
Log:
pull out a hasher class so eventually we can mess with cloudsolrserver sending directly to shard leaders
Added:
lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/Hasher.java (with props)
Modified:
lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java?rev=1214620&r1=1214619&r2=1214620&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java Thu Dec 15 04:23:20 2011
@@ -32,6 +32,7 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.cloud.CloudState;
import org.apache.solr.common.cloud.HashPartitioner;
+import org.apache.solr.common.cloud.Hasher;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -84,6 +85,7 @@ public class DistributedUpdateProcessor
private String collection;
private ZkController zkController;
+ private Hasher hasher = new Hasher();
// these are setup at the start of each request processing
// method in this update processor
@@ -140,7 +142,7 @@ public class DistributedUpdateProcessor
// TODO: we are reading the leader from zk every time - we should cache
// this and watch for changes?? Just pull it from ZkController cluster state probably?
- String shardId = getShard(hash, collection, zkController.getCloudState()); // get the right shard based on the hash...
+ String shardId = zkController.getCloudState().getShard(hash, collection); // get the right shard based on the hash...
try {
ZkNodeProps leaderProps = zkController.getZkStateReader().getLeaderProps(
@@ -178,13 +180,6 @@ public class DistributedUpdateProcessor
return shards;
}
-
- private String getShard(int hash, String collection, CloudState cloudState) {
- // ranges should be part of the cloud state and eventually gotten from zk
-
- // get the shard names
- return cloudState.getShard(hash, collection);
- }
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
@@ -649,12 +644,10 @@ public class DistributedUpdateProcessor
// make the hash pluggable of course.
// The hash also needs to be pluggable
private int hash(AddUpdateCommand cmd) {
- BytesRef br = cmd.getIndexedId();
- return Hash.murmurhash3_x86_32(br.bytes, br.offset, br.length, 0);
+ return hasher.hash(cmd);
}
private int hash(DeleteUpdateCommand cmd) {
- BytesRef br = cmd.getIndexedId();
- return Hash.murmurhash3_x86_32(br.bytes, br.offset, br.length, 0);
+ return hasher.hash(cmd);
}
}
Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java?rev=1214620&r1=1214619&r2=1214620&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java (original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java Thu Dec 15 04:23:20 2011
@@ -33,6 +33,7 @@ import org.apache.solr.client.solrj.Solr
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.CloudState;
+import org.apache.solr.common.cloud.Hasher;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -49,7 +50,9 @@ public class CloudSolrServer extends Sol
private int zkClientTimeout = 10000;
private String defaultCollection;
private LBHttpSolrServer lbServer;
- Random rand = new Random();
+ private Random rand = new Random();
+ // TODO
+ //private Hasher hasher;
/**
* @param zkHost The address of the zookeeper quorum containing the cloud state
@@ -62,10 +65,16 @@ public class CloudSolrServer extends Sol
* @param zkHost The address of the zookeeper quorum containing the cloud state
*/
public CloudSolrServer(String zkHost, LBHttpSolrServer lbServer) {
- System.out.println("new cloud server");
this.zkHost = zkHost;
this.lbServer = lbServer;
}
+
+// TODO
+// public CloudSolrServer(String zkHost, LBHttpSolrServer lbServer, Hasher hasher) {
+// this.zkHost = zkHost;
+// this.lbServer = lbServer;
+// this.hasher = hasher;
+// }
/** Sets the default collection for request */
public void setDefaultCollection(String collection) {
@@ -123,7 +132,7 @@ public class CloudSolrServer extends Sol
public NamedList<Object> request(SolrRequest request) throws SolrServerException, IOException {
connect();
- // TODO: if you can hash here, you could favor the shard leader
+ // TODO: if you can hash here, you could favor the shard leader - more work needed though
CloudState cloudState = zkStateReader.getCloudState();
@@ -142,7 +151,7 @@ public class CloudSolrServer extends Sol
}
Set<String> liveNodes = cloudState.getLiveNodes();
-
+
// IDEA: have versions on various things... like a global cloudState version
// or shardAddressVersion (which only changes when the shards change)
// to allow caching.
Added: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/Hasher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/Hasher.java?rev=1214620&view=auto
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/Hasher.java (added)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/cloud/Hasher.java Thu Dec 15 04:23:20 2011
@@ -0,0 +1,35 @@
+package org.apache.solr.common.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.common.util.Hash;
+import org.apache.solr.update.AddUpdateCommand;
+import org.apache.solr.update.DeleteUpdateCommand;
+
+public class Hasher {
+ public int hash(AddUpdateCommand cmd) {
+ BytesRef br = cmd.getIndexedId();
+ return Hash.murmurhash3_x86_32(br.bytes, br.offset, br.length, 0);
+ }
+
+ public int hash(DeleteUpdateCommand cmd) {
+ BytesRef br = cmd.getIndexedId();
+ return Hash.murmurhash3_x86_32(br.bytes, br.offset, br.length, 0);
+ }
+}