-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added soft limit to open scroll contexts #25244 #36009
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ | |
import java.util.Optional; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
@@ -145,6 +146,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv | |
public static final Setting<Boolean> DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS = | ||
Setting.boolSetting("search.default_allow_partial_results", true, Property.Dynamic, Property.NodeScope); | ||
|
||
public static final Setting<Integer> MAX_OPEN_SCROLL_CONTEXT = | ||
Setting.intSetting("search.max_open_scroll_context", 150, 0, Property.NodeScope); | ||
|
||
|
||
private final ThreadPool threadPool; | ||
|
||
|
@@ -182,6 +186,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv | |
|
||
private final MultiBucketConsumerService multiBucketConsumerService; | ||
|
||
private final AtomicInteger openScrollContexts = new AtomicInteger(); | ||
|
||
public SearchService(ClusterService clusterService, IndicesService indicesService, | ||
ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase, | ||
ResponseCollectorService responseCollectorService) { | ||
|
@@ -592,11 +598,19 @@ private SearchContext findContext(long id, TransportRequest request) throws Sear | |
} | ||
|
||
final SearchContext createAndPutContext(ShardSearchRequest request) throws IOException { | ||
if (request.scroll() != null && openScrollContexts.get() >= MAX_OPEN_SCROLL_CONTEXT.get(clusterService.getSettings())) { | ||
throw new ElasticsearchException( | ||
"Trying to create too many scroll contexts. Must be less than or equal to: [" + | ||
MAX_OPEN_SCROLL_CONTEXT.get(clusterService.getSettings()) + "]. " + "This limit can be set by changing the [" | ||
+ MAX_OPEN_SCROLL_CONTEXT.getKey() + "] setting."); | ||
} | ||
|
||
SearchContext context = createContext(request); | ||
boolean success = false; | ||
try { | ||
putContext(context); | ||
if (request.scroll() != null) { | ||
openScrollContexts.incrementAndGet(); | ||
context.indexShard().getSearchOperationListener().onNewScrollContext(context); | ||
} | ||
context.indexShard().getSearchOperationListener().onNewContext(context); | ||
|
@@ -696,6 +710,7 @@ public boolean freeContext(long id) { | |
assert context.refCount() > 0 : " refCount must be > 0: " + context.refCount(); | ||
context.indexShard().getSearchOperationListener().onFreeContext(context); | ||
if (context.scrollContext() != null) { | ||
openScrollContexts.decrementAndGet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also check the scroll contexts in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry my bad, it does call |
||
context.indexShard().getSearchOperationListener().onFreeScrollContext(context); | ||
} | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting should be dynamic, you should extract the value in the SearchService ctr and register an update consumer. DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS is a good example of how to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be dynamic now. Please review the changes.