diff options
Diffstat (limited to 'core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 4bf196d07d..6d81556eb2 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.util.iterable.Iterables; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardNotFoundException; @@ -88,6 +89,10 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi return indicesRouting.get(index); } + public IndexRoutingTable index(Index index) { + return indicesRouting.get(index.getName()); + } + public ImmutableOpenMap<String, IndexRoutingTable> indicesRouting() { return indicesRouting; } @@ -109,7 +114,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi } IndexShardRoutingTable shard = indexRouting.shard(shardId); if (shard == null) { - throw new ShardNotFoundException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(indexRouting.getIndex(), shardId)); } return shard; } @@ -121,7 +126,15 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi * @throws ShardNotFoundException if provided shard id is unknown */ public IndexShardRoutingTable shardRoutingTable(ShardId shardId) { - return shardRoutingTable(shardId.getIndex(), shardId.getId()); + IndexRoutingTable indexRouting = index(shardId.getIndexName()); + if (indexRouting == null || indexRouting.getIndex().equals(shardId.getIndex()) == false) { + throw new IndexNotFoundException(shardId.getIndex()); + } + IndexShardRoutingTable shard = indexRouting.shard(shardId.id()); + if (shard == null) { + throw new ShardNotFoundException(shardId); + } + return shard; } public RoutingTable validateRaiseException(MetaData metaData) throws RoutingValidationException { @@ -386,7 +399,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi public Builder(RoutingTable routingTable) { version = routingTable.version; for (IndexRoutingTable indexRoutingTable : routingTable) { - indicesRouting.put(indexRoutingTable.index(), indexRoutingTable); + indicesRouting.put(indexRoutingTable.getIndex().getName(), indexRoutingTable); } } @@ -401,14 +414,14 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi if (shardRoutingEntry.initializing() && shardRoutingEntry.relocatingNodeId() != null) continue; - String index = shardRoutingEntry.index(); - IndexRoutingTable.Builder indexBuilder = indexRoutingTableBuilders.get(index); + Index index = shardRoutingEntry.index(); + IndexRoutingTable.Builder indexBuilder = indexRoutingTableBuilders.get(index.getName()); if (indexBuilder == null) { indexBuilder = new IndexRoutingTable.Builder(index); - indexRoutingTableBuilders.put(index, indexBuilder); + indexRoutingTableBuilders.put(index.getName(), indexBuilder); } - IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index()).shard(shardRoutingEntry.id()); + IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index().getName()).shard(shardRoutingEntry.id()); indexBuilder.addShard(refData, shardRoutingEntry); } } @@ -416,13 +429,13 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi Iterable<ShardRouting> shardRoutingEntries = Iterables.concat(routingNodes.unassigned(), routingNodes.unassigned().ignored()); for (ShardRouting shardRoutingEntry : shardRoutingEntries) { - String index = shardRoutingEntry.index(); - IndexRoutingTable.Builder indexBuilder = indexRoutingTableBuilders.get(index); + Index index = shardRoutingEntry.index(); + IndexRoutingTable.Builder indexBuilder = indexRoutingTableBuilders.get(index.getName()); if (indexBuilder == null) { indexBuilder = new IndexRoutingTable.Builder(index); - indexRoutingTableBuilders.put(index, indexBuilder); + indexRoutingTableBuilders.put(index.getName(), indexBuilder); } - IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index()).shard(shardRoutingEntry.id()); + IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index().getName()).shard(shardRoutingEntry.id()); indexBuilder.addShard(refData, shardRoutingEntry); } @@ -446,7 +459,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi continue; } int currentNumberOfReplicas = indexRoutingTable.shards().get(0).size() - 1; // remove the required primary - IndexRoutingTable.Builder builder = new IndexRoutingTable.Builder(index); + IndexRoutingTable.Builder builder = new IndexRoutingTable.Builder(indexRoutingTable.getIndex()); // re-add all the shards for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { builder.addIndexShard(indexShardRoutingTable); @@ -526,7 +539,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi throw new IllegalStateException("once build is called the builder cannot be reused"); } indexRoutingTable.validate(); - indicesRouting.put(indexRoutingTable.index(), indexRoutingTable); + indicesRouting.put(indexRoutingTable.getIndex().getName(), indexRoutingTable); return this; } @@ -567,7 +580,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<Routi } // normalize the versions right before we build it... for (ObjectCursor<IndexRoutingTable> indexRoutingTable : indicesRouting.values()) { - indicesRouting.put(indexRoutingTable.value.index(), indexRoutingTable.value.normalizeVersions()); + indicesRouting.put(indexRoutingTable.value.getIndex().getName(), indexRoutingTable.value.normalizeVersions()); } RoutingTable table = new RoutingTable(version, indicesRouting.build()); indicesRouting = null; |