Migrate Streamable to Writeable for cluster block package (#37391) (#39236)

This commit is contained in:
Daniel Mitterdorfer 2019-02-21 15:21:44 +01:00 committed by GitHub
parent ecfd48b6d3
commit ef921fd157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 31 deletions

View File

@ -158,7 +158,7 @@ public class TransportVerifyShardBeforeCloseAction extends TransportReplicationA
@Override @Override
public void readFrom(final StreamInput in) throws IOException { public void readFrom(final StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
clusterBlock = ClusterBlock.readClusterBlock(in); clusterBlock = new ClusterBlock(in);
} }
@Override @Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; 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.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
@ -34,7 +35,7 @@ import java.util.EnumSet;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
public class ClusterBlock implements Streamable, ToXContentFragment { public class ClusterBlock implements Streamable, Writeable, ToXContentFragment {
private int id; private int id;
private @Nullable String uuid; private @Nullable String uuid;
@ -45,7 +46,24 @@ public class ClusterBlock implements Streamable, ToXContentFragment {
private boolean allowReleaseResources; private boolean allowReleaseResources;
private RestStatus status; 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, public ClusterBlock(int id, String description, boolean retryable, boolean disableStatePersistence,
@ -129,31 +147,9 @@ public class ClusterBlock implements Streamable, ToXContentFragment {
return builder; return builder;
} }
public static ClusterBlock readClusterBlock(StreamInput in) throws IOException {
ClusterBlock block = new ClusterBlock();
block.readFrom(in);
return block;
}
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
id = in.readVInt(); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
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();
} }
@Override @Override

View File

@ -43,7 +43,7 @@ public class ClusterBlockException extends ElasticsearchException {
int totalBlocks = in.readVInt(); int totalBlocks = in.readVInt();
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks); Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
for (int i = 0; i < totalBlocks;i++) { for (int i = 0; i < totalBlocks;i++) {
blocks.add(ClusterBlock.readClusterBlock(in)); blocks.add(new ClusterBlock(in));
} }
this.blocks = unmodifiableSet(blocks); this.blocks = unmodifiableSet(blocks);
} }

View File

@ -305,7 +305,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
int totalBlocks = in.readVInt(); int totalBlocks = in.readVInt();
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks); Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
for (int i = 0; i < totalBlocks;i++) { for (int i = 0; i < totalBlocks;i++) {
blocks.add(ClusterBlock.readClusterBlock(in)); blocks.add(new ClusterBlock(in));
} }
return unmodifiableSet(blocks); return unmodifiableSet(blocks);
} }

View File

@ -56,7 +56,7 @@ public class ClusterBlockTests extends ESTestCase {
StreamInput in = out.bytes().streamInput(); StreamInput in = out.bytes().streamInput();
in.setVersion(version); in.setVersion(version);
ClusterBlock result = ClusterBlock.readClusterBlock(in); ClusterBlock result = new ClusterBlock(in);
assertClusterBlockEquals(clusterBlock, result); assertClusterBlockEquals(clusterBlock, result);
} }
@ -74,7 +74,7 @@ public class ClusterBlockTests extends ESTestCase {
expected.writeTo(out); expected.writeTo(out);
// Deserialize and check the cluster block // 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); assertClusterBlockEquals(expected, actual);
} }
@ -90,7 +90,7 @@ public class ClusterBlockTests extends ESTestCase {
// Deserialize and check the cluster block // Deserialize and check the cluster block
final StreamInput in = out.bytes().streamInput(); final StreamInput in = out.bytes().streamInput();
in.setVersion(out.getVersion()); in.setVersion(out.getVersion());
final ClusterBlock actual = ClusterBlock.readClusterBlock(in); final ClusterBlock actual = new ClusterBlock(in);
assertThat(actual.id(), equalTo(expected.id())); assertThat(actual.id(), equalTo(expected.id()));
assertThat(actual.status(), equalTo(expected.status())); assertThat(actual.status(), equalTo(expected.status()));