-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathIndexingStats.java
306 lines (266 loc) · 9.97 KB
/
IndexingStats.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
* 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.
*/
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.index.shard;
import org.opensearch.Version;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.io.stream.Writeable;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.mapper.MapperService;
import java.io.IOException;
import java.util.Map;
/**
* Tracks indexing statistics
*
* @opensearch.internal
*/
public class IndexingStats implements Writeable, ToXContentFragment {
/**
* Internal statistics for indexing
*
* @opensearch.internal
*/
public static class Stats implements Writeable, ToXContentFragment {
private long indexCount;
private long indexTimeInMillis;
private long indexCurrent;
private long indexFailedCount;
private long deleteCount;
private long deleteTimeInMillis;
private long deleteCurrent;
private long noopUpdateCount;
private long throttleTimeInMillis;
private boolean isThrottled;
Stats() {}
public Stats(StreamInput in) throws IOException {
indexCount = in.readVLong();
indexTimeInMillis = in.readVLong();
indexCurrent = in.readVLong();
indexFailedCount = in.readVLong();
deleteCount = in.readVLong();
deleteTimeInMillis = in.readVLong();
deleteCurrent = in.readVLong();
noopUpdateCount = in.readVLong();
isThrottled = in.readBoolean();
throttleTimeInMillis = in.readLong();
}
public Stats(
long indexCount,
long indexTimeInMillis,
long indexCurrent,
long indexFailedCount,
long deleteCount,
long deleteTimeInMillis,
long deleteCurrent,
long noopUpdateCount,
boolean isThrottled,
long throttleTimeInMillis
) {
this.indexCount = indexCount;
this.indexTimeInMillis = indexTimeInMillis;
this.indexCurrent = indexCurrent;
this.indexFailedCount = indexFailedCount;
this.deleteCount = deleteCount;
this.deleteTimeInMillis = deleteTimeInMillis;
this.deleteCurrent = deleteCurrent;
this.noopUpdateCount = noopUpdateCount;
this.isThrottled = isThrottled;
this.throttleTimeInMillis = throttleTimeInMillis;
}
public void add(Stats stats) {
indexCount += stats.indexCount;
indexTimeInMillis += stats.indexTimeInMillis;
indexCurrent += stats.indexCurrent;
indexFailedCount += stats.indexFailedCount;
deleteCount += stats.deleteCount;
deleteTimeInMillis += stats.deleteTimeInMillis;
deleteCurrent += stats.deleteCurrent;
noopUpdateCount += stats.noopUpdateCount;
throttleTimeInMillis += stats.throttleTimeInMillis;
if (isThrottled != stats.isThrottled) {
isThrottled = true; // When combining if one is throttled set result to throttled.
}
}
/**
* The total number of indexing operations
*/
public long getIndexCount() {
return indexCount;
}
/**
* The number of failed indexing operations
*/
public long getIndexFailedCount() {
return indexFailedCount;
}
/**
* The total amount of time spend on executing index operations.
*/
public TimeValue getIndexTime() {
return new TimeValue(indexTimeInMillis);
}
/**
* Returns the currently in-flight indexing operations.
*/
public long getIndexCurrent() {
return indexCurrent;
}
/**
* Returns the number of delete operation executed
*/
public long getDeleteCount() {
return deleteCount;
}
/**
* Returns if the index is under merge throttling control
*/
public boolean isThrottled() {
return isThrottled;
}
/**
* Gets the amount of time in a TimeValue that the index has been under merge throttling control
*/
public TimeValue getThrottleTime() {
return new TimeValue(throttleTimeInMillis);
}
/**
* The total amount of time spend on executing delete operations.
*/
public TimeValue getDeleteTime() {
return new TimeValue(deleteTimeInMillis);
}
/**
* Returns the currently in-flight delete operations
*/
public long getDeleteCurrent() {
return deleteCurrent;
}
public long getNoopUpdateCount() {
return noopUpdateCount;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(indexCount);
out.writeVLong(indexTimeInMillis);
out.writeVLong(indexCurrent);
out.writeVLong(indexFailedCount);
out.writeVLong(deleteCount);
out.writeVLong(deleteTimeInMillis);
out.writeVLong(deleteCurrent);
out.writeVLong(noopUpdateCount);
out.writeBoolean(isThrottled);
out.writeLong(throttleTimeInMillis);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(Fields.INDEX_TOTAL, indexCount);
builder.humanReadableField(Fields.INDEX_TIME_IN_MILLIS, Fields.INDEX_TIME, getIndexTime());
builder.field(Fields.INDEX_CURRENT, indexCurrent);
builder.field(Fields.INDEX_FAILED, indexFailedCount);
builder.field(Fields.DELETE_TOTAL, deleteCount);
builder.humanReadableField(Fields.DELETE_TIME_IN_MILLIS, Fields.DELETE_TIME, getDeleteTime());
builder.field(Fields.DELETE_CURRENT, deleteCurrent);
builder.field(Fields.NOOP_UPDATE_TOTAL, noopUpdateCount);
builder.field(Fields.IS_THROTTLED, isThrottled);
builder.humanReadableField(Fields.THROTTLED_TIME_IN_MILLIS, Fields.THROTTLED_TIME, getThrottleTime());
return builder;
}
}
private final Stats totalStats;
public IndexingStats() {
totalStats = new Stats();
}
public IndexingStats(StreamInput in) throws IOException {
totalStats = new Stats(in);
if (in.getVersion().before(Version.V_2_0_0)) {
if (in.readBoolean()) {
Map<String, Stats> typeStats = in.readMap(StreamInput::readString, Stats::new);
assert typeStats.size() == 1;
assert typeStats.containsKey(MapperService.SINGLE_MAPPING_NAME);
}
}
}
public IndexingStats(Stats totalStats) {
this.totalStats = totalStats;
}
public void add(IndexingStats indexingStats) {
if (indexingStats == null) {
return;
}
addTotals(indexingStats);
}
public void addTotals(IndexingStats indexingStats) {
if (indexingStats == null) {
return;
}
totalStats.add(indexingStats.totalStats);
}
public Stats getTotal() {
return this.totalStats;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.INDEXING);
totalStats.toXContent(builder, params);
builder.endObject();
return builder;
}
/**
* Fields for indexing statistics
*
* @opensearch.internal
*/
static final class Fields {
static final String INDEXING = "indexing";
static final String INDEX_TOTAL = "index_total";
static final String INDEX_TIME = "index_time";
static final String INDEX_TIME_IN_MILLIS = "index_time_in_millis";
static final String INDEX_CURRENT = "index_current";
static final String INDEX_FAILED = "index_failed";
static final String DELETE_TOTAL = "delete_total";
static final String DELETE_TIME = "delete_time";
static final String DELETE_TIME_IN_MILLIS = "delete_time_in_millis";
static final String DELETE_CURRENT = "delete_current";
static final String NOOP_UPDATE_TOTAL = "noop_update_total";
static final String IS_THROTTLED = "is_throttled";
static final String THROTTLED_TIME_IN_MILLIS = "throttle_time_in_millis";
static final String THROTTLED_TIME = "throttle_time";
}
@Override
public void writeTo(StreamOutput out) throws IOException {
totalStats.writeTo(out);
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeBoolean(false);
}
}
}