Skip to content

Commit 0098c2e

Browse files
Likepgomulka
authored andcommitted
Migrate Streamable to writeable for index package (#37381)
Migrate streamable classes from index package to Writeable and clean up access modifiers Related to #34389
1 parent 3a76c30 commit 0098c2e

File tree

22 files changed

+262
-224
lines changed

22 files changed

+262
-224
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStats.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,22 @@ public CommonStats(IndicesQueryCache indicesQueryCache, IndexShard indexShard, C
228228
}
229229

230230
public CommonStats(StreamInput in) throws IOException {
231-
docs = in.readOptionalStreamable(DocsStats::new);
232-
store = in.readOptionalStreamable(StoreStats::new);
233-
indexing = in.readOptionalStreamable(IndexingStats::new);
234-
get = in.readOptionalStreamable(GetStats::new);
231+
docs = in.readOptionalWriteable(DocsStats::new);
232+
store = in.readOptionalWriteable(StoreStats::new);
233+
indexing = in.readOptionalWriteable(IndexingStats::new);
234+
get = in.readOptionalWriteable(GetStats::new);
235235
search = in.readOptionalWriteable(SearchStats::new);
236-
merge = in.readOptionalStreamable(MergeStats::new);
237-
refresh = in.readOptionalStreamable(RefreshStats::new);
238-
flush = in.readOptionalStreamable(FlushStats::new);
239-
warmer = in.readOptionalStreamable(WarmerStats::new);
240-
queryCache = in.readOptionalStreamable(QueryCacheStats::new);
241-
fieldData = in.readOptionalStreamable(FieldDataStats::new);
242-
completion = in.readOptionalStreamable(CompletionStats::new);
243-
segments = in.readOptionalStreamable(SegmentsStats::new);
244-
translog = in.readOptionalStreamable(TranslogStats::new);
245-
requestCache = in.readOptionalStreamable(RequestCacheStats::new);
246-
recoveryStats = in.readOptionalStreamable(RecoveryStats::new);
236+
merge = in.readOptionalWriteable(MergeStats::new);
237+
refresh = in.readOptionalWriteable(RefreshStats::new);
238+
flush = in.readOptionalWriteable(FlushStats::new);
239+
warmer = in.readOptionalWriteable(WarmerStats::new);
240+
queryCache = in.readOptionalWriteable(QueryCacheStats::new);
241+
fieldData = in.readOptionalWriteable(FieldDataStats::new);
242+
completion = in.readOptionalWriteable(CompletionStats::new);
243+
segments = in.readOptionalWriteable(SegmentsStats::new);
244+
translog = in.readOptionalWriteable(TranslogStats::new);
245+
requestCache = in.readOptionalWriteable(RequestCacheStats::new);
246+
recoveryStats = in.readOptionalWriteable(RecoveryStats::new);
247247
}
248248

249249
@Override

server/src/main/java/org/elasticsearch/index/cache/query/QueryCacheStats.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,33 @@
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
2525
import org.elasticsearch.common.io.stream.Streamable;
26+
import org.elasticsearch.common.io.stream.Writeable;
2627
import org.elasticsearch.common.unit.ByteSizeValue;
2728
import org.elasticsearch.common.xcontent.ToXContent;
2829
import org.elasticsearch.common.xcontent.ToXContentFragment;
2930
import org.elasticsearch.common.xcontent.XContentBuilder;
3031

3132
import java.io.IOException;
3233

33-
public class QueryCacheStats implements Streamable, ToXContentFragment {
34+
public class QueryCacheStats implements Streamable, Writeable, ToXContentFragment {
3435

35-
long ramBytesUsed;
36-
long hitCount;
37-
long missCount;
38-
long cacheCount;
39-
long cacheSize;
36+
private long ramBytesUsed;
37+
private long hitCount;
38+
private long missCount;
39+
private long cacheCount;
40+
private long cacheSize;
4041

4142
public QueryCacheStats() {
4243
}
4344

45+
public QueryCacheStats(StreamInput in) throws IOException {
46+
ramBytesUsed = in.readLong();
47+
hitCount = in.readLong();
48+
missCount = in.readLong();
49+
cacheCount = in.readLong();
50+
cacheSize = in.readLong();
51+
}
52+
4453
public QueryCacheStats(long ramBytesUsed, long hitCount, long missCount, long cacheCount, long cacheSize) {
4554
this.ramBytesUsed = ramBytesUsed;
4655
this.hitCount = hitCount;
@@ -109,11 +118,7 @@ public long getEvictions() {
109118

110119
@Override
111120
public void readFrom(StreamInput in) throws IOException {
112-
ramBytesUsed = in.readLong();
113-
hitCount = in.readLong();
114-
missCount = in.readLong();
115-
cacheCount = in.readLong();
116-
cacheSize = in.readLong();
121+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
117122
}
118123

119124
@Override

server/src/main/java/org/elasticsearch/index/cache/request/RequestCacheStats.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,30 @@
2222
import org.elasticsearch.common.io.stream.StreamInput;
2323
import org.elasticsearch.common.io.stream.StreamOutput;
2424
import org.elasticsearch.common.io.stream.Streamable;
25+
import org.elasticsearch.common.io.stream.Writeable;
2526
import org.elasticsearch.common.unit.ByteSizeValue;
26-
import org.elasticsearch.common.xcontent.ToXContent.Params;
2727
import org.elasticsearch.common.xcontent.ToXContentFragment;
2828
import org.elasticsearch.common.xcontent.XContentBuilder;
2929

3030
import java.io.IOException;
3131

32-
public class RequestCacheStats implements Streamable, ToXContentFragment {
32+
public class RequestCacheStats implements Streamable, Writeable, ToXContentFragment {
3333

34-
long memorySize;
35-
long evictions;
36-
long hitCount;
37-
long missCount;
34+
private long memorySize;
35+
private long evictions;
36+
private long hitCount;
37+
private long missCount;
3838

3939
public RequestCacheStats() {
4040
}
4141

42+
public RequestCacheStats(StreamInput in) throws IOException {
43+
memorySize = in.readVLong();
44+
evictions = in.readVLong();
45+
hitCount = in.readVLong();
46+
missCount = in.readVLong();
47+
}
48+
4249
public RequestCacheStats(long memorySize, long evictions, long hitCount, long missCount) {
4350
this.memorySize = memorySize;
4451
this.evictions = evictions;
@@ -75,10 +82,7 @@ public long getMissCount() {
7582

7683
@Override
7784
public void readFrom(StreamInput in) throws IOException {
78-
memorySize = in.readVLong();
79-
evictions = in.readVLong();
80-
hitCount = in.readVLong();
81-
missCount = in.readVLong();
85+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
8286
}
8387

8488
@Override

server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@
2020
package org.elasticsearch.index.engine;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
23-
2423
import org.elasticsearch.common.collect.ImmutableOpenMap;
2524
import org.elasticsearch.common.io.stream.StreamInput;
2625
import org.elasticsearch.common.io.stream.StreamOutput;
2726
import org.elasticsearch.common.io.stream.Streamable;
27+
import org.elasticsearch.common.io.stream.Writeable;
2828
import org.elasticsearch.common.unit.ByteSizeValue;
29-
import org.elasticsearch.common.xcontent.ToXContent.Params;
3029
import org.elasticsearch.common.xcontent.ToXContentFragment;
3130
import org.elasticsearch.common.xcontent.XContentBuilder;
3231

3332
import java.io.IOException;
3433
import java.util.Iterator;
3534

36-
public class SegmentsStats implements Streamable, ToXContentFragment {
35+
public class SegmentsStats implements Streamable, Writeable, ToXContentFragment {
3736

3837
private long count;
3938
private long memoryInBytes;
@@ -79,6 +78,30 @@ public class SegmentsStats implements Streamable, ToXContentFragment {
7978

8079
public SegmentsStats() {}
8180

81+
public SegmentsStats(StreamInput in) throws IOException {
82+
count = in.readVLong();
83+
memoryInBytes = in.readLong();
84+
termsMemoryInBytes = in.readLong();
85+
storedFieldsMemoryInBytes = in.readLong();
86+
termVectorsMemoryInBytes = in.readLong();
87+
normsMemoryInBytes = in.readLong();
88+
pointsMemoryInBytes = in.readLong();
89+
docValuesMemoryInBytes = in.readLong();
90+
indexWriterMemoryInBytes = in.readLong();
91+
versionMapMemoryInBytes = in.readLong();
92+
bitsetMemoryInBytes = in.readLong();
93+
maxUnsafeAutoIdTimestamp = in.readLong();
94+
95+
int size = in.readVInt();
96+
ImmutableOpenMap.Builder<String, Long> map = ImmutableOpenMap.builder(size);
97+
for (int i = 0; i < size; i++) {
98+
String key = in.readString();
99+
Long value = in.readLong();
100+
map.put(key, value);
101+
}
102+
fileSizes = map.build();
103+
}
104+
82105
public void add(long count, long memoryInBytes) {
83106
this.count += count;
84107
this.memoryInBytes += memoryInBytes;
@@ -347,27 +370,7 @@ static final class Fields {
347370

348371
@Override
349372
public void readFrom(StreamInput in) throws IOException {
350-
count = in.readVLong();
351-
memoryInBytes = in.readLong();
352-
termsMemoryInBytes = in.readLong();
353-
storedFieldsMemoryInBytes = in.readLong();
354-
termVectorsMemoryInBytes = in.readLong();
355-
normsMemoryInBytes = in.readLong();
356-
pointsMemoryInBytes = in.readLong();
357-
docValuesMemoryInBytes = in.readLong();
358-
indexWriterMemoryInBytes = in.readLong();
359-
versionMapMemoryInBytes = in.readLong();
360-
bitsetMemoryInBytes = in.readLong();
361-
maxUnsafeAutoIdTimestamp = in.readLong();
362-
363-
int size = in.readVInt();
364-
ImmutableOpenMap.Builder<String, Long> map = ImmutableOpenMap.builder(size);
365-
for (int i = 0; i < size; i++) {
366-
String key = in.readString();
367-
Long value = in.readLong();
368-
map.put(key, value);
369-
}
370-
fileSizes = map.build();
373+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
371374
}
372375

373376
@Override

server/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,36 @@
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.unit.ByteSizeValue;
2829
import org.elasticsearch.common.xcontent.ToXContentFragment;
2930
import org.elasticsearch.common.xcontent.XContentBuilder;
3031

3132
import java.io.IOException;
3233
import java.util.Objects;
3334

34-
public class FieldDataStats implements Streamable, ToXContentFragment {
35+
public class FieldDataStats implements Streamable, Writeable, ToXContentFragment {
3536

3637
private static final String FIELDDATA = "fielddata";
3738
private static final String MEMORY_SIZE = "memory_size";
3839
private static final String MEMORY_SIZE_IN_BYTES = "memory_size_in_bytes";
3940
private static final String EVICTIONS = "evictions";
4041
private static final String FIELDS = "fields";
41-
long memorySize;
42-
long evictions;
42+
private long memorySize;
43+
private long evictions;
4344
@Nullable
44-
FieldMemoryStats fields;
45+
private FieldMemoryStats fields;
4546

4647
public FieldDataStats() {
4748

4849
}
4950

51+
public FieldDataStats(StreamInput in) throws IOException {
52+
memorySize = in.readVLong();
53+
evictions = in.readVLong();
54+
fields = in.readOptionalWriteable(FieldMemoryStats::new);
55+
}
56+
5057
public FieldDataStats(long memorySize, long evictions, @Nullable FieldMemoryStats fields) {
5158
this.memorySize = memorySize;
5259
this.evictions = evictions;
@@ -84,9 +91,7 @@ public FieldMemoryStats getFields() {
8491

8592
@Override
8693
public void readFrom(StreamInput in) throws IOException {
87-
memorySize = in.readVLong();
88-
evictions = in.readVLong();
89-
fields = in.readOptionalWriteable(FieldMemoryStats::new);
94+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
9095
}
9196

9297
@Override

server/src/main/java/org/elasticsearch/index/flush/FlushStats.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
2525
import org.elasticsearch.common.io.stream.Streamable;
26+
import org.elasticsearch.common.io.stream.Writeable;
2627
import org.elasticsearch.common.unit.TimeValue;
2728
import org.elasticsearch.common.xcontent.ToXContentFragment;
2829
import org.elasticsearch.common.xcontent.XContentBuilder;
2930

3031
import java.io.IOException;
3132

32-
public class FlushStats implements Streamable, ToXContentFragment {
33+
public class FlushStats implements Streamable, Writeable, ToXContentFragment {
3334

3435
private long total;
3536
private long periodic;
@@ -39,6 +40,14 @@ public FlushStats() {
3940

4041
}
4142

43+
public FlushStats(StreamInput in) throws IOException {
44+
total = in.readVLong();
45+
totalTimeInMillis = in.readVLong();
46+
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
47+
periodic = in.readVLong();
48+
}
49+
}
50+
4251
public FlushStats(long total, long periodic, long totalTimeInMillis) {
4352
this.total = total;
4453
this.periodic = periodic;
@@ -112,11 +121,7 @@ static final class Fields {
112121

113122
@Override
114123
public void readFrom(StreamInput in) throws IOException {
115-
total = in.readVLong();
116-
totalTimeInMillis = in.readVLong();
117-
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
118-
periodic = in.readVLong();
119-
}
124+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
120125
}
121126

122127
@Override

server/src/main/java/org/elasticsearch/index/get/GetStats.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
import org.elasticsearch.common.io.stream.StreamInput;
2323
import org.elasticsearch.common.io.stream.StreamOutput;
2424
import org.elasticsearch.common.io.stream.Streamable;
25+
import org.elasticsearch.common.io.stream.Writeable;
2526
import org.elasticsearch.common.unit.TimeValue;
2627
import org.elasticsearch.common.xcontent.ToXContentFragment;
2728
import org.elasticsearch.common.xcontent.XContentBuilder;
2829

2930
import java.io.IOException;
3031

31-
public class GetStats implements Streamable, ToXContentFragment {
32+
public class GetStats implements Streamable, Writeable, ToXContentFragment {
3233

3334
private long existsCount;
3435
private long existsTimeInMillis;
@@ -39,6 +40,14 @@ public class GetStats implements Streamable, ToXContentFragment {
3940
public GetStats() {
4041
}
4142

43+
public GetStats(StreamInput in) throws IOException {
44+
existsCount = in.readVLong();
45+
existsTimeInMillis = in.readVLong();
46+
missingCount = in.readVLong();
47+
missingTimeInMillis = in.readVLong();
48+
current = in.readVLong();
49+
}
50+
4251
public GetStats(long existsCount, long existsTimeInMillis, long missingCount, long missingTimeInMillis, long current) {
4352
this.existsCount = existsCount;
4453
this.existsTimeInMillis = existsTimeInMillis;
@@ -136,11 +145,7 @@ static final class Fields {
136145

137146
@Override
138147
public void readFrom(StreamInput in) throws IOException {
139-
existsCount = in.readVLong();
140-
existsTimeInMillis = in.readVLong();
141-
missingCount = in.readVLong();
142-
missingTimeInMillis = in.readVLong();
143-
current = in.readVLong();
148+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
144149
}
145150

146151
@Override

0 commit comments

Comments
 (0)