Skip to content
Merged
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
6 changes: 6 additions & 0 deletions docs/changelog/124107.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 124107
summary: Avoid hoarding cluster state references during rollover
area: Indices APIs
type: bug
issues:
- 123893
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.elasticsearch.cluster.service.MasterServiceTaskQueue;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -189,7 +188,7 @@ record LazyRolloverExecutor(
@Override
public ClusterState execute(BatchExecutionContext<LazyRolloverTask> batchExecutionContext) {
final var listener = new AllocationActionMultiListener<RolloverResponse>(threadPool.getThreadContext());
final var results = new ArrayList<MetadataRolloverService.RolloverResult>(batchExecutionContext.taskContexts().size());
final var results = new ArrayList<String>(batchExecutionContext.taskContexts().size());
var state = batchExecutionContext.initialState();
Map<ProjectId, Map<RolloverRequest, List<TaskContext<LazyRolloverTask>>>> groupedRequests = new HashMap<>();
for (final var taskContext : batchExecutionContext.taskContexts()) {
Expand All @@ -214,14 +213,7 @@ public ClusterState execute(BatchExecutionContext<LazyRolloverTask> batchExecuti

if (state != batchExecutionContext.initialState()) {
var reason = new StringBuilder();
Strings.collectionToDelimitedStringWithLimit(
(Iterable<String>) () -> Iterators.map(results.iterator(), t -> t.sourceIndexName() + "->" + t.rolloverIndexName()),
",",
"lazy bulk rollover [",
"]",
1024,
reason
);
Strings.collectionToDelimitedStringWithLimit(results, ",", "lazy bulk rollover [", "]", 1024, reason);
try (var ignored = batchExecutionContext.dropHeadersContext()) {
state = allocationService.reroute(state, reason.toString(), listener.reroute());
}
Expand All @@ -234,7 +226,7 @@ public ClusterState execute(BatchExecutionContext<LazyRolloverTask> batchExecuti
public ClusterState executeTask(
ProjectState currentState,
RolloverRequest rolloverRequest,
List<MetadataRolloverService.RolloverResult> results,
ArrayList<String> results,
List<TaskContext<LazyRolloverTask>> rolloverTaskContexts,
AllocationActionMultiListener<RolloverResponse> allocationActionMultiListener
) throws Exception {
Expand Down Expand Up @@ -271,7 +263,7 @@ public ClusterState executeTask(
null,
isFailureStoreRollover
);
results.add(rolloverResult);
results.add(rolloverResult.sourceIndexName() + "->" + rolloverResult.rolloverIndexName());
logger.trace("lazy rollover result [{}]", rolloverResult);

final var rolloverIndexName = rolloverResult.rolloverIndexName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.elasticsearch.cluster.service.MasterServiceTaskQueue;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.core.Nullable;
Expand Down Expand Up @@ -494,7 +493,7 @@ record RolloverExecutor(
@Override
public ClusterState execute(BatchExecutionContext<RolloverTask> batchExecutionContext) {
final var listener = new AllocationActionMultiListener<RolloverResponse>(threadPool.getThreadContext());
final var results = new ArrayList<MetadataRolloverService.RolloverResult>(batchExecutionContext.taskContexts().size());
final var results = new ArrayList<String>(batchExecutionContext.taskContexts().size());
var state = batchExecutionContext.initialState();
for (final var taskContext : batchExecutionContext.taskContexts()) {
try (var ignored = taskContext.captureResponseHeaders()) {
Expand All @@ -506,14 +505,7 @@ public ClusterState execute(BatchExecutionContext<RolloverTask> batchExecutionCo

if (state != batchExecutionContext.initialState()) {
var reason = new StringBuilder();
Strings.collectionToDelimitedStringWithLimit(
(Iterable<String>) () -> Iterators.map(results.iterator(), t -> t.sourceIndexName() + "->" + t.rolloverIndexName()),
",",
"bulk rollover [",
"]",
1024,
reason
);
Strings.collectionToDelimitedStringWithLimit(results, ",", "bulk rollover [", "]", 1024, reason);
try (var ignored = batchExecutionContext.dropHeadersContext()) {
state = allocationService.reroute(state, reason.toString(), listener.reroute());
}
Expand All @@ -525,7 +517,7 @@ public ClusterState execute(BatchExecutionContext<RolloverTask> batchExecutionCo

public ClusterState executeTask(
ClusterState currentState,
List<MetadataRolloverService.RolloverResult> results,
ArrayList<String> results,
TaskContext<RolloverTask> rolloverTaskContext,
AllocationActionMultiListener<RolloverResponse> allocationActionMultiListener
) throws Exception {
Expand Down Expand Up @@ -596,7 +588,7 @@ public ClusterState executeTask(
rolloverTask.autoShardingResult(),
targetFailureStore
);
results.add(rolloverResult);
results.add(rolloverResult.sourceIndexName() + "->" + rolloverResult.rolloverIndexName());
logger.trace("rollover result [{}]", rolloverResult);

final var rolloverIndexName = rolloverResult.rolloverIndexName();
Expand Down