Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -614,6 +614,7 @@ public void apply(Settings value, Settings current, Settings previous) {
DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING,
IndicesClusterStateService.SHARD_LOCK_RETRY_INTERVAL_SETTING,
IndicesClusterStateService.SHARD_LOCK_RETRY_TIMEOUT_SETTING,
IndicesClusterStateService.CONCURRENT_SHARD_CLOSE_LIMIT,
IngestSettings.GROK_WATCHDOG_INTERVAL,
IngestSettings.GROK_WATCHDOG_MAX_EXECUTION_TIME,
TDigestExecutionHint.SETTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
Setting.Property.NodeScope
);

public static final Setting<Integer> CONCURRENT_SHARD_CLOSE_LIMIT = Setting.intSetting(
"indices.store.max_concurrent_closing_shards",
settings -> Integer.toString(Math.min(10, EsExecutors.NODE_PROCESSORS_SETTING.get(settings).roundUp())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the default max was

final var maxThreads = Math.max(EsExecutors.NODE_PROCESSORS_SETTING.get(settings).roundUp(), 10);

Note Math.max instead of Math.min. Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was a (my) mistake to use max here in the first place. I noticed the issue when I saw a small (IO-bound) node struggling to close lots of shards at once.

1,
Integer.MAX_VALUE,
Setting.Property.NodeScope
);

final AllocatedIndices<? extends Shard, ? extends AllocatedIndex<? extends Shard>> indicesService;
private final ClusterService clusterService;
private final ThreadPool threadPool;
Expand Down Expand Up @@ -1347,7 +1355,7 @@ enum IndexRemovalReason {
}
}

private static class ShardCloseExecutor implements Executor {
static class ShardCloseExecutor implements Executor {

private final ThrottledTaskRunner throttledTaskRunner;

Expand All @@ -1360,8 +1368,11 @@ private static class ShardCloseExecutor implements Executor {
// can't close the old ones down fast enough. Maybe we could block or throttle new shards starting while old shards are still
// shutting down, given that starting new shards is already async. Since this seems unlikely in practice, we opt for the simple
// approach here.
final var maxThreads = Math.max(EsExecutors.NODE_PROCESSORS_SETTING.get(settings).roundUp(), 10);
throttledTaskRunner = new ThrottledTaskRunner(IndicesClusterStateService.class.getCanonicalName(), maxThreads, delegate);
throttledTaskRunner = new ThrottledTaskRunner(
IndicesClusterStateService.class.getCanonicalName(),
CONCURRENT_SHARD_CLOSE_LIMIT.get(settings),
delegate
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.indices.cluster;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.test.ESTestCase;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class ShardCloseExecutorTests extends ESTestCase {

public void testThrottling() {
final var defaultProcessors = EsExecutors.NODE_PROCESSORS_SETTING.get(Settings.EMPTY).roundUp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the expectations around the value of defaultProcessors for tests? You have if-statements later, and I'm wondering what runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the number of CPUs of the machine on which the tests are running, so can be more or less than 10. And it's not permitted to increase node.processors to greater than the default, which is why we have to skip some tests on low-CPU machiens.

ensureThrottling(Math.min(10, defaultProcessors), Settings.EMPTY);

if (10 < defaultProcessors) {
ensureThrottling(
10,
Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), between(10, defaultProcessors - 1)).build()
);
}

if (1 < defaultProcessors) {
final var fewProcessors = between(1, Math.min(10, defaultProcessors - 1));
ensureThrottling(fewProcessors, Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), fewProcessors).build());
}

final var override = between(1, defaultProcessors * 2);
ensureThrottling(
override,
Settings.builder().put(IndicesClusterStateService.CONCURRENT_SHARD_CLOSE_LIMIT.getKey(), override).build()
);
}

private static void ensureThrottling(int expectedLimit, Settings settings) {
final var tasksToRun = new ArrayList<Runnable>(expectedLimit + 1);
final var executor = new IndicesClusterStateService.ShardCloseExecutor(settings, tasksToRun::add);
final var runCount = new AtomicInteger();

for (int i = 0; i < expectedLimit + 1; i++) {
executor.execute(runCount::incrementAndGet);
}

assertEquals(expectedLimit, tasksToRun.size()); // didn't enqueue the final task yet

for (int i = 0; i < tasksToRun.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to understand this method. Is there any way you could refactor or document it to make it easier to understand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments in d1fd519, does that help?

assertEquals(i, runCount.get());
tasksToRun.get(i).run();
assertEquals(i + 1, runCount.get());
assertEquals(expectedLimit + 1, tasksToRun.size());
}
}
}