Drop legacy hashfunctions - these tests don't work anymore since we dropped support for them
This commit is contained in:
parent
48162fa90b
commit
7329493783
|
@ -21,7 +21,6 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.Diff;
|
||||
import org.elasticsearch.cluster.Diffable;
|
||||
|
@ -29,8 +28,6 @@ import org.elasticsearch.cluster.DiffableUtils;
|
|||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodeFilters;
|
||||
import org.elasticsearch.cluster.routing.HashFunction;
|
||||
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
|
@ -167,16 +164,12 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
public static final String SETTING_PRIORITY = "index.priority";
|
||||
public static final String SETTING_CREATION_DATE_STRING = "index.creation_date_string";
|
||||
public static final String SETTING_INDEX_UUID = "index.uuid";
|
||||
public static final String SETTING_LEGACY_ROUTING_HASH_FUNCTION = "index.legacy.routing.hash.type";
|
||||
public static final String SETTING_LEGACY_ROUTING_USE_TYPE = "index.legacy.routing.use_type";
|
||||
public static final String SETTING_DATA_PATH = "index.data_path";
|
||||
public static final String SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE = "index.shared_filesystem.recover_on_any_node";
|
||||
public static final String INDEX_UUID_NA_VALUE = "_na_";
|
||||
|
||||
|
||||
// hard-coded hash function as of 2.0
|
||||
// older indices will read which hash function to use in their index settings
|
||||
private static final HashFunction MURMUR3_HASH_FUNCTION = new Murmur3HashFunction();
|
||||
|
||||
|
||||
private final String index;
|
||||
private final long version;
|
||||
|
@ -200,8 +193,6 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
private final Version indexCreatedVersion;
|
||||
private final Version indexUpgradedVersion;
|
||||
private final org.apache.lucene.util.Version minimumCompatibleLuceneVersion;
|
||||
private final HashFunction routingHashFunction;
|
||||
private final boolean useTypeForRouting;
|
||||
|
||||
private IndexMetaData(String index, long version, State state, Settings settings, ImmutableOpenMap<String, MappingMetaData> mappings, ImmutableOpenMap<String, AliasMetaData> aliases, ImmutableOpenMap<String, Custom> customs) {
|
||||
if (settings.getAsInt(SETTING_NUMBER_OF_SHARDS, null) == null) {
|
||||
|
@ -249,23 +240,6 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
} else {
|
||||
this.minimumCompatibleLuceneVersion = null;
|
||||
}
|
||||
final String hashFunction = settings.get(SETTING_LEGACY_ROUTING_HASH_FUNCTION);
|
||||
if (hashFunction == null) {
|
||||
routingHashFunction = MURMUR3_HASH_FUNCTION;
|
||||
} else {
|
||||
final Class<? extends HashFunction> hashFunctionClass;
|
||||
try {
|
||||
hashFunctionClass = Class.forName(hashFunction).asSubclass(HashFunction.class);
|
||||
} catch (ClassNotFoundException|NoClassDefFoundError e) {
|
||||
throw new ElasticsearchException("failed to load custom hash function [" + hashFunction + "]", e);
|
||||
}
|
||||
try {
|
||||
routingHashFunction = hashFunctionClass.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new IllegalStateException("Cannot instantiate hash function", e);
|
||||
}
|
||||
}
|
||||
useTypeForRouting = settings.getAsBoolean(SETTING_LEGACY_ROUTING_USE_TYPE, false);
|
||||
}
|
||||
|
||||
public String index() {
|
||||
|
@ -335,29 +309,6 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
return minimumCompatibleLuceneVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link HashFunction} that should be used for routing.
|
||||
*/
|
||||
public HashFunction routingHashFunction() {
|
||||
return routingHashFunction;
|
||||
}
|
||||
|
||||
public HashFunction getRoutingHashFunction() {
|
||||
return routingHashFunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether routing should use the _type in addition to the _id in
|
||||
* order to decide which shard a document should go to.
|
||||
*/
|
||||
public boolean routingUseType() {
|
||||
return useTypeForRouting;
|
||||
}
|
||||
|
||||
public boolean getRoutingUseType() {
|
||||
return routingUseType();
|
||||
}
|
||||
|
||||
public long creationDate() {
|
||||
return settings.getAsLong(SETTING_CREATION_DATE, -1l);
|
||||
}
|
||||
|
|
|
@ -21,11 +21,7 @@ package org.elasticsearch.cluster.metadata;
|
|||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.cluster.routing.HashFunction;
|
||||
import org.elasticsearch.cluster.routing.SimpleHashFunction;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -35,7 +31,6 @@ import org.elasticsearch.index.analysis.AnalysisService;
|
|||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.similarity.SimilarityService;
|
||||
import org.elasticsearch.index.store.IndexStoreModule;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -54,47 +49,12 @@ import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
|||
*/
|
||||
public class MetaDataIndexUpgradeService extends AbstractComponent {
|
||||
|
||||
private static final String DEPRECATED_SETTING_ROUTING_HASH_FUNCTION = "cluster.routing.operation.hash.type";
|
||||
private static final String DEPRECATED_SETTING_ROUTING_USE_TYPE = "cluster.routing.operation.use_type";
|
||||
|
||||
private final Class<? extends HashFunction> pre20HashFunction;
|
||||
private final Boolean pre20UseType;
|
||||
private final ScriptService scriptService;
|
||||
|
||||
@Inject
|
||||
public MetaDataIndexUpgradeService(Settings settings, ScriptService scriptService) {
|
||||
super(settings);
|
||||
this.scriptService = scriptService;
|
||||
final String pre20HashFunctionName = settings.get(DEPRECATED_SETTING_ROUTING_HASH_FUNCTION, null);
|
||||
final boolean hasCustomPre20HashFunction = pre20HashFunctionName != null;
|
||||
// the hash function package has changed we replace the two hash functions if their fully qualified name is used.
|
||||
if (hasCustomPre20HashFunction) {
|
||||
switch (pre20HashFunctionName) {
|
||||
case "Simple":
|
||||
case "simple":
|
||||
case "org.elasticsearch.cluster.routing.operation.hash.simple.SimpleHashFunction":
|
||||
pre20HashFunction = SimpleHashFunction.class;
|
||||
break;
|
||||
case "Djb":
|
||||
case "djb":
|
||||
case "org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction":
|
||||
pre20HashFunction = DjbHashFunction.class;
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
pre20HashFunction = Class.forName(pre20HashFunctionName).asSubclass(HashFunction.class);
|
||||
} catch (ClassNotFoundException|NoClassDefFoundError e) {
|
||||
throw new ElasticsearchException("failed to load custom hash function [" + pre20HashFunctionName + "]", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pre20HashFunction = DjbHashFunction.class;
|
||||
}
|
||||
pre20UseType = settings.getAsBoolean(DEPRECATED_SETTING_ROUTING_USE_TYPE, null);
|
||||
if (hasCustomPre20HashFunction || pre20UseType != null) {
|
||||
logger.warn("Settings [{}] and [{}] are deprecated. Index settings from your old indices have been updated to record the fact that they "
|
||||
+ "used some custom routing logic, you can now remove these settings from your `elasticsearch.yml` file", DEPRECATED_SETTING_ROUTING_HASH_FUNCTION, DEPRECATED_SETTING_ROUTING_USE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +70,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
|||
return indexMetaData;
|
||||
}
|
||||
checkSupportedVersion(indexMetaData);
|
||||
IndexMetaData newMetaData = upgradeLegacyRoutingSettings(indexMetaData);
|
||||
IndexMetaData newMetaData = indexMetaData;
|
||||
newMetaData = addDefaultUnitsIfNeeded(newMetaData);
|
||||
checkMappingsCompatibility(newMetaData);
|
||||
newMetaData = markAsUpgraded(newMetaData);
|
||||
|
@ -122,7 +82,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
|||
* Checks if the index was already opened by this version of Elasticsearch and doesn't require any additional checks.
|
||||
*/
|
||||
private boolean isUpgraded(IndexMetaData indexMetaData) {
|
||||
return indexMetaData.upgradeVersion().onOrAfter(Version.V_2_0_0_beta1);
|
||||
return indexMetaData.upgradeVersion().onOrAfter(Version.V_3_0_0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,32 +114,6 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Elasticsearch 2.0 deprecated custom routing hash functions. So what we do here is that for old indices, we
|
||||
* move this old and deprecated node setting to an index setting so that we can keep things backward compatible.
|
||||
*/
|
||||
private IndexMetaData upgradeLegacyRoutingSettings(IndexMetaData indexMetaData) {
|
||||
if (indexMetaData.settings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION) == null
|
||||
&& indexMetaData.getCreationVersion().before(Version.V_2_0_0_beta1)) {
|
||||
// these settings need an upgrade
|
||||
Settings indexSettings = Settings.builder().put(indexMetaData.settings())
|
||||
.put(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION, pre20HashFunction)
|
||||
.put(IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE, pre20UseType == null ? false : pre20UseType)
|
||||
.build();
|
||||
return IndexMetaData.builder(indexMetaData)
|
||||
.version(indexMetaData.version())
|
||||
.settings(indexSettings)
|
||||
.build();
|
||||
} else if (indexMetaData.getCreationVersion().onOrAfter(Version.V_2_0_0_beta1)) {
|
||||
if (indexMetaData.getSettings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION) != null
|
||||
|| indexMetaData.getSettings().get(IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE) != null) {
|
||||
throw new IllegalStateException("Index [" + indexMetaData.getIndex() + "] created on or after 2.0 should NOT contain [" + IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION
|
||||
+ "] + or [" + IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE + "] in its index settings");
|
||||
}
|
||||
}
|
||||
return indexMetaData;
|
||||
}
|
||||
|
||||
/** All known byte-sized settings for an index. */
|
||||
public static final Set<String> INDEX_BYTES_SIZE_SETTINGS = unmodifiableSet(newHashSet(
|
||||
"index.merge.policy.floor_segment",
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.math.MathUtils;
|
||||
|
@ -43,6 +43,6 @@ public class MetaDataService extends AbstractComponent {
|
|||
}
|
||||
|
||||
public Semaphore indexMetaDataLock(String index) {
|
||||
return indexMdLocks[MathUtils.mod(DjbHashFunction.DJB_HASH(index), indexMdLocks.length)];
|
||||
return indexMdLocks[MathUtils.mod(Murmur3HashFunction.hash(index), indexMdLocks.length)];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.elasticsearch.cluster.routing.HashFunction;
|
||||
|
||||
/**
|
||||
* This class implements the efficient hash function
|
||||
* developed by <i>Daniel J. Bernstein</i>.
|
||||
*/
|
||||
public class DjbHashFunction implements HashFunction {
|
||||
|
||||
public static int DJB_HASH(String value) {
|
||||
long hash = 5381;
|
||||
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
hash = ((hash << 5) + hash) + value.charAt(i);
|
||||
}
|
||||
|
||||
return (int) hash;
|
||||
}
|
||||
|
||||
public static int DJB_HASH(byte[] value, int offset, int length) {
|
||||
long hash = 5381;
|
||||
|
||||
final int end = offset + length;
|
||||
for (int i = offset; i < end; i++) {
|
||||
hash = ((hash << 5) + hash) + value[i];
|
||||
}
|
||||
|
||||
return (int) hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hash(String routing) {
|
||||
return DJB_HASH(routing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hash(String type, String id) {
|
||||
long hash = 5381;
|
||||
|
||||
for (int i = 0; i < type.length(); i++) {
|
||||
hash = ((hash << 5) + hash) + type.charAt(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < id.length(); i++) {
|
||||
hash = ((hash << 5) + hash) + id.charAt(i);
|
||||
}
|
||||
|
||||
return (int) hash;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Simple hash function interface used for shard routing.
|
||||
*/
|
||||
public interface HashFunction {
|
||||
|
||||
/**
|
||||
* Calculate a hash value for routing
|
||||
* @param routing String to calculate the hash value from
|
||||
* @return hash value of the given routing string
|
||||
*/
|
||||
int hash(String routing);
|
||||
|
||||
/**
|
||||
* Calculate a hash value for routing and its type
|
||||
* @param type types name
|
||||
* @param id String to calculate the hash value from
|
||||
* @return hash value of the given type and routing string
|
||||
*/
|
||||
@Deprecated
|
||||
int hash(String type, String id);
|
||||
}
|
|
@ -20,15 +20,17 @@
|
|||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import org.apache.lucene.util.StringHelper;
|
||||
import org.elasticsearch.cluster.routing.HashFunction;
|
||||
|
||||
/**
|
||||
* Hash function based on the Murmur3 algorithm, which is the default as of Elasticsearch 2.0.
|
||||
*/
|
||||
public class Murmur3HashFunction implements HashFunction {
|
||||
public final class Murmur3HashFunction {
|
||||
|
||||
@Override
|
||||
public int hash(String routing) {
|
||||
private Murmur3HashFunction() {
|
||||
//no instance
|
||||
}
|
||||
|
||||
public static 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);
|
||||
|
@ -37,12 +39,10 @@ public class Murmur3HashFunction implements HashFunction {
|
|||
bytesToHash[i * 2] = b1;
|
||||
bytesToHash[i * 2 + 1] = b2;
|
||||
}
|
||||
return StringHelper.murmurhash3_x86_32(bytesToHash, 0, bytesToHash.length, 0);
|
||||
return hash(bytesToHash, 0, bytesToHash.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hash(String type, String id) {
|
||||
throw new UnsupportedOperationException();
|
||||
public static int hash(byte[] bytes, int offset, int length) {
|
||||
return StringHelper.murmurhash3_x86_32(bytes, offset, length, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -47,7 +46,6 @@ import java.util.Set;
|
|||
public class OperationRouting extends AbstractComponent {
|
||||
|
||||
|
||||
|
||||
private final AwarenessAllocationDecider awarenessAllocationDecider;
|
||||
|
||||
@Inject
|
||||
|
@ -196,9 +194,9 @@ public class OperationRouting extends AbstractComponent {
|
|||
// if not, then use it as the index
|
||||
String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes();
|
||||
if (awarenessAttributes.length == 0) {
|
||||
return indexShard.activeInitializingShardsIt(DjbHashFunction.DJB_HASH(preference));
|
||||
return indexShard.activeInitializingShardsIt(Murmur3HashFunction.hash(preference));
|
||||
} else {
|
||||
return indexShard.preferAttributesActiveInitializingShardsIt(awarenessAttributes, nodes, DjbHashFunction.DJB_HASH(preference));
|
||||
return indexShard.preferAttributesActiveInitializingShardsIt(awarenessAttributes, nodes, Murmur3HashFunction.hash(preference));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,37 +235,13 @@ public class OperationRouting extends AbstractComponent {
|
|||
@SuppressForbidden(reason = "Math#abs is trappy")
|
||||
private int shardId(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
|
||||
final IndexMetaData indexMetaData = indexMetaData(clusterState, index);
|
||||
final Version createdVersion = indexMetaData.getCreationVersion();
|
||||
final HashFunction hashFunction = indexMetaData.getRoutingHashFunction();
|
||||
final boolean useType = indexMetaData.getRoutingUseType();
|
||||
|
||||
final int hash;
|
||||
if (routing == null) {
|
||||
if (!useType) {
|
||||
hash = hash(hashFunction, id);
|
||||
hash = Murmur3HashFunction.hash(id);
|
||||
} else {
|
||||
hash = hash(hashFunction, type, id);
|
||||
hash = Murmur3HashFunction.hash(routing);
|
||||
}
|
||||
} else {
|
||||
hash = hash(hashFunction, routing);
|
||||
}
|
||||
if (createdVersion.onOrAfter(Version.V_2_0_0_beta1)) {
|
||||
return MathUtils.mod(hash, indexMetaData.numberOfShards());
|
||||
} else {
|
||||
return Math.abs(hash % indexMetaData.numberOfShards());
|
||||
}
|
||||
}
|
||||
|
||||
protected int hash(HashFunction hashFunction, String routing) {
|
||||
return hashFunction.hash(routing);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected int hash(HashFunction hashFunction, String type, String id) {
|
||||
if (type == null || "_all".equals(type)) {
|
||||
throw new IllegalArgumentException("Can't route an operation with no type and having type part of the routing (for backward comp)");
|
||||
}
|
||||
return hashFunction.hash(type, id);
|
||||
}
|
||||
|
||||
private void ensureNodeIdExists(DiscoveryNodes nodes, String nodeId) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* This class implements a simple hash function based on Java Build-In {@link Object#hashCode()}
|
||||
*/
|
||||
public class SimpleHashFunction implements HashFunction {
|
||||
|
||||
@Override
|
||||
public int hash(String routing) {
|
||||
return routing.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hash(String type, String id) {
|
||||
return type.hashCode() + 31 * id.hashCode();
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ import org.apache.lucene.util.IOUtils;
|
|||
import org.apache.lucene.util.InfoStream;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -856,7 +856,7 @@ public class InternalEngine extends Engine {
|
|||
}
|
||||
|
||||
private Object dirtyLock(BytesRef uid) {
|
||||
int hash = DjbHashFunction.DJB_HASH(uid.bytes, uid.offset, uid.length);
|
||||
int hash = Murmur3HashFunction.hash(uid.bytes, uid.offset, uid.length);
|
||||
return dirtyLocks[MathUtils.mod(hash, dirtyLocks.length)];
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,6 @@ import static java.util.Collections.unmodifiableSet;
|
|||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_CREATION_DATE;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_INDEX_UUID;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
|
||||
|
@ -131,8 +129,6 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
private static final Set<String> UNMODIFIABLE_SETTINGS = unmodifiableSet(newHashSet(
|
||||
SETTING_NUMBER_OF_SHARDS,
|
||||
SETTING_VERSION_CREATED,
|
||||
SETTING_LEGACY_ROUTING_HASH_FUNCTION,
|
||||
SETTING_LEGACY_ROUTING_USE_TYPE,
|
||||
SETTING_INDEX_UUID,
|
||||
SETTING_CREATION_DATE));
|
||||
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.action.admin.indices.upgrade;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.bwcompat.StaticIndexBackwardCompatibilityIT;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
public class UpgradeReallyOldIndexIT extends StaticIndexBackwardCompatibilityIT {
|
||||
|
||||
public void testUpgrade_0_90_6() throws Exception {
|
||||
String indexName = "index-0.90.6";
|
||||
|
||||
loadIndex(indexName);
|
||||
assertMinVersion(indexName, org.apache.lucene.util.Version.parse("4.5.1"));
|
||||
UpgradeIT.assertNotUpgraded(client(), indexName);
|
||||
assertTrue(UpgradeIT.hasAncientSegments(client(), indexName));
|
||||
assertNoFailures(client().admin().indices().prepareUpgrade(indexName).setUpgradeOnlyAncientSegments(true).get());
|
||||
|
||||
assertFalse(UpgradeIT.hasAncientSegments(client(), indexName));
|
||||
// This index has only ancient segments, so it should now be fully upgraded:
|
||||
UpgradeIT.assertUpgraded(client(), indexName);
|
||||
assertEquals(Version.CURRENT.luceneVersion.toString(), client().admin().indices().prepareGetSettings(indexName).get().getSetting(indexName, IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE));
|
||||
assertMinVersion(indexName, Version.CURRENT.luceneVersion);
|
||||
|
||||
assertEquals(client().admin().indices().prepareGetSettings(indexName).get().getSetting(indexName, IndexMetaData.SETTING_VERSION_UPGRADED), Integer.toString(Version.CURRENT.id));
|
||||
}
|
||||
|
||||
public void testUpgradeConflictingMapping() throws Exception {
|
||||
String indexName = "index-conflicting-mappings-1.7.0";
|
||||
logger.info("Checking static index " + indexName);
|
||||
Settings nodeSettings = prepareBackwardsDataDir(getDataPath(indexName + ".zip"));
|
||||
try {
|
||||
internalCluster().startNode(nodeSettings);
|
||||
fail("Should have failed to start the node");
|
||||
} catch (Exception ex) {
|
||||
assertThat(ex.getMessage(), containsString("conflicts with existing mapping in other types"));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertMinVersion(String index, org.apache.lucene.util.Version version) {
|
||||
for (IndicesService services : internalCluster().getInstances(IndicesService.class)) {
|
||||
IndexService indexService = services.indexService(index);
|
||||
if (indexService != null) {
|
||||
assertEquals(version, indexService.getShardOrNull(0).minimumCompatibleVersion());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,7 @@ public class RecoveryWithUnsupportedIndicesIT extends StaticIndexBackwardCompati
|
|||
internalCluster().startNode(nodeSettings);
|
||||
fail();
|
||||
} catch (Exception ex) {
|
||||
assertThat(ex.getMessage(), containsString(" was created before v0.90.0 and wasn't upgraded"));
|
||||
assertThat(ex.getMessage(), containsString(" was created before v2.0.0.beta1 and wasn't upgraded"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
|
||||
|
||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, minNumDataNodes = 0, maxNumDataNodes = 0)
|
||||
@LuceneTestCase.SuppressFileSystems("*") // extra files break the single data cluster expectation when unzipping the static index
|
||||
public class RoutingBackwardCompatibilityUponUpgradeIT extends ESIntegTestCase {
|
||||
|
||||
public void testDefaultRouting() throws Exception {
|
||||
test("default_routing_1_x", DjbHashFunction.class, false);
|
||||
}
|
||||
|
||||
public void testCustomRouting() throws Exception {
|
||||
test("custom_routing_1_x", SimpleHashFunction.class, true);
|
||||
}
|
||||
|
||||
private void test(String name, Class<? extends HashFunction> expectedHashFunction, boolean expectedUseType) throws Exception {
|
||||
Path zippedIndexDir = getDataPath("/org/elasticsearch/cluster/routing/" + name + ".zip");
|
||||
Settings baseSettings = prepareBackwardsDataDir(zippedIndexDir);
|
||||
internalCluster().startNode(Settings.builder()
|
||||
.put(baseSettings)
|
||||
.put(Node.HTTP_ENABLED, true)
|
||||
.build());
|
||||
ensureYellow("test");
|
||||
GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().get();
|
||||
assertArrayEquals(new String[] {"test"}, getIndexResponse.indices());
|
||||
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
|
||||
assertEquals(expectedHashFunction.getName(), getSettingsResponse.getSetting("test", IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION));
|
||||
assertEquals(Boolean.valueOf(expectedUseType).toString(), getSettingsResponse.getSetting("test", IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE));
|
||||
SearchResponse allDocs = client().prepareSearch("test").get();
|
||||
assertSearchResponse(allDocs);
|
||||
assertHitCount(allDocs, 4);
|
||||
// Make sure routing works
|
||||
for (SearchHit hit : allDocs.getHits().hits()) {
|
||||
GetResponse get = client().prepareGet(hit.index(), hit.type(), hit.id()).get();
|
||||
assertTrue(get.isExists());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -24,8 +24,6 @@ import org.elasticsearch.test.ESTestCase;
|
|||
|
||||
public class Murmur3HashFunctionTests extends ESTestCase {
|
||||
|
||||
private static Murmur3HashFunction HASH = new Murmur3HashFunction();
|
||||
|
||||
public void testKnownValues() {
|
||||
assertHash(0x5a0cb7c3, "hell");
|
||||
assertHash(0xd7c31989, "hello");
|
||||
|
@ -37,6 +35,6 @@ public class Murmur3HashFunctionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private static void assertHash(int expected, String stringInput) {
|
||||
assertEquals(expected, HASH.hash(stringInput));
|
||||
assertEquals(expected, Murmur3HashFunction.hash(stringInput));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Priority;
|
||||
|
@ -441,7 +441,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
|
|||
logger.info("[{}] Acquired semaphore and it has {} permits left", name, semaphore.availablePermits());
|
||||
try {
|
||||
id = Integer.toString(idGenerator.incrementAndGet());
|
||||
int shard = ((InternalTestCluster) cluster()).getInstance(DjbHashFunction.class).hash(id) % numPrimaries;
|
||||
int shard = Murmur3HashFunction.hash(id) % numPrimaries;
|
||||
logger.trace("[{}] indexing id [{}] through node [{}] targeting shard [{}]", name, id, node, shard);
|
||||
IndexResponse response = client.prepareIndex("test", "type", id).setSource("{}").setTimeout("1s").get();
|
||||
assertThat(response.getVersion(), equalTo(1l));
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.elasticsearch.bootstrap.BootstrapForTesting;
|
|||
import org.elasticsearch.cache.recycler.MockPageCacheRecycler;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.io.PathUtilsForTesting;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -549,9 +548,6 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
/** Return consistent index settings for the provided index version. */
|
||||
public static Settings.Builder settings(Version version) {
|
||||
Settings.Builder builder = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version);
|
||||
if (version.before(Version.V_2_0_0_beta1)) {
|
||||
builder.put(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION, DjbHashFunction.class);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue