Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre conditions check before updating weighted routing metadata #4955

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Migrate client transports to Apache HttpClient / Core 5.x ([#4459](https://github.com/opensearch-project/OpenSearch/pull/4459))
- Refactored BalancedAllocator.Balancer to LocalShardsBalancer ([#4761](https://github.com/opensearch-project/OpenSearch/pull/4761))
- Fail weight update when decommission ongoing and fail decommission when attribute not weighed away ([#4839](https://github.com/opensearch-project/OpenSearch/pull/4839))
- Allow weight updates for non decommissioned attribute([#4955](https://github.com/opensearch-project/OpenSearch/pull/4955))
### Deprecated
### Removed
- Remove deprecated code to add node name into log pattern of log4j property file ([#4568](https://github.com/opensearch-project/OpenSearch/pull/4568))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.util.List;
import java.util.Locale;
import java.util.Objects;

import static org.opensearch.action.ValidateActions.addValidationError;

Expand Down Expand Up @@ -70,8 +71,8 @@ public void registerWeightedRoutingMetadata(
clusterService.submitStateUpdateTask("update_weighted_routing", new ClusterStateUpdateTask(Priority.URGENT) {
@Override
public ClusterState execute(ClusterState currentState) {
// verify currently no decommission action is ongoing
ensureNoOngoingDecommissionAction(currentState);
// verify weights will not be updated for a decommissioned attribute
ensureNoWeightUpdateForDecommissionedAttribute(currentState, request);
Metadata metadata = currentState.metadata();
Metadata.Builder mdBuilder = Metadata.builder(currentState.metadata());
WeightedRoutingMetadata weightedRoutingMetadata = metadata.custom(WeightedRoutingMetadata.TYPE);
Expand Down Expand Up @@ -159,9 +160,18 @@ public void verifyAwarenessAttribute(String attributeName) {
}
}

public void ensureNoOngoingDecommissionAction(ClusterState state) {
public void ensureNoWeightUpdateForDecommissionedAttribute(ClusterState state, ClusterPutWeightedRoutingRequest request) {
DecommissionAttributeMetadata decommissionAttributeMetadata = state.metadata().decommissionAttributeMetadata();
if (decommissionAttributeMetadata != null && decommissionAttributeMetadata.status().equals(DecommissionStatus.FAILED) == false) {
if (decommissionAttributeMetadata != null
&& decommissionAttributeMetadata.status().equals(DecommissionStatus.FAILED) == false
&& Objects.equals(
request.getWeightedRouting().attributeName(),
decommissionAttributeMetadata.decommissionAttribute().attributeName()
)
&& Objects.equals(
request.getWeightedRouting().weights().get(decommissionAttributeMetadata.decommissionAttribute().attributeValue()),
0.0
) == false) {
throw new IllegalStateException(
imRishN marked this conversation as resolved.
Show resolved Hide resolved
"a decommission action is ongoing with status ["
+ decommissionAttributeMetadata.status().status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,36 @@ public void onFailure(Exception e) {}
weightedRoutingService.registerWeightedRoutingMetadata(request.request(), listener);
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
}

public void testAddWeightedRoutingPassesWhenWeightOfDecommissionedAttributeStillZero() throws InterruptedException {
imRishN marked this conversation as resolved.
Show resolved Hide resolved
Map<String, Double> weights = Map.of("zone_A", 0.0, "zone_B", 1.0, "zone_C", 1.0);
DecommissionStatus status = DecommissionStatus.SUCCESSFUL;
ClusterState state = clusterService.state();
state = setWeightedRoutingWeights(state, weights);
state = setDecommissionAttribute(state, status);
ClusterState.Builder builder = ClusterState.builder(state);
ClusterServiceUtils.setState(clusterService, builder);

ClusterPutWeightedRoutingRequestBuilder request = new ClusterPutWeightedRoutingRequestBuilder(
client,
ClusterAddWeightedRoutingAction.INSTANCE
);
Map<String, Double> updatedWeights = Map.of("zone_A", 0.0, "zone_B", 2.0, "zone_C", 1.0);
WeightedRouting updatedWeightedRouting = new WeightedRouting("zone", updatedWeights);
request.setWeightedRouting(updatedWeightedRouting);
final CountDownLatch countDownLatch = new CountDownLatch(1);
ActionListener<ClusterStateUpdateResponse> listener = new ActionListener<ClusterStateUpdateResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
assertTrue(clusterStateUpdateResponse.isAcknowledged());
countDownLatch.countDown();
}

@Override
public void onFailure(Exception e) {}
};
weightedRoutingService.registerWeightedRoutingMetadata(request.request(), listener);
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertEquals(updatedWeightedRouting, clusterService.state().metadata().weightedRoutingMetadata().getWeightedRouting());
}
}