New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to murmurhash3 to route documents to shards. #7954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,6 @@ | |
package org.elasticsearch.cluster.routing.operation; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should drop this module entirely and a make it hardcoded wherever it's used? Or at least not changeable? I don't think anybody should change this module or have it's own operation routing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kimchy what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be delayed to another PR? I am slightly concerned this PR has already been awaiting merge for a long time? |
||
import com.google.common.collect.ImmutableList; | ||
import org.elasticsearch.cluster.routing.operation.hash.HashFunction; | ||
import org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction; | ||
import org.elasticsearch.cluster.routing.operation.plain.PlainOperationRoutingModule; | ||
import org.elasticsearch.common.inject.AbstractModule; | ||
import org.elasticsearch.common.inject.Module; | ||
|
@@ -48,6 +46,5 @@ public Iterable<? extends Module> spawnModules() { | |
|
||
@Override | ||
protected void configure() { | ||
bind(HashFunction.class).to(settings.getAsClass("cluster.routing.operation.hash.type", DjbHashFunction.class, "org.elasticsearch.cluster.routing.operation.hash.", "HashFunction")).asEagerSingleton(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.operation.hash.murmur3; | ||
|
||
import org.apache.lucene.util.StringHelper; | ||
import org.elasticsearch.cluster.routing.operation.hash.HashFunction; | ||
|
||
/** | ||
* Hash function based on the Murmur3 algorithm, which is the default as of Elasticsearch 2.0. | ||
*/ | ||
public class Murmur3HashFunction implements HashFunction { | ||
|
||
@Override | ||
public int hash(String routing) { | ||
final byte[] bytesToHash = new byte[routing.length() * 2]; | ||
for (int i = 0; i < routing.length(); ++i) { | ||
final char c = routing.charAt(i); | ||
final byte b1 = (byte) c, b2 = (byte) (c >>> 8); | ||
assert ((b1 & 0xFF) | ((b2 & 0xFF) << 8)) == c; // no information loss | ||
bytesToHash[i * 2] = b1; | ||
bytesToHash[i * 2 + 1] = b2; | ||
} | ||
return StringHelper.murmurhash3_x86_32(bytesToHash, 0, bytesToHash.length, 0); | ||
} | ||
|
||
@Override | ||
public int hash(String type, String id) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will make our tests go wild for rest compat so be prepared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm maybe not if we go with 2.x only change since REST tests only run against major version and if not we should fix it.