Skip to content

Commit

Permalink
No wait for search shards in reserved role mapping update
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Nov 9, 2023
1 parent 6b72def commit 600fbfb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static TransportVersion def(int id) {
public static final TransportVersion UNDESIRED_SHARD_ALLOCATIONS_COUNT_ADDED = def(8_530_00_0);
public static final TransportVersion ML_INFERENCE_TASK_SETTINGS_OPTIONAL_ADDED = def(8_531_00_0);
public static final TransportVersion DEPRECATED_COMPONENT_TEMPLATES_ADDED = def(8_532_00_0);
public static final TransportVersion PUT_ROLE_MAPPING_REQUEST_ACTIVE_SHARD = def(8_534_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class PutRoleMappingRequest extends ActionRequest implements WriteRequest
private RoleMapperExpression rules = null;
private Map<String, Object> metadata = Collections.emptyMap();
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
private ActiveShardCount activeShardCount = ActiveShardCount.DEFAULT;

public PutRoleMappingRequest(StreamInput in) throws IOException {
super(in);
Expand All @@ -53,6 +55,9 @@ public PutRoleMappingRequest(StreamInput in) throws IOException {
this.rules = ExpressionParser.readExpression(in);
this.metadata = in.readMap();
this.refreshPolicy = RefreshPolicy.readFrom(in);
if (in.getTransportVersion().onOrAfter(TransportVersions.PUT_ROLE_MAPPING_REQUEST_ACTIVE_SHARD)) {
this.activeShardCount = ActiveShardCount.readFrom(in);
}
}

public PutRoleMappingRequest() {}
Expand Down Expand Up @@ -149,6 +154,14 @@ public Map<String, Object> getMetadata() {
return metadata;
}

public ActiveShardCount getActiveShardCount() {
return activeShardCount;
}

public void setActiveShardCount(ActiveShardCount activeShardCount) {
this.activeShardCount = activeShardCount;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand All @@ -160,6 +173,9 @@ public void writeTo(StreamOutput out) throws IOException {
}
ExpressionParser.writeExpression(rules, out);
out.writeGenericMap(metadata);
if (out.getTransportVersion().onOrAfter(TransportVersions.PUT_ROLE_MAPPING_REQUEST_ACTIVE_SHARD)) {
activeShardCount.writeTo(out);
}
refreshPolicy.writeTo(out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.xpack.security.action.rolemapping;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.GroupedActionListener;
import org.elasticsearch.common.util.concurrent.ListenableFuture;
import org.elasticsearch.reservedstate.NonStateTransformResult;
Expand Down Expand Up @@ -126,6 +127,8 @@ public void onFailure(Exception e) {
});

for (var request : requests) {
// Avoid waiting for search shards since the security index may still be bootstrapping
request.setActiveShardCount(ActiveShardCount.NONE);
roleMappingStore.putRoleMapping(request, taskListener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ private void innerPutMapping(PutRoleMappingRequest request, ActionListener<Boole
.setId(getIdForName(mapping.getName()))
.setSource(xContentBuilder)
.setRefreshPolicy(request.getRefreshPolicy())
.setWaitForActiveShards(request.getActiveShardCount())
.request(),
new ActionListener<DocWriteResponse>() {
@Override
Expand Down

0 comments on commit 600fbfb

Please sign in to comment.