Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.search;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FilterDirectory;

/**
* Temporary stub for index shard prewarming capabilities that is a no-op in the default build but can be extende
* by classes implementing the interface
*/
public interface OnlinePrewarmingService {
void prewarm();

static OnlinePrewarmingService unwrapDirectory(final Directory directory) {
Directory dir = directory;
while (dir != null) {
if (dir instanceof OnlinePrewarmingService searchDirectory) {
return searchDirectory;
} else if (dir instanceof FilterDirectory) {
dir = ((FilterDirectory) dir).getDelegate();
} else {
dir = null;
}
}
return () -> {
// no-Op by default
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ public void executeQueryPhase(ShardSearchRequest request, CancellableTask task,
assert request.canReturnNullResponseIfMatchNoDocs() == false || request.numberOfShards() > 1
: "empty responses require more than one shard";
final IndexShard shard = getShard(request);
// TODO this call probably needs to be somewhere else where we want to fork the online prewarming of shards
OnlinePrewarmingService.unwrapDirectory(shard.store().directory()).prewarm();
rewriteAndFetchShardRequest(
shard,
request,
Expand Down