mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
Change single operation shard hashing to only use id, and not id and type, closes #472.
This commit is contained in:
parent
8d454ba293
commit
92b3ae3f73
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user