Skip to content

Commit ba047e4

Browse files
Avoid walking the complete list of search contexts on shard creation
This I found in the many-shards benchmark during some manual testing. Creating indices slows down measurably when there's concurrent searches going on. Interestingly enough, the bulk of the cost is coming from this hook. This makes sense to some extend because the map can quickly grow to a massive size as it scales as O(shards_searched_on_average * concurrent_searches) and a CHM generally is anything but cheap to iterate over.
1 parent dbac70e commit ba047e4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.action.support.TransportActions;
3030
import org.elasticsearch.cluster.ProjectState;
3131
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression;
32+
import org.elasticsearch.cluster.routing.RecoverySource;
3233
import org.elasticsearch.cluster.routing.ShardRouting;
3334
import org.elasticsearch.cluster.service.ClusterService;
3435
import org.elasticsearch.common.CheckedSupplier;
@@ -488,7 +489,7 @@ public void beforeIndexShardCreated(ShardRouting routing, Settings indexSettings
488489
// to stop searches to restore full availability as fast as possible. A known scenario here is that we lost connection to master
489490
// or master(s) were restarted.
490491
assert routing.initializing();
491-
if (routing.isRelocationTarget() == false) {
492+
if (routing.isRelocationTarget() == false && routing.recoverySource() != RecoverySource.EmptyStoreRecoverySource.INSTANCE) {
492493
freeAllContextsForShard(routing.shardId());
493494
}
494495
}

0 commit comments

Comments
 (0)