Change single operation shard hashing to only use id, and not id and type, closes #472.

This commit is contained in:
kimchy 2010-11-03 12:47:34 +02:00
parent 8d454ba293
commit 92b3ae3f73
2 changed files with 19 additions and 1 deletions

View File

@ -49,9 +49,12 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
private final HashFunction hashFunction;
private final boolean useType;
@Inject public PlainOperationRouting(Settings indexSettings, HashFunction hashFunction) {
super(indexSettings);
this.hashFunction = hashFunction;
this.useType = indexSettings.getAsBoolean("cluster.routing.operation.use_type", false);
}
@Override public ShardsIterator indexShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing) throws IndexMissingException, IndexShardMissingException {
@ -159,7 +162,11 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
private int shardId(ClusterState clusterState, String index, String type, @Nullable String id, @Nullable String routing) {
if (routing == null) {
return Math.abs(hash(type, id)) % indexMetaData(clusterState, index).numberOfShards();
if (!useType) {
return Math.abs(hash(id)) % indexMetaData(clusterState, index).numberOfShards();
} else {
return Math.abs(hash(type, id)) % indexMetaData(clusterState, index).numberOfShards();
}
}
return Math.abs(hash(routing)) % indexMetaData(clusterState, index).numberOfShards();
}

View File

@ -394,6 +394,17 @@ public class TwoInstanceUnbalancedShardsEmbeddedSearchTests extends AbstractNode
super(settings, null);
}
@Override protected int hash(String routing) {
long lId = Long.parseLong(routing);
if (lId < 60) {
return 0;
}
if (lId >= 60 && lId < 90) {
return 1;
}
return 2;
}
@Override protected int hash(String type, String id) {
long lId = Long.parseLong(id);
if (lId < 60) {