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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ protected void masterOperation(

@Override
protected ClusterBlockException checkBlock(CreateDataStreamAction.Request request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ static ClusterState removeDataStream(

@Override
protected ClusterBlockException checkBlock(DeleteDataStreamAction.Request request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ protected void localClusterStateOperation(

@Override
protected ClusterBlockException checkBlock(GetDataStreamLifecycleAction.Request request, ProjectState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
return state.blocks().globalBlockedException(state.projectId(), ClusterBlockLevel.METADATA_READ);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.injection.guice.Inject;
Expand All @@ -28,13 +29,15 @@
public class TransportDeleteStoredScriptAction extends AcknowledgedTransportMasterNodeAction<DeleteStoredScriptRequest> {

public static final ActionType<AcknowledgedResponse> TYPE = new ActionType<>("cluster:admin/script/delete");
private final ProjectResolver projectResolver;

@Inject
public TransportDeleteStoredScriptAction(
TransportService transportService,
ClusterService clusterService,
ThreadPool threadPool,
ActionFilters actionFilters
ActionFilters actionFilters,
ProjectResolver projectResolver
) {
super(
TYPE.name(),
Expand All @@ -45,6 +48,7 @@ public TransportDeleteStoredScriptAction(
DeleteStoredScriptRequest::new,
EsExecutors.DIRECT_EXECUTOR_SERVICE
);
this.projectResolver = projectResolver;
}

@Override
Expand All @@ -59,7 +63,7 @@ protected void masterOperation(

@Override
protected ClusterBlockException checkBlock(DeleteStoredScriptRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected ShardsIterator shards(ClusterState clusterState, ForceMergeRequest req

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, ForceMergeRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ protected void doExecute(Task task, AddIndexBlockRequest request, ActionListener

@Override
protected ClusterBlockException checkBlock(AddIndexBlockRequest request, ClusterState state) {
final ProjectMetadata projectMetadata = projectResolver.getProjectMetadata(state);
if (request.getBlock().getBlock().levels().contains(ClusterBlockLevel.METADATA_WRITE)
&& state.blocks().global(ClusterBlockLevel.METADATA_WRITE).isEmpty()) {
&& state.blocks().global(projectMetadata.id(), ClusterBlockLevel.METADATA_WRITE).isEmpty()) {
return null;
}
final ProjectMetadata projectMetadata = projectResolver.getProjectMetadata(state);
return state.blocks()
.indicesBlockedException(
projectMetadata.id(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public TransportUpdateSettingsAction(
@Override
protected ClusterBlockException checkBlock(UpdateSettingsRequest request, ClusterState state) {
// allow for dedicated changes to the metadata blocks, so we don't block those to allow to "re-enable" it
ClusterBlockException globalBlock = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
ClusterBlockException globalBlock = state.blocks()
.globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
if (globalBlock != null) {
return globalBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public TransportDeleteComponentTemplateAction(

@Override
protected ClusterBlockException checkBlock(Request request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public TransportDeleteComposableIndexTemplateAction(

@Override
protected ClusterBlockException checkBlock(Request request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public TransportDeleteIndexTemplateAction(

@Override
protected ClusterBlockException checkBlock(DeleteIndexTemplateRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public TransportGetComponentTemplateAction(
projectResolver
);
clusterSettings = clusterService.getClusterSettings();

transportService.registerRequestHandler(
actionName,
executor,
Expand All @@ -74,7 +73,7 @@ public TransportGetComponentTemplateAction(

@Override
protected ClusterBlockException checkBlock(GetComponentTemplateAction.Request request, ProjectState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
return state.blocks().globalBlockedException(state.projectId(), ClusterBlockLevel.METADATA_READ);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public TransportGetComposableIndexTemplateAction(

@Override
protected ClusterBlockException checkBlock(GetComposableIndexTemplateAction.Request request, ProjectState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
return state.blocks().globalBlockedException(state.projectId(), ClusterBlockLevel.METADATA_READ);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected List<ShardIterator> shards(ClusterState clusterState, ValidateQueryReq

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, ValidateQueryRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.READ);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.READ);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ private void maybeMarkFailureStoreForRollover(DataStream dataStream) {
* @return {@code true} if the cluster is currently blocked at all, {@code false} if the cluster has no blocks.
*/
private boolean handleBlockExceptions(ClusterState state, Runnable retryOperation, Consumer<Exception> onClusterBlocked) {
ClusterBlockException blockException = state.blocks().globalBlockedException(ClusterBlockLevel.WRITE);
ClusterBlockException blockException = state.blocks()
.globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.WRITE);
if (blockException != null) {
if (blockException.retryable()) {
logger.trace("cluster is blocked, scheduling a retry", blockException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private void ensureClusterStateThenForkAndExecute(
ActionListener<BulkResponse> releasingListener
) {
final ClusterState initialState = clusterService.state();
final ClusterBlockException blockException = initialState.blocks().globalBlockedException(ClusterBlockLevel.WRITE);
ProjectId projectId = projectResolver.getProjectId();
final ClusterBlockException blockException = initialState.blocks().globalBlockedException(projectId, ClusterBlockLevel.WRITE);
if (blockException != null) {
if (false == blockException.retryable()) {
releasingListener.onFailure(blockException);
Expand Down Expand Up @@ -171,7 +172,7 @@ public void onClusterServiceClose() {
public void onTimeout(TimeValue timeout) {
releasingListener.onFailure(blockException);
}
}, newState -> false == newState.blocks().hasGlobalBlockWithLevel(ClusterBlockLevel.WRITE));
}, newState -> false == newState.blocks().hasGlobalBlockWithLevel(projectId, ClusterBlockLevel.WRITE));
} else {
forkAndExecute(task, bulkRequest, executor, releasingListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,12 @@ void executeRemoteRequest(

private static void checkIndexBlocks(ProjectState projectState, String[] concreteIndices) {
var blocks = projectState.blocks();
if (blocks.global().isEmpty() && blocks.indices(projectState.projectId()).isEmpty()) {
var projectId = projectState.projectId();
if (blocks.global(projectId).isEmpty() && blocks.indices(projectId).isEmpty()) {
// short circuit optimization because block check below is relatively expensive for many indices
return;
}
blocks.globalBlockedRaiseException(ClusterBlockLevel.READ);
blocks.globalBlockedRaiseException(projectId, ClusterBlockLevel.READ);
for (String index : concreteIndices) {
blocks.indexBlockedRaiseException(projectState.projectId(), ClusterBlockLevel.READ, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TransportMultiGetAction(
protected void doExecute(Task task, final MultiGetRequest request, final ActionListener<MultiGetResponse> listener) {
ClusterState clusterState = clusterService.state();
ProjectMetadata project = projectResolver.getProjectMetadata(clusterState);
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
clusterState.blocks().globalBlockedRaiseException(project.id(), ClusterBlockLevel.READ);

final AtomicArray<MultiGetItemResponse> responses = new AtomicArray<>(request.items.size());
final Map<ShardId, MultiGetShardRequest> shardRequests = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void masterOperation(

@Override
protected ClusterBlockException checkBlock(DeletePipelineRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.transport.TransportService;

public class GetPipelineTransportAction extends TransportLocalProjectMetadataAction<GetPipelineRequest, GetPipelineResponse> {

/**
* NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until
* we no longer need to support calling this action remotely.
Expand Down Expand Up @@ -71,7 +70,7 @@ protected void localClusterStateOperation(

@Override
protected ClusterBlockException checkBlock(GetPipelineRequest request, ProjectState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
return state.blocks().globalBlockedException(state.projectId(), ClusterBlockLevel.METADATA_READ);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void masterOperation(Task task, PutPipelineRequest request, ClusterSta

@Override
protected ClusterBlockException checkBlock(PutPipelineRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
Expand All @@ -44,20 +45,23 @@ public class TransportMultiSearchAction extends HandledTransportAction<MultiSear
private final ClusterService clusterService;
private final LongSupplier relativeTimeProvider;
private final NodeClient client;
private final ProjectResolver projectResolver;

@Inject
public TransportMultiSearchAction(
Settings settings,
TransportService transportService,
ClusterService clusterService,
ActionFilters actionFilters,
NodeClient client
NodeClient client,
ProjectResolver projectResolver
) {
super(TYPE.name(), transportService, actionFilters, MultiSearchRequest::new, EsExecutors.DIRECT_EXECUTOR_SERVICE);
this.clusterService = clusterService;
this.allocatedProcessors = EsExecutors.allocatedProcessors(settings);
this.relativeTimeProvider = System::nanoTime;
this.client = client;
this.projectResolver = projectResolver;
}

TransportMultiSearchAction(
Expand All @@ -66,21 +70,23 @@ public TransportMultiSearchAction(
ClusterService clusterService,
int allocatedProcessors,
LongSupplier relativeTimeProvider,
NodeClient client
NodeClient client,
ProjectResolver projectResolver
) {
super(TYPE.name(), transportService, actionFilters, MultiSearchRequest::new, EsExecutors.DIRECT_EXECUTOR_SERVICE);
this.clusterService = clusterService;
this.allocatedProcessors = allocatedProcessors;
this.relativeTimeProvider = relativeTimeProvider;
this.client = client;
this.projectResolver = projectResolver;
}

@Override
protected void doExecute(Task task, MultiSearchRequest request, ActionListener<MultiSearchResponse> listener) {
final long relativeStartTime = relativeTimeProvider.getAsLong();

ClusterState clusterState = clusterService.state();
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
clusterState.blocks().globalBlockedRaiseException(projectResolver.getProjectId(), ClusterBlockLevel.READ);

int maxConcurrentSearches = request.maxConcurrentSearchRequests();
if (maxConcurrentSearches == MultiSearchRequest.MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ private Map<String, OriginalIndices> buildPerIndexOriginalIndices(
) {
Map<String, OriginalIndices> res = Maps.newMapWithExpectedSize(indices.length);
var blocks = projectState.blocks();
var projectId = projectState.projectId();
// optimization: mostly we do not have any blocks so there's no point in the expensive per-index checking
boolean hasBlocks = blocks.global().isEmpty() == false || blocks.indices(projectState.projectId()).isEmpty() == false;
boolean hasBlocks = blocks.global(projectId).isEmpty() == false || blocks.indices(projectState.projectId()).isEmpty() == false;
// Get a distinct set of index abstraction names present from the resolved expressions to help with the reverse resolution from
// concrete index to the expression that produced it.
Set<String> indicesAndAliasesResources = indicesAndAliases.stream().map(ResolvedExpression::resource).collect(Collectors.toSet());
for (String index : indices) {
if (hasBlocks) {
blocks.indexBlockedRaiseException(projectState.projectId(), ClusterBlockLevel.READ, index);
blocks.indexBlockedRaiseException(projectId, ClusterBlockLevel.READ, index);
}

String[] aliases = indexNameExpressionResolver.allIndexAliases(projectState.metadata(), index, indicesAndAliases);
Expand Down Expand Up @@ -346,7 +347,7 @@ void executeRequest(
);

final ClusterState clusterState = clusterService.state();
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
clusterState.blocks().globalBlockedRaiseException(projectResolver.getProjectId(), ClusterBlockLevel.READ);

ProjectState projectState = projectResolver.getProjectState(clusterState);
Comment on lines +350 to 352
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
clusterState.blocks().globalBlockedRaiseException(projectResolver.getProjectId(), ClusterBlockLevel.READ);
ProjectState projectState = projectResolver.getProjectState(clusterState);
ProjectState projectState = projectResolver.getProjectState(clusterState);
clusterState.blocks().globalBlockedRaiseException(projectState.projectId(), ClusterBlockLevel.READ);

final ResolvedIndices resolvedIndices;
Expand Down Expand Up @@ -1410,7 +1411,7 @@ static boolean shouldPreFilterSearchShards(

private static boolean hasReadOnlyIndices(String[] indices, ProjectState projectState) {
var blocks = projectState.blocks();
if (blocks.global().isEmpty() && blocks.indices(projectState.projectId()).isEmpty()) {
if (blocks.global(projectState.projectId()).isEmpty() && blocks.indices(projectState.projectId()).isEmpty()) {
// short circuit optimization because block check below is relatively expensive for many indices
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public TransportMultiTermVectorsAction(
protected void doExecute(Task task, final MultiTermVectorsRequest request, final ActionListener<MultiTermVectorsResponse> listener) {
ClusterState clusterState = clusterService.state();
ProjectMetadata project = projectResolver.getProjectMetadata(clusterState);
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
clusterState.blocks().globalBlockedRaiseException(project.id(), ClusterBlockLevel.READ);

final AtomicArray<MultiTermVectorsItemResponse> responses = new AtomicArray<>(request.requests.size());

Expand Down
Loading