-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Weighted Routing] Add support for discovered master and remove local weights in the response #5680
Merged
Bukhtawar
merged 8 commits into
opensearch-project:main
from
anshu1106:feature/wrr-deprecate-get-local
Jan 7, 2023
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70971dc
Initial Commit
73fd9b8
Fix test
ef429b2
Fix test failure
5ad7e3c
Fix test
311363a
Add changelog
1d904be
Address review comments
4e15525
Fix comments
dff4cce
Merge branch 'main' into feature/wrr-deprecate-get-local
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,26 +31,37 @@ | |
* @opensearch.internal | ||
*/ | ||
public class ClusterGetWeightedRoutingResponse extends ActionResponse implements ToXContentObject { | ||
private WeightedRouting weightedRouting; | ||
private String localNodeWeight; | ||
private static final String NODE_WEIGHT = "node_weight"; | ||
public WeightedRouting getWeightedRouting() { | ||
return weightedRouting; | ||
} | ||
|
||
private final WeightedRouting weightedRouting; | ||
|
||
public String getLocalNodeWeight() { | ||
return localNodeWeight; | ||
public Boolean getDiscoveredClusterManager() { | ||
return discoveredClusterManager; | ||
} | ||
|
||
private final Boolean discoveredClusterManager; | ||
|
||
private static final String DISCOVERED_CLUSTER_MANAGER = "discovered_cluster_manager"; | ||
|
||
ClusterGetWeightedRoutingResponse() { | ||
this.weightedRouting = null; | ||
this.discoveredClusterManager = null; | ||
} | ||
Comment on lines
48
to
51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no explicit need to set them null |
||
|
||
public ClusterGetWeightedRoutingResponse(String localNodeWeight, WeightedRouting weightedRouting) { | ||
this.localNodeWeight = localNodeWeight; | ||
public ClusterGetWeightedRoutingResponse(WeightedRouting weightedRouting, Boolean discoveredClusterManager) { | ||
this.discoveredClusterManager = discoveredClusterManager; | ||
this.weightedRouting = weightedRouting; | ||
} | ||
|
||
ClusterGetWeightedRoutingResponse(StreamInput in) throws IOException { | ||
if (in.available() != 0) { | ||
this.weightedRouting = new WeightedRouting(in); | ||
this.discoveredClusterManager = in.readOptionalBoolean(); | ||
} else { | ||
this.weightedRouting = null; | ||
this.discoveredClusterManager = null; | ||
} | ||
} | ||
|
||
|
@@ -68,6 +79,9 @@ public void writeTo(StreamOutput out) throws IOException { | |
if (weightedRouting != null) { | ||
weightedRouting.writeTo(out); | ||
} | ||
if (discoveredClusterManager != null) { | ||
out.writeOptionalBoolean(discoveredClusterManager); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -77,8 +91,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
for (Map.Entry<String, Double> entry : weightedRouting.weights().entrySet()) { | ||
builder.field(entry.getKey(), entry.getValue().toString()); | ||
} | ||
if (localNodeWeight != null) { | ||
builder.field(NODE_WEIGHT, localNodeWeight); | ||
if (discoveredClusterManager != null) { | ||
builder.field(DISCOVERED_CLUSTER_MANAGER, discoveredClusterManager); | ||
} | ||
} | ||
builder.endObject(); | ||
|
@@ -89,37 +103,37 @@ public static ClusterGetWeightedRoutingResponse fromXContent(XContentParser pars | |
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
XContentParser.Token token; | ||
String attrKey = null, attrValue = null; | ||
String localNodeWeight = null; | ||
Boolean discoveredClusterManager = null; | ||
Map<String, Double> weights = new HashMap<>(); | ||
|
||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token == XContentParser.Token.FIELD_NAME) { | ||
attrKey = parser.currentName(); | ||
} else if (token == XContentParser.Token.VALUE_STRING) { | ||
attrValue = parser.text(); | ||
if (attrKey != null && attrKey.equals(NODE_WEIGHT)) { | ||
localNodeWeight = attrValue; | ||
} else if (attrKey != null) { | ||
if (attrKey != null) { | ||
weights.put(attrKey, Double.parseDouble(attrValue)); | ||
} | ||
} else if (token == XContentParser.Token.VALUE_BOOLEAN && attrKey != null && attrKey.equals(DISCOVERED_CLUSTER_MANAGER)) { | ||
discoveredClusterManager = Boolean.parseBoolean(parser.text()); | ||
} else { | ||
throw new OpenSearchParseException("failed to parse weighted routing response"); | ||
} | ||
} | ||
WeightedRouting weightedRouting = new WeightedRouting("", weights); | ||
return new ClusterGetWeightedRoutingResponse(localNodeWeight, weightedRouting); | ||
return new ClusterGetWeightedRoutingResponse(weightedRouting, discoveredClusterManager); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ClusterGetWeightedRoutingResponse that = (ClusterGetWeightedRoutingResponse) o; | ||
return weightedRouting.equals(that.weightedRouting) && localNodeWeight.equals(that.localNodeWeight); | ||
return weightedRouting.equals(that.weightedRouting) && discoveredClusterManager.equals(that.discoveredClusterManager); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(weightedRouting, localNodeWeight); | ||
return Objects.hash(weightedRouting, discoveredClusterManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
discovered_cluster_manager
assertion as well .