Skip to content

Commit

Permalink
Store: Only send shard exists requests if shards exist locally on dis…
Browse files Browse the repository at this point in the history
…k and are not allocated on that node according to the cluster state.

Closes #6870
  • Loading branch information
martijnvg committed Jul 16, 2014
1 parent 35037e3 commit f1c2cdb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/org/elasticsearch/indices/store/IndicesStore.java
Expand Up @@ -48,7 +48,9 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand Down Expand Up @@ -156,8 +158,19 @@ public void clusterChanged(ClusterChangedEvent event) {
if (shardCanBeDeleted(event.state(), indexShardRoutingTable)) {
ShardId shardId = indexShardRoutingTable.shardId();
IndexService indexService = indicesService.indexService(shardId.getIndex());
if (indexService == null || !indexService.hasShard(shardId.getId())) {
deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable);
if (indexService == null) {
if (nodeEnv.hasNodeFile()) {
File[] shardLocations = nodeEnv.shardLocations(shardId);
if (FileSystemUtils.exists(shardLocations)) {
deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable);
}
}
} else {
if (!indexService.hasShard(shardId.id())) {
if (indexService.store().canDeleteUnallocated(shardId)) {
deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable);
}
}
}
}
}
Expand Down Expand Up @@ -231,7 +244,7 @@ private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTa

ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state, requests.size());
for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
transportService.submitRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
}
}

Expand Down

0 comments on commit f1c2cdb

Please sign in to comment.