Skip to content

Commit 23828cf

Browse files
authored
Convert direct implementations of Streamable to Writeable (#44605)
This commit converts Streamable to Writeable for direct implementations. relates #34389
1 parent 187dc5a commit 23828cf

File tree

31 files changed

+211
-512
lines changed

31 files changed

+211
-512
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcStreamableXContentTestCase.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.elasticsearch.common.bytes.BytesReference;
2525
import org.elasticsearch.common.io.stream.BytesStreamOutput;
2626
import org.elasticsearch.common.io.stream.StreamInput;
27-
import org.elasticsearch.common.io.stream.Streamable;
27+
import org.elasticsearch.common.io.stream.Writeable;
2828
import org.elasticsearch.common.lucene.uid.Versions;
2929
import org.elasticsearch.common.unit.TimeValue;
3030
import org.elasticsearch.script.Script;
@@ -175,11 +175,11 @@ public void testRethrottleRequest() throws IOException {
175175
assertEquals(request.getTaskId(), tripped.getTaskId());
176176
}
177177

178-
private StreamInput toInputByteStream(Streamable example) throws IOException {
178+
private StreamInput toInputByteStream(Writeable example) throws IOException {
179179
return toInputByteStream(Version.CURRENT, example);
180180
}
181181

182-
private StreamInput toInputByteStream(Version version, Streamable example) throws IOException {
182+
private StreamInput toInputByteStream(Version version, Writeable example) throws IOException {
183183
BytesStreamOutput out = new BytesStreamOutput();
184184
out.setVersion(version);
185185
example.writeTo(out);

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void writeTo(StreamOutput out) throws IOException {
147147
public void readFrom(StreamInput in) throws IOException {
148148
super.readFrom(in);
149149
stage = SnapshotIndexShardStage.fromValue(in.readByte());
150-
stats = SnapshotStats.readSnapshotStats(in);
150+
stats = new SnapshotStats(in);
151151
nodeId = in.readOptionalString();
152152
failure = in.readOptionalString();
153153
}

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.elasticsearch.common.io.stream.StreamInput;
2323
import org.elasticsearch.common.io.stream.StreamOutput;
24-
import org.elasticsearch.common.io.stream.Streamable;
24+
import org.elasticsearch.common.io.stream.Writeable;
2525
import org.elasticsearch.common.unit.ByteSizeValue;
2626
import org.elasticsearch.common.unit.TimeValue;
2727
import org.elasticsearch.common.xcontent.ToXContent;
@@ -32,7 +32,7 @@
3232

3333
import java.io.IOException;
3434

35-
public class SnapshotStats implements Streamable, ToXContentObject {
35+
public class SnapshotStats implements Writeable, ToXContentObject {
3636

3737
private long startTime;
3838
private long time;
@@ -43,7 +43,20 @@ public class SnapshotStats implements Streamable, ToXContentObject {
4343
private long totalSize;
4444
private long processedSize;
4545

46-
SnapshotStats() {
46+
SnapshotStats() {}
47+
48+
SnapshotStats(StreamInput in) throws IOException {
49+
startTime = in.readVLong();
50+
time = in.readVLong();
51+
52+
incrementalFileCount = in.readVInt();
53+
processedFileCount = in.readVInt();
54+
55+
incrementalSize = in.readVLong();
56+
processedSize = in.readVLong();
57+
58+
totalFileCount = in.readVInt();
59+
totalSize = in.readVLong();
4760
}
4861

4962
SnapshotStats(long startTime, long time,
@@ -115,13 +128,6 @@ public long getProcessedSize() {
115128
return processedSize;
116129
}
117130

118-
119-
public static SnapshotStats readSnapshotStats(StreamInput in) throws IOException {
120-
SnapshotStats stats = new SnapshotStats();
121-
stats.readFrom(in);
122-
return stats;
123-
}
124-
125131
@Override
126132
public void writeTo(StreamOutput out) throws IOException {
127133
out.writeVLong(startTime);
@@ -137,21 +143,6 @@ public void writeTo(StreamOutput out) throws IOException {
137143
out.writeVLong(totalSize);
138144
}
139145

140-
@Override
141-
public void readFrom(StreamInput in) throws IOException {
142-
startTime = in.readVLong();
143-
time = in.readVLong();
144-
145-
incrementalFileCount = in.readVInt();
146-
processedFileCount = in.readVInt();
147-
148-
incrementalSize = in.readVLong();
149-
processedSize = in.readVLong();
150-
151-
totalFileCount = in.readVInt();
152-
totalSize = in.readVLong();
153-
}
154-
155146
static final class Fields {
156147
static final String STATS = "stats";
157148

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.elasticsearch.common.Strings;
2828
import org.elasticsearch.common.io.stream.StreamInput;
2929
import org.elasticsearch.common.io.stream.StreamOutput;
30-
import org.elasticsearch.common.io.stream.Streamable;
30+
import org.elasticsearch.common.io.stream.Writeable;
3131
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
3232
import org.elasticsearch.common.xcontent.ObjectParser;
3333
import org.elasticsearch.common.xcontent.ToXContentObject;
@@ -55,7 +55,7 @@
5555
/**
5656
* Status of a snapshot
5757
*/
58-
public class SnapshotStatus implements ToXContentObject, Streamable {
58+
public class SnapshotStatus implements ToXContentObject, Writeable {
5959

6060
private Snapshot snapshot;
6161

@@ -72,6 +72,28 @@ public class SnapshotStatus implements ToXContentObject, Streamable {
7272
@Nullable
7373
private Boolean includeGlobalState;
7474

75+
SnapshotStatus(StreamInput in) throws IOException {
76+
snapshot = new Snapshot(in);
77+
state = State.fromValue(in.readByte());
78+
int size = in.readVInt();
79+
List<SnapshotIndexShardStatus> builder = new ArrayList<>();
80+
for (int i = 0; i < size; i++) {
81+
builder.add(SnapshotIndexShardStatus.readShardSnapshotStatus(in));
82+
}
83+
shards = Collections.unmodifiableList(builder);
84+
includeGlobalState = in.readOptionalBoolean();
85+
final long startTime;
86+
final long time;
87+
if (in.getVersion().onOrAfter(Version.V_7_4_0)) {
88+
startTime = in.readLong();
89+
time = in.readLong();
90+
} else {
91+
startTime = 0L;
92+
time = 0L;
93+
}
94+
updateShardStats(startTime, time);
95+
}
96+
7597
SnapshotStatus(Snapshot snapshot, State state, List<SnapshotIndexShardStatus> shards, Boolean includeGlobalState,
7698
long startTime, long time) {
7799
this.snapshot = Objects.requireNonNull(snapshot);
@@ -94,9 +116,6 @@ private SnapshotStatus(Snapshot snapshot, State state, List<SnapshotIndexShardSt
94116
this.includeGlobalState = includeGlobalState;
95117
}
96118

97-
SnapshotStatus() {
98-
}
99-
100119
/**
101120
* Returns snapshot
102121
*/
@@ -159,29 +178,6 @@ public Map<String, SnapshotIndexStatus> getIndices() {
159178

160179
}
161180

162-
@Override
163-
public void readFrom(StreamInput in) throws IOException {
164-
snapshot = new Snapshot(in);
165-
state = State.fromValue(in.readByte());
166-
int size = in.readVInt();
167-
List<SnapshotIndexShardStatus> builder = new ArrayList<>();
168-
for (int i = 0; i < size; i++) {
169-
builder.add(SnapshotIndexShardStatus.readShardSnapshotStatus(in));
170-
}
171-
shards = Collections.unmodifiableList(builder);
172-
includeGlobalState = in.readOptionalBoolean();
173-
final long startTime;
174-
final long time;
175-
if (in.getVersion().onOrAfter(Version.V_7_4_0)) {
176-
startTime = in.readLong();
177-
time = in.readLong();
178-
} else {
179-
startTime = 0L;
180-
time = 0L;
181-
}
182-
updateShardStats(startTime, time);
183-
}
184-
185181
@Override
186182
public void writeTo(StreamOutput out) throws IOException {
187183
snapshot.writeTo(out);
@@ -197,18 +193,6 @@ public void writeTo(StreamOutput out) throws IOException {
197193
}
198194
}
199195

200-
/**
201-
* Reads snapshot status from stream input
202-
*
203-
* @param in stream input
204-
* @return deserialized snapshot status
205-
*/
206-
public static SnapshotStatus readSnapshotStatus(StreamInput in) throws IOException {
207-
SnapshotStatus snapshotInfo = new SnapshotStatus();
208-
snapshotInfo.readFrom(in);
209-
return snapshotInfo;
210-
}
211-
212196
@Override
213197
public String toString() {
214198
return Strings.toString(this, true, false);

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public SnapshotsStatusResponse(StreamInput in) throws IOException {
4747
int size = in.readVInt();
4848
List<SnapshotStatus> builder = new ArrayList<>();
4949
for (int i = 0; i < size; i++) {
50-
builder.add(SnapshotStatus.readSnapshotStatus(in));
50+
builder.add(new SnapshotStatus(in));
5151
}
5252
snapshots = Collections.unmodifiableList(builder);
5353
}

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodeResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ClusterStatsNodeResponse(StreamInput in) throws IOException {
4949
int size = in.readVInt();
5050
shardsStats = new ShardStats[size];
5151
for (int i = 0; i < size; i++) {
52-
shardsStats[i] = ShardStats.readShardStats(in);
52+
shardsStats[i] = new ShardStats(in);
5353
}
5454
}
5555

server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.elasticsearch.common.bytes.BytesArray;
2727
import org.elasticsearch.common.io.stream.StreamInput;
2828
import org.elasticsearch.common.io.stream.StreamOutput;
29-
import org.elasticsearch.common.io.stream.Streamable;
29+
import org.elasticsearch.common.io.stream.Writeable;
3030
import org.elasticsearch.common.xcontent.ToXContent;
3131
import org.elasticsearch.common.xcontent.ToXContentFragment;
3232
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -42,7 +42,7 @@
4242
/**
4343
* Represents an alias, to be associated with an index
4444
*/
45-
public class Alias implements Streamable, ToXContentFragment {
45+
public class Alias implements Writeable, ToXContentFragment {
4646

4747
private static final ParseField FILTER = new ParseField("filter");
4848
private static final ParseField ROUTING = new ParseField("routing");
@@ -64,8 +64,12 @@ public class Alias implements Streamable, ToXContentFragment {
6464
@Nullable
6565
private Boolean writeIndex;
6666

67-
private Alias() {
68-
67+
public Alias(StreamInput in) throws IOException {
68+
name = in.readString();
69+
filter = in.readOptionalString();
70+
indexRouting = in.readOptionalString();
71+
searchRouting = in.readOptionalString();
72+
writeIndex = in.readOptionalBoolean();
6973
}
7074

7175
public Alias(String name) {
@@ -185,24 +189,6 @@ public Alias writeIndex(@Nullable Boolean writeIndex) {
185189
return this;
186190
}
187191

188-
/**
189-
* Allows to read an alias from the provided input stream
190-
*/
191-
public static Alias read(StreamInput in) throws IOException {
192-
Alias alias = new Alias();
193-
alias.readFrom(in);
194-
return alias;
195-
}
196-
197-
@Override
198-
public void readFrom(StreamInput in) throws IOException {
199-
name = in.readString();
200-
filter = in.readOptionalString();
201-
indexRouting = in.readOptionalString();
202-
searchRouting = in.readOptionalString();
203-
writeIndex = in.readOptionalBoolean();
204-
}
205-
206192
@Override
207193
public void writeTo(StreamOutput out) throws IOException {
208194
out.writeString(name);

server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public CreateIndexRequest(StreamInput in) throws IOException {
100100
}
101101
int aliasesSize = in.readVInt();
102102
for (int i = 0; i < aliasesSize; i++) {
103-
aliases.add(Alias.read(in));
103+
aliases.add(new Alias(in));
104104
}
105105
waitForActiveShards = ActiveShardCount.readFrom(in);
106106
}

0 commit comments

Comments
 (0)