Skip to content

Commit e4111fa

Browse files
committed
Remove legacyValue
1 parent 6320511 commit e4111fa

File tree

10 files changed

+42
-97
lines changed

10 files changed

+42
-97
lines changed

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@ record StatsCounter(LongAdder operations, LongAdder requests) {
744744
}
745745

746746
EndpointStats getEndpointStats() {
747-
return new EndpointStats(operations.sum(), requests.sum(), operations.sum());
747+
return new EndpointStats(operations.sum(), requests.sum());
748748
}
749749

750750
EndpointStats addTo(EndpointStats other) {
751751
long ops = operations.sum() + other.operations();
752752
long reqs = requests.sum() + other.requests();
753-
return new EndpointStats(ops, reqs, ops);
753+
return new EndpointStats(ops, reqs);
754754
}
755755
}
756756

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageOperationsStats.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ String getTrackedBucket() {
5151
Map<String, EndpointStats> toMap() {
5252
final Map<String, EndpointStats> results = new HashMap<>();
5353
final long getOperations = getCount.get();
54-
results.put("GetObject", new EndpointStats(getOperations, getOperations, getOperations));
54+
results.put("GetObject", new EndpointStats(getOperations, getOperations));
5555
final long listOperations = listCount.get();
56-
results.put("ListObjects", new EndpointStats(listOperations, listOperations, listOperations));
56+
results.put("ListObjects", new EndpointStats(listOperations, listOperations));
5757
final long insertOperations = postCount.get() + putCount.get();
58-
results.put("InsertObject", new EndpointStats(insertOperations, insertOperations, insertOperations));
58+
results.put("InsertObject", new EndpointStats(insertOperations, insertOperations));
5959
return results;
6060
}
6161
}

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private IgnoreNoResponseMetricsCollector(Operation operation, OperationPurpose p
158158
}
159159

160160
EndpointStats getEndpointStats() {
161-
return new EndpointStats(operations.sum(), requests.sum(), requests.sum());
161+
return new EndpointStats(operations.sum(), requests.sum());
162162
}
163163

164164
@Override

server/src/main/java/org/elasticsearch/common/blobstore/EndpointStats.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,51 @@
2323
*
2424
* @param operations The number of calls
2525
* @param requests The number of calls (including retries)
26-
* @param legacyValue The number used before the migration to separate counts (sometimes operations, sometimes requests, for temporary BWC)
2726
*/
28-
public record EndpointStats(long operations, long requests, long legacyValue) implements Writeable, ToXContentObject {
27+
public record EndpointStats(long operations, long requests) implements Writeable, ToXContentObject {
2928

30-
public static EndpointStats ZERO = new EndpointStats(0, 0, 0);
31-
32-
public EndpointStats(long legacyValue) {
33-
this(-1, -1, legacyValue);
34-
}
29+
public static EndpointStats ZERO = new EndpointStats(0, 0);
3530

3631
public EndpointStats(StreamInput in) throws IOException {
37-
this(in.readLong(), in.readLong(), in.readLong());
32+
this(in.readLong(), in.readLong());
3833
}
3934

4035
public EndpointStats {
41-
assert legacyValue >= 0 && ((operations == -1 && requests == -1) || (operations >= 0 && requests >= 0));
36+
assert operations >= 0 && requests >= 0;
4237
}
4338

4439
@Override
4540
public void writeTo(StreamOutput out) throws IOException {
4641
out.writeLong(operations);
4742
out.writeLong(requests);
48-
out.writeLong(legacyValue);
49-
}
50-
51-
public boolean isLegacyStats() {
52-
return operations == -1 && requests == -1;
5343
}
5444

5545
public EndpointStats add(EndpointStats other) {
56-
if (isLegacyStats() || other.isLegacyStats()) {
57-
return new EndpointStats(Math.addExact(legacyValue, other.legacyValue));
58-
} else {
59-
return new EndpointStats(
60-
Math.addExact(operations, other.operations),
61-
Math.addExact(requests, other.requests),
62-
Math.addExact(legacyValue, other.legacyValue)
63-
);
64-
}
46+
return new EndpointStats(Math.addExact(operations, other.operations), Math.addExact(requests, other.requests));
6547
}
6648

6749
public boolean isZero() {
68-
return (isLegacyStats() && legacyValue == 0) || (operations == 0 && requests == 0 && legacyValue == 0);
50+
return operations == 0 && requests == 0;
6951
}
7052

7153
@Override
7254
public boolean equals(Object o) {
7355
if (o instanceof EndpointStats other) {
74-
return requests == other.requests && operations == other.operations && legacyValue == other.legacyValue;
56+
return requests == other.requests && operations == other.operations;
7557
}
7658
return false;
7759
}
7860

7961
@Override
8062
public int hashCode() {
81-
return Objects.hash(operations, requests, legacyValue);
63+
return Objects.hash(operations, requests);
8264
}
8365

8466
@Override
8567
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
8668
builder.startObject();
87-
if (isLegacyStats() == false) {
88-
builder.field("operations", operations);
89-
builder.field("requests", requests);
90-
}
69+
builder.field("operations", operations);
70+
builder.field("requests", requests);
9171
builder.endObject();
9272
return builder;
9373
}

server/src/main/java/org/elasticsearch/repositories/RepositoryStats.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public RepositoryStats(StreamInput in) throws IOException {
3535
if (in.getTransportVersion().onOrAfter(TransportVersions.RETRIES_AND_OPERATIONS_IN_BLOBSTORE_STATS)) {
3636
this.requestCounts = in.readMap(EndpointStats::new);
3737
} else {
38-
this.requestCounts = in.readMap(si -> new EndpointStats(in.readLong()));
38+
this.requestCounts = in.readMap(si -> {
39+
long legacyValue = in.readLong();
40+
return new EndpointStats(legacyValue, legacyValue);
41+
});
3942
}
4043
}
4144

@@ -53,7 +56,7 @@ public void writeTo(StreamOutput out) throws IOException {
5356
if (out.getTransportVersion().onOrAfter(TransportVersions.RETRIES_AND_OPERATIONS_IN_BLOBSTORE_STATS)) {
5457
out.writeMap(requestCounts, (so, v) -> v.writeTo(so));
5558
} else {
56-
out.writeMap(requestCounts, (so, v) -> so.writeLong(v.legacyValue()));
59+
out.writeMap(requestCounts, (so, v) -> so.writeLong(v.requests()));
5760
}
5861
}
5962

server/src/main/java/org/elasticsearch/repositories/RepositoryStatsSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
7474
builder.startObject("request_counts");
7575
for (Map.Entry<String, EndpointStats> entry : repositoryStats.requestCounts.entrySet()) {
7676
final EndpointStats stats = entry.getValue();
77-
builder.field(entry.getKey(), stats.isLegacyStats() ? stats.legacyValue() : stats.operations());
77+
builder.field(entry.getKey(), stats.operations());
7878
}
7979
builder.endObject();
8080
builder.field("archived", archived);

server/src/test/java/org/elasticsearch/common/blobstore/EndpointStatsTests.java

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,47 @@
1414
public class EndpointStatsTests extends ESTestCase {
1515

1616
public void testEquals() {
17-
EndpointStats expected = randomEndpointStats(false);
18-
assertEquals(expected, new EndpointStats(expected.operations(), expected.requests(), expected.legacyValue()));
17+
EndpointStats expected = randomEndpointStats();
18+
assertEquals(expected, new EndpointStats(expected.operations(), expected.requests()));
1919
assertNotEquals(
2020
expected,
21-
new EndpointStats(
22-
randomValueOtherThan(expected.operations(), ESTestCase::randomNonNegativeLong),
23-
expected.requests(),
24-
expected.legacyValue()
25-
)
21+
new EndpointStats(randomValueOtherThan(expected.operations(), ESTestCase::randomNonNegativeLong), expected.requests())
2622
);
2723
assertNotEquals(
2824
expected,
29-
new EndpointStats(
30-
expected.operations(),
31-
randomValueOtherThan(expected.requests(), ESTestCase::randomNonNegativeLong),
32-
expected.legacyValue()
33-
)
34-
);
35-
assertNotEquals(
36-
expected,
37-
new EndpointStats(
38-
expected.operations(),
39-
expected.requests(),
40-
randomValueOtherThan(expected.legacyValue(), ESTestCase::randomNonNegativeLong)
41-
)
25+
new EndpointStats(expected.operations(), randomValueOtherThan(expected.requests(), ESTestCase::randomNonNegativeLong))
4226
);
4327
}
4428

4529
public void testAdd() {
46-
final EndpointStats lhs = randomEndpointStats(false, 1 << 30);
47-
final EndpointStats rhs = randomEndpointStats(false, 1 << 30);
30+
final EndpointStats lhs = randomEndpointStats(1 << 30);
31+
final EndpointStats rhs = randomEndpointStats(1 << 30);
4832
final EndpointStats result = lhs.add(rhs);
4933
assertEquals(lhs.operations() + rhs.operations(), result.operations());
5034
assertEquals(lhs.requests() + rhs.requests(), result.requests());
51-
assertEquals(lhs.legacyValue() + rhs.legacyValue(), result.legacyValue());
5235
}
5336

5437
public void testAddOverflow() {
55-
final EndpointStats lhs = new EndpointStats(
56-
randomLongBetween(50, 1 << 30),
57-
randomLongBetween(50, 1 << 30),
58-
randomLongBetween(50, 1 << 30)
59-
);
38+
final EndpointStats lhs = new EndpointStats(randomLongBetween(50, 1 << 30), randomLongBetween(50, 1 << 30));
6039
final int fieldToOverflow = randomIntBetween(0, 2);
6140
final EndpointStats rhs = new EndpointStats(
6241
fieldToOverflow == 0 ? (Long.MAX_VALUE - lhs.operations()) + 1 : 1,
63-
fieldToOverflow == 1 ? (Long.MAX_VALUE - lhs.requests()) + 1 : 1,
64-
fieldToOverflow == 2 ? (Long.MAX_VALUE - lhs.legacyValue()) + 1 : 1
42+
fieldToOverflow == 1 ? (Long.MAX_VALUE - lhs.requests()) + 1 : 1
6543
);
6644
assertThrows(ArithmeticException.class, () -> lhs.add(rhs));
6745
}
6846

69-
public void testAddLegacy() {
70-
final EndpointStats nonLegacy = randomEndpointStats(false, 1 << 30);
71-
final EndpointStats legacy = randomEndpointStats(true, 1 << 30);
72-
final EndpointStats result = nonLegacy.add(legacy);
73-
assertTrue(result.isLegacyStats());
74-
assertEquals(nonLegacy.legacyValue() + legacy.legacyValue(), result.legacyValue());
75-
}
76-
7747
public void testIsZero() {
78-
assertTrue(new EndpointStats(0).isZero());
79-
assertFalse(new EndpointStats(randomLongBetween(1, Long.MAX_VALUE)).isZero());
80-
81-
assertTrue(new EndpointStats(0, 0, 0).isZero());
82-
assertFalse(new EndpointStats(randomLongBetween(1, Long.MAX_VALUE), 0, 0).isZero());
83-
assertFalse(new EndpointStats(0, randomLongBetween(1, Long.MAX_VALUE), 0).isZero());
84-
assertFalse(new EndpointStats(0, 0, randomLongBetween(1, Long.MAX_VALUE)).isZero());
48+
assertTrue(new EndpointStats(0, 0).isZero());
49+
assertFalse(new EndpointStats(randomLongBetween(1, Long.MAX_VALUE), 0).isZero());
50+
assertFalse(new EndpointStats(0, randomLongBetween(1, Long.MAX_VALUE)).isZero());
8551
}
8652

87-
private EndpointStats randomEndpointStats(boolean legacy) {
88-
return randomEndpointStats(legacy, Long.MAX_VALUE);
53+
private EndpointStats randomEndpointStats() {
54+
return randomEndpointStats(Long.MAX_VALUE);
8955
}
9056

91-
private EndpointStats randomEndpointStats(boolean legacy, long upperBound) {
92-
if (legacy) {
93-
return new EndpointStats(randomLongBetween(0, upperBound));
94-
} else {
95-
return new EndpointStats(randomLongBetween(0, upperBound), randomLongBetween(0, upperBound), randomLongBetween(0, upperBound));
96-
}
57+
private EndpointStats randomEndpointStats(long upperBound) {
58+
return new EndpointStats(randomLongBetween(0, upperBound), randomLongBetween(0, upperBound));
9759
}
9860
}

server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public String startVerification() {
580580

581581
private static class MeteredRepositoryTypeA extends MeteredBlobStoreRepository {
582582
private static final String TYPE = "type-a";
583-
private static final RepositoryStats STATS = new RepositoryStats(Map.of("GET", new EndpointStats(10, 13, 13)));
583+
private static final RepositoryStats STATS = new RepositoryStats(Map.of("GET", new EndpointStats(10, 13)));
584584

585585
private MeteredRepositoryTypeA(RepositoryMetadata metadata, ClusterService clusterService) {
586586
super(
@@ -607,7 +607,7 @@ public RepositoryStats stats() {
607607

608608
private static class MeteredRepositoryTypeB extends MeteredBlobStoreRepository {
609609
private static final String TYPE = "type-b";
610-
private static final RepositoryStats STATS = new RepositoryStats(Map.of("LIST", new EndpointStats(20, 25, 25)));
610+
private static final RepositoryStats STATS = new RepositoryStats(Map.of("LIST", new EndpointStats(20, 25)));
611611

612612
private MeteredRepositoryTypeB(RepositoryMetadata metadata, ClusterService clusterService) {
613613
super(

server/src/test/java/org/elasticsearch/repositories/RepositoriesStatsArchiveTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public void testStatsAreEvictedOnceTheyAreOlderThanRetentionPeriod() {
3939
fakeRelativeClock.set(retentionTimeInMillis * 2);
4040
int statsToBeRetainedCount = randomInt(10);
4141
for (int i = 0; i < statsToBeRetainedCount; i++) {
42-
RepositoryStatsSnapshot repoStats = createRepositoryStats(new RepositoryStats(Map.of("GET", new EndpointStats(10, 13, 13))));
42+
RepositoryStatsSnapshot repoStats = createRepositoryStats(new RepositoryStats(Map.of("GET", new EndpointStats(10, 13))));
4343
repositoriesStatsArchive.archive(repoStats);
4444
}
4545

4646
List<RepositoryStatsSnapshot> archivedStats = repositoriesStatsArchive.getArchivedStats();
4747
assertThat(archivedStats.size(), equalTo(statsToBeRetainedCount));
4848
for (RepositoryStatsSnapshot repositoryStatsSnapshot : archivedStats) {
49-
assertThat(repositoryStatsSnapshot.getRepositoryStats().requestCounts, equalTo(Map.of("GET", new EndpointStats(10, 13, 13))));
49+
assertThat(repositoryStatsSnapshot.getRepositoryStats().requestCounts, equalTo(Map.of("GET", new EndpointStats(10, 13))));
5050
}
5151
}
5252

x-pack/plugin/repositories-metering-api/src/test/java/org/elasticsearch/xpack/repositories/metering/AbstractRepositoriesMeteringAPIRestTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private List<RepositoryStatsSnapshot> parseRepositoriesStatsResponse(Map<String,
328328
.collect(Collectors.toMap(Map.Entry::getKey, e -> {
329329
long operationCount = e.getValue().longValue();
330330
// The API is lossy, we don't get back operations/requests, so we'll assume they're all the same
331-
return new EndpointStats(operationCount, operationCount, operationCount);
331+
return new EndpointStats(operationCount, operationCount);
332332
}));
333333
RepositoryStats repositoryStats = new RepositoryStats(requestCounters);
334334
RepositoryStatsSnapshot statsSnapshot = new RepositoryStatsSnapshot(

0 commit comments

Comments
 (0)