forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplicationStats.java
101 lines (84 loc) · 3.13 KB
/
ReplicationStats.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.index;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import java.io.IOException;
/**
* ReplicationStats is used to provide segment replication statistics at an index,
* node and cluster level on a segment replication enabled cluster.
*
* @opensearch.api
*/
@PublicApi(since = "2.10.0")
public class ReplicationStats implements ToXContentFragment, Writeable {
public long maxBytesBehind;
public long maxReplicationLag;
public long totalBytesBehind;
public ReplicationStats(long maxBytesBehind, long totalBytesBehind, long maxReplicationLag) {
this.maxBytesBehind = maxBytesBehind;
this.totalBytesBehind = totalBytesBehind;
this.maxReplicationLag = maxReplicationLag;
}
public ReplicationStats(StreamInput in) throws IOException {
this.maxBytesBehind = in.readVLong();
this.totalBytesBehind = in.readVLong();
this.maxReplicationLag = in.readVLong();
}
public static ReplicationStats empty() {
return new ReplicationStats();
}
public ReplicationStats() {
}
public void add(ReplicationStats other) {
if (other != null) {
maxBytesBehind = Math.max(other.maxBytesBehind, maxBytesBehind);
totalBytesBehind += other.totalBytesBehind;
maxReplicationLag = Math.max(other.maxReplicationLag, maxReplicationLag);
}
}
public long getMaxBytesBehind() {
return this.maxBytesBehind;
}
public long getTotalBytesBehind() {
return this.totalBytesBehind;
}
public long getMaxReplicationLag() {
return this.maxReplicationLag;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(maxBytesBehind);
out.writeVLong(totalBytesBehind);
out.writeVLong(maxReplicationLag);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.SEGMENT_REPLICATION);
builder.field(Fields.MAX_BYTES_BEHIND, maxBytesBehind);
builder.field(Fields.TOTAL_BYTES_BEHIND, totalBytesBehind);
builder.field(Fields.MAX_REPLICATION_LAG, maxReplicationLag);
builder.endObject();
return builder;
}
/**
* Fields for segment replication statistics
*
* @opensearch.internal
*/
static final class Fields {
static final String SEGMENT_REPLICATION = "segment_replication";
static final String MAX_BYTES_BEHIND = "max_bytes_behind";
static final String TOTAL_BYTES_BEHIND = "total_bytes_behind";
static final String MAX_REPLICATION_LAG = "max_replication_lag";
}
}