Skip to content
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 @@ -253,6 +253,7 @@ static TransportVersion def(int id) {
public static final TransportVersion INFERENCE_ADD_TIMEOUT_PUT_ENDPOINT = def(9_074_0_00);
public static final TransportVersion ESQL_FIELD_ATTRIBUTE_DROP_TYPE = def(9_075_0_00);
public static final TransportVersion ESQL_TIME_SERIES_SOURCE_STATUS = def(9_076_0_00);
public static final TransportVersion PROJECT_DELETION_GLOBAL_BLOCK = def(9_077_0_00);

/*
* STOP! READ THIS FIRST! No, really,
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 @@ -142,6 +142,7 @@ private void ensureClusterStateThenForkAndExecute(
ActionListener<BulkResponse> releasingListener
) {
final ClusterState initialState = clusterService.state();
ProjectId projectId = projectResolver.getProjectId();
final ClusterBlockException blockException = initialState.blocks().globalBlockedException(ClusterBlockLevel.WRITE);
if (blockException != null) {
if (false == blockException.retryable()) {
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 @@ -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 @@ -220,14 +220,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 @@ -341,7 +342,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);
final ResolvedIndices resolvedIndices;
Expand Down Expand Up @@ -1405,7 +1406,8 @@ static boolean shouldPreFilterSearchShards(

private static boolean hasReadOnlyIndices(String[] indices, ProjectState projectState) {
var blocks = projectState.blocks();
if (blocks.global().isEmpty() && blocks.indices(projectState.projectId()).isEmpty()) {
var projectId = projectState.projectId();
if (blocks.global(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