optimize applyDeletes event
- reuse set - don't copy over again the shard ids immutable set
This commit is contained in:
parent
5b078ebfed
commit
09a6907cca
|
@ -192,7 +192,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableSet<Integer> shardIds() {
|
public ImmutableSet<Integer> shardIds() {
|
||||||
return ImmutableSet.copyOf(shards.keySet());
|
return shards.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.indices.cluster;
|
package org.elasticsearch.indices.cluster;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import gnu.trove.set.hash.TIntHashSet;
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||||
|
@ -65,11 +66,9 @@ import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
import static com.google.common.collect.Maps.newHashMap;
|
||||||
import static com.google.common.collect.Sets.newHashSet;
|
|
||||||
import static org.elasticsearch.ExceptionsHelper.detailedMessage;
|
import static org.elasticsearch.ExceptionsHelper.detailedMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,24 +241,26 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyDeletedShards(final ClusterChangedEvent event) {
|
private void applyDeletedShards(final ClusterChangedEvent event) {
|
||||||
RoutingNode routingNodes = event.state().readOnlyRoutingNodes().nodesToShards().get(event.state().nodes().localNodeId());
|
RoutingNode routingNode = event.state().readOnlyRoutingNodes().nodesToShards().get(event.state().nodes().localNodeId());
|
||||||
if (routingNodes == null) {
|
if (routingNode == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (final String index : indicesService.indices()) {
|
TIntHashSet newShardIds = new TIntHashSet();
|
||||||
|
for (IndexService indexService : indicesService) {
|
||||||
|
String index = indexService.index().name();
|
||||||
IndexMetaData indexMetaData = event.state().metaData().index(index);
|
IndexMetaData indexMetaData = event.state().metaData().index(index);
|
||||||
if (indexMetaData != null) {
|
if (indexMetaData == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// now, go over and delete shards that needs to get deleted
|
// now, go over and delete shards that needs to get deleted
|
||||||
Set<Integer> newShardIds = newHashSet();
|
newShardIds.clear();
|
||||||
for (final ShardRouting shardRouting : routingNodes) {
|
List<MutableShardRouting> shards = routingNode.shards();
|
||||||
|
for (int i = 0; i < shards.size(); i++) {
|
||||||
|
ShardRouting shardRouting = shards.get(i);
|
||||||
if (shardRouting.index().equals(index)) {
|
if (shardRouting.index().equals(index)) {
|
||||||
newShardIds.add(shardRouting.id());
|
newShardIds.add(shardRouting.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final IndexService indexService = indicesService.indexService(index);
|
|
||||||
if (indexService == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Integer existingShardId : indexService.shardIds()) {
|
for (Integer existingShardId : indexService.shardIds()) {
|
||||||
if (!newShardIds.contains(existingShardId)) {
|
if (!newShardIds.contains(existingShardId)) {
|
||||||
if (indexMetaData.state() == IndexMetaData.State.CLOSE) {
|
if (indexMetaData.state() == IndexMetaData.State.CLOSE) {
|
||||||
|
@ -279,7 +280,6 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void applyNewIndices(final ClusterChangedEvent event) {
|
private void applyNewIndices(final ClusterChangedEvent event) {
|
||||||
// we only create indices for shards that are allocated
|
// we only create indices for shards that are allocated
|
||||||
|
|
Loading…
Reference in New Issue