Skip to content

Migrate Streamable to Writeable for cluster block package #37391

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

Merged
merged 3 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public String toString() {
@Override
public void readFrom(final StreamInput in) throws IOException {
super.readFrom(in);
clusterBlock = ClusterBlock.readClusterBlock(in);
clusterBlock = new ClusterBlock(in);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus;
Expand All @@ -34,7 +35,7 @@
import java.util.Locale;
import java.util.Objects;

public class ClusterBlock implements Streamable, ToXContentFragment {
public class ClusterBlock implements Streamable, Writeable, ToXContentFragment {

private int id;
private @Nullable String uuid;
Expand All @@ -45,7 +46,24 @@ public class ClusterBlock implements Streamable, ToXContentFragment {
private boolean allowReleaseResources;
private RestStatus status;

private ClusterBlock() {
public ClusterBlock(StreamInput in) throws IOException {
id = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
uuid = in.readOptionalString();
} else {
uuid = null;
}
description = in.readString();
final int len = in.readVInt();
ArrayList<ClusterBlockLevel> levels = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
levels.add(in.readEnum(ClusterBlockLevel.class));
}
this.levels = EnumSet.copyOf(levels);
retryable = in.readBoolean();
disableStatePersistence = in.readBoolean();
status = RestStatus.readFrom(in);
allowReleaseResources = in.readBoolean();
}

public ClusterBlock(int id, String description, boolean retryable, boolean disableStatePersistence,
Expand Down Expand Up @@ -129,31 +147,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static ClusterBlock readClusterBlock(StreamInput in) throws IOException {
ClusterBlock block = new ClusterBlock();
block.readFrom(in);
return block;
}

@Override
public void readFrom(StreamInput in) throws IOException {
id = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
uuid = in.readOptionalString();
} else {
uuid = null;
}
description = in.readString();
final int len = in.readVInt();
ArrayList<ClusterBlockLevel> levels = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
levels.add(in.readEnum(ClusterBlockLevel.class));
}
this.levels = EnumSet.copyOf(levels);
retryable = in.readBoolean();
disableStatePersistence = in.readBoolean();
status = RestStatus.readFrom(in);
allowReleaseResources = in.readBoolean();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ClusterBlockException(StreamInput in) throws IOException {
int totalBlocks = in.readVInt();
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
for (int i = 0; i < totalBlocks;i++) {
blocks.add(ClusterBlock.readClusterBlock(in));
blocks.add(new ClusterBlock(in));
}
this.blocks = unmodifiableSet(blocks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private static Set<ClusterBlock> readBlockSet(StreamInput in) throws IOException
int totalBlocks = in.readVInt();
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
for (int i = 0; i < totalBlocks;i++) {
blocks.add(ClusterBlock.readClusterBlock(in));
blocks.add(new ClusterBlock(in));
}
return unmodifiableSet(blocks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testSerialization() throws Exception {

StreamInput in = out.bytes().streamInput();
in.setVersion(version);
ClusterBlock result = ClusterBlock.readClusterBlock(in);
ClusterBlock result = new ClusterBlock(in);

assertClusterBlockEquals(clusterBlock, result);
}
Expand All @@ -74,7 +74,7 @@ public void testBwcSerialization() throws Exception {
expected.writeTo(out);

// Deserialize and check the cluster block
final ClusterBlock actual = ClusterBlock.readClusterBlock(out.bytes().streamInput());
final ClusterBlock actual = new ClusterBlock(out.bytes().streamInput());
assertClusterBlockEquals(expected, actual);
}

Expand All @@ -90,7 +90,7 @@ public void testBwcSerialization() throws Exception {
// Deserialize and check the cluster block
final StreamInput in = out.bytes().streamInput();
in.setVersion(out.getVersion());
final ClusterBlock actual = ClusterBlock.readClusterBlock(in);
final ClusterBlock actual = new ClusterBlock(in);

assertThat(actual.id(), equalTo(expected.id()));
assertThat(actual.status(), equalTo(expected.status()));
Expand Down