Skip to content

Commit

Permalink
Change single operation shard hashing to only use id, and not id and …
Browse files Browse the repository at this point in the history
…type, closes elastic#472.
  • Loading branch information
kimchy committed Nov 3, 2010
1 parent 8d454ba commit 92b3ae3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -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 {
Expand Down Expand Up @@ -159,7 +162,11 @@ protected IndexShardRoutingTable shards(ClusterState clusterState, String index,

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();
}
Expand Down
Expand Up @@ -394,6 +394,17 @@ public static class UnevenOperationRoutingStrategy extends PlainOperationRouting
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) {
Expand Down

0 comments on commit 92b3ae3

Please sign in to comment.