Skip to content

Commit ef921fd

Browse files
Migrate Streamable to Writeable for cluster block package (#37391) (#39236)
1 parent ecfd48b commit ef921fd

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public String toString() {
158158
@Override
159159
public void readFrom(final StreamInput in) throws IOException {
160160
super.readFrom(in);
161-
clusterBlock = ClusterBlock.readClusterBlock(in);
161+
clusterBlock = new ClusterBlock(in);
162162
}
163163

164164
@Override

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.common.io.stream.StreamInput;
2525
import org.elasticsearch.common.io.stream.StreamOutput;
2626
import org.elasticsearch.common.io.stream.Streamable;
27+
import org.elasticsearch.common.io.stream.Writeable;
2728
import org.elasticsearch.common.xcontent.ToXContentFragment;
2829
import org.elasticsearch.common.xcontent.XContentBuilder;
2930
import org.elasticsearch.rest.RestStatus;
@@ -34,7 +35,7 @@
3435
import java.util.Locale;
3536
import java.util.Objects;
3637

37-
public class ClusterBlock implements Streamable, ToXContentFragment {
38+
public class ClusterBlock implements Streamable, Writeable, ToXContentFragment {
3839

3940
private int id;
4041
private @Nullable String uuid;
@@ -45,7 +46,24 @@ public class ClusterBlock implements Streamable, ToXContentFragment {
4546
private boolean allowReleaseResources;
4647
private RestStatus status;
4748

48-
private ClusterBlock() {
49+
public ClusterBlock(StreamInput in) throws IOException {
50+
id = in.readVInt();
51+
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
52+
uuid = in.readOptionalString();
53+
} else {
54+
uuid = null;
55+
}
56+
description = in.readString();
57+
final int len = in.readVInt();
58+
ArrayList<ClusterBlockLevel> levels = new ArrayList<>(len);
59+
for (int i = 0; i < len; i++) {
60+
levels.add(in.readEnum(ClusterBlockLevel.class));
61+
}
62+
this.levels = EnumSet.copyOf(levels);
63+
retryable = in.readBoolean();
64+
disableStatePersistence = in.readBoolean();
65+
status = RestStatus.readFrom(in);
66+
allowReleaseResources = in.readBoolean();
4967
}
5068

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

132-
public static ClusterBlock readClusterBlock(StreamInput in) throws IOException {
133-
ClusterBlock block = new ClusterBlock();
134-
block.readFrom(in);
135-
return block;
136-
}
137-
138150
@Override
139151
public void readFrom(StreamInput in) throws IOException {
140-
id = in.readVInt();
141-
if (in.getVersion().onOrAfter(Version.V_6_7_0)) {
142-
uuid = in.readOptionalString();
143-
} else {
144-
uuid = null;
145-
}
146-
description = in.readString();
147-
final int len = in.readVInt();
148-
ArrayList<ClusterBlockLevel> levels = new ArrayList<>(len);
149-
for (int i = 0; i < len; i++) {
150-
levels.add(in.readEnum(ClusterBlockLevel.class));
151-
}
152-
this.levels = EnumSet.copyOf(levels);
153-
retryable = in.readBoolean();
154-
disableStatePersistence = in.readBoolean();
155-
status = RestStatus.readFrom(in);
156-
allowReleaseResources = in.readBoolean();
152+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
157153
}
158154

159155
@Override

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ClusterBlockException(StreamInput in) throws IOException {
4343
int totalBlocks = in.readVInt();
4444
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
4545
for (int i = 0; i < totalBlocks;i++) {
46-
blocks.add(ClusterBlock.readClusterBlock(in));
46+
blocks.add(new ClusterBlock(in));
4747
}
4848
this.blocks = unmodifiableSet(blocks);
4949
}

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private static Set<ClusterBlock> readBlockSet(StreamInput in) throws IOException
305305
int totalBlocks = in.readVInt();
306306
Set<ClusterBlock> blocks = new HashSet<>(totalBlocks);
307307
for (int i = 0; i < totalBlocks;i++) {
308-
blocks.add(ClusterBlock.readClusterBlock(in));
308+
blocks.add(new ClusterBlock(in));
309309
}
310310
return unmodifiableSet(blocks);
311311
}

server/src/test/java/org/elasticsearch/cluster/block/ClusterBlockTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void testSerialization() throws Exception {
5656

5757
StreamInput in = out.bytes().streamInput();
5858
in.setVersion(version);
59-
ClusterBlock result = ClusterBlock.readClusterBlock(in);
59+
ClusterBlock result = new ClusterBlock(in);
6060

6161
assertClusterBlockEquals(clusterBlock, result);
6262
}
@@ -74,7 +74,7 @@ public void testBwcSerialization() throws Exception {
7474
expected.writeTo(out);
7575

7676
// Deserialize and check the cluster block
77-
final ClusterBlock actual = ClusterBlock.readClusterBlock(out.bytes().streamInput());
77+
final ClusterBlock actual = new ClusterBlock(out.bytes().streamInput());
7878
assertClusterBlockEquals(expected, actual);
7979
}
8080

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

9595
assertThat(actual.id(), equalTo(expected.id()));
9696
assertThat(actual.status(), equalTo(expected.status()));

0 commit comments

Comments
 (0)