|
@@ -191,7 +191,7 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
String node,
|
|
|
boolean nodeIsDesired,
|
|
|
@Nullable String relocatingNode,
|
|
|
- boolean relocatingNodeIsDesired,
|
|
|
+ @Nullable Boolean relocatingNodeIsDesired,
|
|
|
int shardId,
|
|
|
String index,
|
|
|
@Nullable Double forecastWriteLoad,
|
|
@@ -201,25 +201,47 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
|
|
|
private static final TransportVersion ADD_FORECASTS_VERSION = TransportVersion.V_8_7_0;
|
|
|
private static final TransportVersion ADD_TIER_PREFERENCE = TransportVersion.V_8_8_0;
|
|
|
+ private static final TransportVersion NULLABLE_RELOCATING_NODE_IS_DESIRED = TransportVersion.V_8_8_0;
|
|
|
+
|
|
|
+ public ShardView {
|
|
|
+ assert (relocatingNode == null) == (relocatingNodeIsDesired == null)
|
|
|
+ : "relocatingNodeIsDesired should only be set when relocatingNode is set";
|
|
|
+ }
|
|
|
|
|
|
public static ShardView from(StreamInput in) throws IOException {
|
|
|
- var view = new ShardView(
|
|
|
- ShardRoutingState.fromValue(in.readByte()),
|
|
|
- in.readBoolean(),
|
|
|
- in.readOptionalString(),
|
|
|
- in.readBoolean(),
|
|
|
- in.readOptionalString(),
|
|
|
- in.readBoolean(),
|
|
|
- in.readVInt(),
|
|
|
- in.readString(),
|
|
|
- in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalDouble() : null,
|
|
|
- in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalLong() : null,
|
|
|
- in.getTransportVersion().onOrAfter(ADD_TIER_PREFERENCE) ? in.readStringList() : List.of()
|
|
|
- );
|
|
|
+ ShardRoutingState state = ShardRoutingState.fromValue(in.readByte());
|
|
|
+ boolean primary = in.readBoolean();
|
|
|
+ String node = in.readOptionalString();
|
|
|
+ boolean nodeIsDesired = in.readBoolean();
|
|
|
+ String relocatingNode = in.readOptionalString();
|
|
|
+ Boolean relocatingNodeIsDesired;
|
|
|
+ if (in.getTransportVersion().onOrAfter(NULLABLE_RELOCATING_NODE_IS_DESIRED)) {
|
|
|
+ relocatingNodeIsDesired = in.readOptionalBoolean();
|
|
|
+ } else {
|
|
|
+ boolean wireRelocatingNodeIsDesired = in.readBoolean();
|
|
|
+ relocatingNodeIsDesired = relocatingNode == null ? null : wireRelocatingNodeIsDesired;
|
|
|
+ }
|
|
|
+ int shardId = in.readVInt();
|
|
|
+ String index = in.readString();
|
|
|
+ Double forecastWriteLoad = in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalDouble() : null;
|
|
|
+ Long forecastShardSizeInBytes = in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalLong() : null;
|
|
|
if (in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) == false) {
|
|
|
in.readOptionalWriteable(AllocationId::new);
|
|
|
}
|
|
|
- return view;
|
|
|
+ List<String> tierPreference = in.getTransportVersion().onOrAfter(ADD_TIER_PREFERENCE) ? in.readStringList() : List.of();
|
|
|
+ return new ShardView(
|
|
|
+ state,
|
|
|
+ primary,
|
|
|
+ node,
|
|
|
+ nodeIsDesired,
|
|
|
+ relocatingNode,
|
|
|
+ relocatingNodeIsDesired,
|
|
|
+ shardId,
|
|
|
+ index,
|
|
|
+ forecastWriteLoad,
|
|
|
+ forecastShardSizeInBytes,
|
|
|
+ tierPreference
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -229,7 +251,11 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
out.writeOptionalString(node);
|
|
|
out.writeBoolean(nodeIsDesired);
|
|
|
out.writeOptionalString(relocatingNode);
|
|
|
- out.writeBoolean(relocatingNodeIsDesired);
|
|
|
+ if (out.getTransportVersion().onOrAfter(NULLABLE_RELOCATING_NODE_IS_DESIRED)) {
|
|
|
+ out.writeOptionalBoolean(relocatingNodeIsDesired);
|
|
|
+ } else {
|
|
|
+ out.writeBoolean(relocatingNodeIsDesired != null && relocatingNodeIsDesired);
|
|
|
+ }
|
|
|
out.writeVInt(shardId);
|
|
|
out.writeString(index);
|
|
|
if (out.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION)) {
|
|
@@ -246,14 +272,14 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
return builder.startObject()
|
|
|
+ .field("index", index)
|
|
|
+ .field("shard_id", shardId)
|
|
|
.field("state", state.toString())
|
|
|
.field("primary", primary)
|
|
|
.field("node", node)
|
|
|
.field("node_is_desired", nodeIsDesired)
|
|
|
.field("relocating_node", relocatingNode)
|
|
|
.field("relocating_node_is_desired", relocatingNodeIsDesired)
|
|
|
- .field("shard_id", shardId)
|
|
|
- .field("index", index)
|
|
|
.field("forecast_write_load", forecastWriteLoad)
|
|
|
.field("forecast_shard_size_in_bytes", forecastShardSizeInBytes)
|
|
|
.field("tier_preference", tierPreference)
|