|
@@ -36,6 +36,7 @@ import org.elasticsearch.cluster.ClusterStateAckListener;
|
|
|
import org.elasticsearch.cluster.ClusterStateTaskConfig;
|
|
|
import org.elasticsearch.cluster.ClusterStateTaskExecutor;
|
|
|
import org.elasticsearch.cluster.ClusterStateTaskListener;
|
|
|
+import org.elasticsearch.cluster.SimpleBatchedExecutor;
|
|
|
import org.elasticsearch.cluster.block.ClusterBlock;
|
|
|
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|
|
import org.elasticsearch.cluster.block.ClusterBlocks;
|
|
@@ -169,42 +170,37 @@ public class MetadataIndexStateService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- private class AddBlocksToCloseExecutor implements ClusterStateTaskExecutor<AddBlocksToCloseTask> {
|
|
|
+ private class AddBlocksToCloseExecutor extends SimpleBatchedExecutor<AddBlocksToCloseTask, Map<Index, ClusterBlock>> {
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(BatchExecutionContext<AddBlocksToCloseTask> batchExecutionContext) throws Exception {
|
|
|
- ClusterState state = batchExecutionContext.initialState();
|
|
|
- for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
- final var task = taskContext.getTask();
|
|
|
- try {
|
|
|
- final Map<Index, ClusterBlock> blockedIndices = new HashMap<>(task.request.indices().length);
|
|
|
- state = addIndexClosedBlocks(task.request.indices(), blockedIndices, state);
|
|
|
- taskContext.success(() -> {
|
|
|
- if (blockedIndices.isEmpty()) {
|
|
|
- task.listener().onResponse(CloseIndexResponse.EMPTY);
|
|
|
- } else {
|
|
|
- threadPool.executor(ThreadPool.Names.MANAGEMENT)
|
|
|
- .execute(
|
|
|
- new WaitForClosedBlocksApplied(
|
|
|
- blockedIndices,
|
|
|
- task.request,
|
|
|
- task.listener().delegateFailure((delegate2, verifyResults) -> {
|
|
|
- clusterService.submitStateUpdateTask(
|
|
|
- "close-indices",
|
|
|
- new CloseIndicesTask(task.request, blockedIndices, verifyResults, delegate2),
|
|
|
- ClusterStateTaskConfig.build(Priority.URGENT),
|
|
|
- closesExecutor
|
|
|
- );
|
|
|
- })
|
|
|
- )
|
|
|
+ public Tuple<ClusterState, Map<Index, ClusterBlock>> executeTask(AddBlocksToCloseTask task, ClusterState clusterState)
|
|
|
+ throws Exception {
|
|
|
+ final Map<Index, ClusterBlock> blockedIndices = new HashMap<>(task.request.indices().length);
|
|
|
+ var updatedClusterState = addIndexClosedBlocks(task.request.indices(), blockedIndices, clusterState);
|
|
|
+ return Tuple.tuple(updatedClusterState, blockedIndices);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void taskSucceeded(AddBlocksToCloseTask task, Map<Index, ClusterBlock> blockedIndices) {
|
|
|
+ if (blockedIndices.isEmpty()) {
|
|
|
+ task.listener().onResponse(CloseIndexResponse.EMPTY);
|
|
|
+ } else {
|
|
|
+ threadPool.executor(ThreadPool.Names.MANAGEMENT)
|
|
|
+ .execute(
|
|
|
+ new WaitForClosedBlocksApplied(
|
|
|
+ blockedIndices,
|
|
|
+ task.request,
|
|
|
+ task.listener().delegateFailure((delegate2, verifyResults) -> {
|
|
|
+ clusterService.submitStateUpdateTask(
|
|
|
+ "close-indices",
|
|
|
+ new CloseIndicesTask(task.request, blockedIndices, verifyResults, delegate2),
|
|
|
+ ClusterStateTaskConfig.build(Priority.URGENT),
|
|
|
+ closesExecutor
|
|
|
);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- taskContext.onFailure(e);
|
|
|
- }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
- return state;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -477,53 +473,38 @@ public class MetadataIndexStateService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- private class AddBlocksExecutor implements ClusterStateTaskExecutor<AddBlocksTask> {
|
|
|
+ private class AddBlocksExecutor extends SimpleBatchedExecutor<AddBlocksTask, Map<Index, ClusterBlock>> {
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(BatchExecutionContext<AddBlocksTask> batchExecutionContext) throws Exception {
|
|
|
- ClusterState state = batchExecutionContext.initialState();
|
|
|
+ public Tuple<ClusterState, Map<Index, ClusterBlock>> executeTask(AddBlocksTask task, ClusterState clusterState) {
|
|
|
+ return addIndexBlock(task.request.indices(), clusterState, task.request.getBlock());
|
|
|
+ }
|
|
|
|
|
|
- for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
- try {
|
|
|
- final var task = taskContext.getTask();
|
|
|
- final Tuple<ClusterState, Map<Index, ClusterBlock>> blockResult = addIndexBlock(
|
|
|
- task.request.indices(),
|
|
|
- state,
|
|
|
- task.request.getBlock()
|
|
|
- );
|
|
|
- state = blockResult.v1();
|
|
|
- final Map<Index, ClusterBlock> blockedIndices = blockResult.v2();
|
|
|
- taskContext.success(() -> {
|
|
|
- if (blockedIndices.isEmpty()) {
|
|
|
- task.listener().onResponse(AddIndexBlockResponse.EMPTY);
|
|
|
- } else {
|
|
|
- threadPool.executor(ThreadPool.Names.MANAGEMENT)
|
|
|
- .execute(
|
|
|
- new WaitForBlocksApplied(
|
|
|
- blockedIndices,
|
|
|
- task.request,
|
|
|
- task.listener().delegateFailure((delegate2, verifyResults) -> {
|
|
|
- clusterService.submitStateUpdateTask(
|
|
|
- "finalize-index-block-["
|
|
|
- + task.request.getBlock().name
|
|
|
- + "]-["
|
|
|
- + blockedIndices.keySet().stream().map(Index::getName).collect(Collectors.joining(", "))
|
|
|
- + "]",
|
|
|
- new FinalizeBlocksTask(task.request, blockedIndices, verifyResults, delegate2),
|
|
|
- ClusterStateTaskConfig.build(Priority.URGENT),
|
|
|
- finalizeBlocksExecutor
|
|
|
- );
|
|
|
- })
|
|
|
- )
|
|
|
+ @Override
|
|
|
+ public void taskSucceeded(AddBlocksTask task, Map<Index, ClusterBlock> blockedIndices) {
|
|
|
+ if (blockedIndices.isEmpty()) {
|
|
|
+ task.listener().onResponse(AddIndexBlockResponse.EMPTY);
|
|
|
+ } else {
|
|
|
+ threadPool.executor(ThreadPool.Names.MANAGEMENT)
|
|
|
+ .execute(
|
|
|
+ new WaitForBlocksApplied(
|
|
|
+ blockedIndices,
|
|
|
+ task.request,
|
|
|
+ task.listener().delegateFailure((delegate2, verifyResults) -> {
|
|
|
+ clusterService.submitStateUpdateTask(
|
|
|
+ "finalize-index-block-["
|
|
|
+ + task.request.getBlock().name
|
|
|
+ + "]-["
|
|
|
+ + blockedIndices.keySet().stream().map(Index::getName).collect(Collectors.joining(", "))
|
|
|
+ + "]",
|
|
|
+ new FinalizeBlocksTask(task.request, blockedIndices, verifyResults, delegate2),
|
|
|
+ ClusterStateTaskConfig.build(Priority.URGENT),
|
|
|
+ finalizeBlocksExecutor
|
|
|
);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- taskContext.onFailure(e);
|
|
|
- }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
- return state;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -537,35 +518,24 @@ public class MetadataIndexStateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static class FinalizeBlocksExecutor implements ClusterStateTaskExecutor<FinalizeBlocksTask> {
|
|
|
+ private static class FinalizeBlocksExecutor extends SimpleBatchedExecutor<FinalizeBlocksTask, List<AddBlockResult>> {
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(BatchExecutionContext<FinalizeBlocksTask> batchExecutionContext) throws Exception {
|
|
|
- ClusterState state = batchExecutionContext.initialState();
|
|
|
-
|
|
|
- for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
- try {
|
|
|
- final var task = taskContext.getTask();
|
|
|
- final Tuple<ClusterState, List<AddBlockResult>> finalizeResult = finalizeBlock(
|
|
|
- state,
|
|
|
- task.blockedIndices,
|
|
|
- task.verifyResults,
|
|
|
- task.request.getBlock()
|
|
|
- );
|
|
|
- state = finalizeResult.v1();
|
|
|
- final List<AddBlockResult> indices = finalizeResult.v2();
|
|
|
- assert indices.size() == task.verifyResults.size();
|
|
|
-
|
|
|
- taskContext.success(() -> {
|
|
|
- final boolean acknowledged = indices.stream().noneMatch(AddBlockResult::hasFailures);
|
|
|
- task.listener().onResponse(new AddIndexBlockResponse(acknowledged, acknowledged, indices));
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- taskContext.onFailure(e);
|
|
|
- }
|
|
|
- }
|
|
|
+ public Tuple<ClusterState, List<AddBlockResult>> executeTask(FinalizeBlocksTask task, ClusterState clusterState) throws Exception {
|
|
|
+ final Tuple<ClusterState, List<AddBlockResult>> finalizeResult = finalizeBlock(
|
|
|
+ clusterState,
|
|
|
+ task.blockedIndices,
|
|
|
+ task.verifyResults,
|
|
|
+ task.request.getBlock()
|
|
|
+ );
|
|
|
+ assert finalizeResult.v2().size() == task.verifyResults.size();
|
|
|
+ return finalizeResult;
|
|
|
+ }
|
|
|
|
|
|
- return state;
|
|
|
+ @Override
|
|
|
+ public void taskSucceeded(FinalizeBlocksTask task, List<AddBlockResult> indices) {
|
|
|
+ final boolean acknowledged = indices.stream().noneMatch(AddBlockResult::hasFailures);
|
|
|
+ task.listener().onResponse(new AddIndexBlockResponse(acknowledged, acknowledged, indices));
|
|
|
}
|
|
|
}
|
|
|
|