-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Move serialization back out of SplitShardCountSummary #136055
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,15 +9,9 @@ | |||||
|
||||||
package org.elasticsearch.cluster.routing; | ||||||
|
||||||
import org.elasticsearch.TransportVersion; | ||||||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||||||
import org.elasticsearch.cluster.metadata.IndexReshardingMetadata; | ||||||
import org.elasticsearch.cluster.metadata.IndexReshardingState; | ||||||
import org.elasticsearch.common.io.stream.StreamInput; | ||||||
import org.elasticsearch.common.io.stream.StreamOutput; | ||||||
import org.elasticsearch.common.io.stream.Writeable; | ||||||
|
||||||
import java.io.IOException; | ||||||
|
||||||
/** | ||||||
* The SplitShardCountSummary has been added to accommodate in-place index resharding. | ||||||
|
@@ -57,12 +51,7 @@ | |||||
* will be treated as a Summary mismatch on the source shard node. | ||||||
*/ | ||||||
|
||||||
public class SplitShardCountSummary implements Writeable { | ||||||
// superseded | ||||||
private static final TransportVersion INDEX_RESHARD_SHARDCOUNT_SUMMARY = TransportVersion.fromName("index_reshard_shardcount_summary"); | ||||||
// bumped to use VInt instead of Int | ||||||
private static final TransportVersion INDEX_RESHARD_SHARDCOUNT_SMALL = TransportVersion.fromName("index_reshard_shardcount_small"); | ||||||
|
||||||
public class SplitShardCountSummary { | ||||||
public static final SplitShardCountSummary UNSET = new SplitShardCountSummary(0); | ||||||
|
||||||
/** | ||||||
|
@@ -137,39 +126,35 @@ private static SplitShardCountSummary getReshardSplitShardCountSummary( | |||||
return new SplitShardCountSummary(shardCount); | ||||||
} | ||||||
|
||||||
private final int shardCountSummary; | ||||||
/** | ||||||
* Construct a SplitShardCountSummary from an integer | ||||||
* Used for deserialization. | ||||||
*/ | ||||||
public static SplitShardCountSummary fromInt(int payload) { | ||||||
return new SplitShardCountSummary(payload); | ||||||
} | ||||||
|
||||||
public SplitShardCountSummary(StreamInput in) throws IOException { | ||||||
if (in.getTransportVersion().supports(INDEX_RESHARD_SHARDCOUNT_SMALL)) { | ||||||
this.shardCountSummary = in.readVInt(); | ||||||
} else if (in.getTransportVersion().supports(INDEX_RESHARD_SHARDCOUNT_SUMMARY)) { | ||||||
this.shardCountSummary = in.readInt(); | ||||||
} else { | ||||||
this.shardCountSummary = UNSET.shardCountSummary; | ||||||
} | ||||||
/** | ||||||
* Return an integer representation of this summary | ||||||
* Used for serialization. | ||||||
*/ | ||||||
public int asInt() { | ||||||
return shardCountSummary; | ||||||
} | ||||||
|
||||||
private final int shardCountSummary; | ||||||
|
||||||
/** | ||||||
* Returns whether this shard count summary is carrying an actual value or is UNSET | ||||||
*/ | ||||||
public boolean isUnset() { | ||||||
return this.shardCountSummary == UNSET.shardCountSummary; | ||||||
} | ||||||
|
||||||
// visible for testing | ||||||
SplitShardCountSummary(int shardCountSummary) { | ||||||
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. [nitpick] The constructor visibility was changed from package-private with a comment 'visible for testing' to package-private without comment. Consider adding back the visibility comment or making it private since it's now only used internally via the fromInt() factory method.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. I didn't mean to remove the comment. Thanks copilot! |
||||||
this.shardCountSummary = shardCountSummary; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void writeTo(StreamOutput out) throws IOException { | ||||||
if (out.getTransportVersion().supports(INDEX_RESHARD_SHARDCOUNT_SMALL)) { | ||||||
out.writeVInt(shardCountSummary); | ||||||
} else if (out.getTransportVersion().supports(INDEX_RESHARD_SHARDCOUNT_SUMMARY)) { | ||||||
out.writeInt(shardCountSummary); | ||||||
} | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean equals(Object other) { | ||||||
if (this == other) { | ||||||
|
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.
[nitpick] The field declaration was moved after the method definitions. Consider keeping field declarations at the top of the class for better readability and consistency with Java conventions.
Copilot uses AI. Check for mistakes.