19
19
20
20
package org .elasticsearch .action .admin .cluster .snapshots .status ;
21
21
22
+ import org .elasticsearch .Version ;
22
23
import org .elasticsearch .common .io .stream .StreamInput ;
23
24
import org .elasticsearch .common .io .stream .StreamOutput ;
24
25
import org .elasticsearch .common .io .stream .Streamable ;
@@ -34,19 +35,25 @@ public class SnapshotStats implements Streamable, ToXContentFragment {
34
35
35
36
private long startTime ;
36
37
private long time ;
37
- private int numberOfFiles ;
38
- private int processedFiles ;
38
+ private int incrementalFileCount ;
39
+ private int totalFileCount ;
40
+ private int processedFileCount ;
41
+ private long incrementalSize ;
39
42
private long totalSize ;
40
43
private long processedSize ;
41
44
42
45
SnapshotStats () {
43
46
}
44
47
45
- SnapshotStats (long startTime , long time , int numberOfFiles , int processedFiles , long totalSize , long processedSize ) {
48
+ SnapshotStats (long startTime , long time ,
49
+ int incrementalFileCount , int totalFileCount , int processedFileCount ,
50
+ long incrementalSize , long totalSize , long processedSize ) {
46
51
this .startTime = startTime ;
47
52
this .time = time ;
48
- this .numberOfFiles = numberOfFiles ;
49
- this .processedFiles = processedFiles ;
53
+ this .incrementalFileCount = incrementalFileCount ;
54
+ this .totalFileCount = totalFileCount ;
55
+ this .processedFileCount = processedFileCount ;
56
+ this .incrementalSize = incrementalSize ;
50
57
this .totalSize = totalSize ;
51
58
this .processedSize = processedSize ;
52
59
}
@@ -66,17 +73,31 @@ public long getTime() {
66
73
}
67
74
68
75
/**
69
- * Returns number of files in the snapshot
76
+ * Returns incremental file count of the snapshot
70
77
*/
71
- public int getNumberOfFiles () {
72
- return numberOfFiles ;
78
+ public int getIncrementalFileCount () {
79
+ return incrementalFileCount ;
80
+ }
81
+
82
+ /**
83
+ * Returns total number of files in the snapshot
84
+ */
85
+ public int getTotalFileCount () {
86
+ return totalFileCount ;
73
87
}
74
88
75
89
/**
76
90
* Returns number of files in the snapshot that were processed so far
77
91
*/
78
- public int getProcessedFiles () {
79
- return processedFiles ;
92
+ public int getProcessedFileCount () {
93
+ return processedFileCount ;
94
+ }
95
+
96
+ /**
97
+ * Return incremental files size of the snapshot
98
+ */
99
+ public long getIncrementalSize () {
100
+ return incrementalSize ;
80
101
}
81
102
82
103
/**
@@ -105,59 +126,109 @@ public void writeTo(StreamOutput out) throws IOException {
105
126
out .writeVLong (startTime );
106
127
out .writeVLong (time );
107
128
108
- out .writeVInt (numberOfFiles );
109
- out .writeVInt (processedFiles );
129
+ out .writeVInt (incrementalFileCount );
130
+ out .writeVInt (processedFileCount );
110
131
111
- out .writeVLong (totalSize );
132
+ out .writeVLong (incrementalSize );
112
133
out .writeVLong (processedSize );
134
+
135
+ if (out .getVersion ().onOrAfter (Version .V_6_4_0 )) {
136
+ out .writeVInt (totalFileCount );
137
+ out .writeVLong (totalSize );
138
+ }
113
139
}
114
140
115
141
@ Override
116
142
public void readFrom (StreamInput in ) throws IOException {
117
143
startTime = in .readVLong ();
118
144
time = in .readVLong ();
119
145
120
- numberOfFiles = in .readVInt ();
121
- processedFiles = in .readVInt ();
146
+ incrementalFileCount = in .readVInt ();
147
+ processedFileCount = in .readVInt ();
122
148
123
- totalSize = in .readVLong ();
149
+ incrementalSize = in .readVLong ();
124
150
processedSize = in .readVLong ();
151
+
152
+ if (in .getVersion ().onOrAfter (Version .V_6_4_0 )) {
153
+ totalFileCount = in .readVInt ();
154
+ totalSize = in .readVLong ();
155
+ } else {
156
+ totalFileCount = incrementalFileCount ;
157
+ totalSize = incrementalSize ;
158
+ }
125
159
}
126
160
127
161
static final class Fields {
128
162
static final String STATS = "stats" ;
163
+
164
+ static final String INCREMENTAL = "incremental" ;
165
+ static final String PROCESSED = "processed" ;
166
+ static final String TOTAL = "total" ;
167
+
168
+ static final String FILE_COUNT = "file_count" ;
169
+ static final String SIZE = "size" ;
170
+ static final String SIZE_IN_BYTES = "size_in_bytes" ;
171
+
172
+ static final String START_TIME_IN_MILLIS = "start_time_in_millis" ;
173
+ static final String TIME_IN_MILLIS = "time_in_millis" ;
174
+ static final String TIME = "time" ;
175
+
176
+ // BWC
129
177
static final String NUMBER_OF_FILES = "number_of_files" ;
130
178
static final String PROCESSED_FILES = "processed_files" ;
131
- static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes" ;
132
179
static final String TOTAL_SIZE = "total_size" ;
180
+ static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes" ;
133
181
static final String PROCESSED_SIZE_IN_BYTES = "processed_size_in_bytes" ;
134
182
static final String PROCESSED_SIZE = "processed_size" ;
135
- static final String START_TIME_IN_MILLIS = "start_time_in_millis" ;
136
- static final String TIME_IN_MILLIS = "time_in_millis" ;
137
- static final String TIME = "time" ;
183
+
138
184
}
139
185
140
186
@ Override
141
187
public XContentBuilder toXContent (XContentBuilder builder , ToXContent .Params params ) throws IOException {
142
- builder .startObject (Fields .STATS );
143
- builder .field (Fields .NUMBER_OF_FILES , getNumberOfFiles ());
144
- builder .field (Fields .PROCESSED_FILES , getProcessedFiles ());
145
- builder .humanReadableField (Fields .TOTAL_SIZE_IN_BYTES , Fields .TOTAL_SIZE , new ByteSizeValue (getTotalSize ()));
146
- builder .humanReadableField (Fields .PROCESSED_SIZE_IN_BYTES , Fields .PROCESSED_SIZE , new ByteSizeValue (getProcessedSize ()));
147
- builder .field (Fields .START_TIME_IN_MILLIS , getStartTime ());
148
- builder .humanReadableField (Fields .TIME_IN_MILLIS , Fields .TIME , new TimeValue (getTime ()));
149
- builder .endObject ();
150
- return builder ;
188
+ builder .startObject (Fields .STATS )
189
+ // incremental starts
190
+ .startObject (Fields .INCREMENTAL )
191
+ .field (Fields .FILE_COUNT , getIncrementalFileCount ())
192
+ .humanReadableField (Fields .SIZE_IN_BYTES , Fields .SIZE , new ByteSizeValue (getIncrementalSize ()))
193
+ // incremental ends
194
+ .endObject ();
195
+
196
+ if (getProcessedFileCount () != getIncrementalFileCount ()) {
197
+ // processed starts
198
+ builder .startObject (Fields .PROCESSED )
199
+ .field (Fields .FILE_COUNT , getProcessedFileCount ())
200
+ .humanReadableField (Fields .SIZE_IN_BYTES , Fields .SIZE , new ByteSizeValue (getProcessedSize ()))
201
+ // processed ends
202
+ .endObject ();
203
+ }
204
+ // total starts
205
+ builder .startObject (Fields .TOTAL )
206
+ .field (Fields .FILE_COUNT , getTotalFileCount ())
207
+ .humanReadableField (Fields .SIZE_IN_BYTES , Fields .SIZE , new ByteSizeValue (getTotalSize ()))
208
+ // total ends
209
+ .endObject ();
210
+ // timings stats
211
+ builder .field (Fields .START_TIME_IN_MILLIS , getStartTime ())
212
+ .humanReadableField (Fields .TIME_IN_MILLIS , Fields .TIME , new TimeValue (getTime ()));
213
+
214
+ // BWC part
215
+ return builder .field (Fields .NUMBER_OF_FILES , getIncrementalFileCount ())
216
+ .field (Fields .PROCESSED_FILES , getProcessedFileCount ())
217
+ .humanReadableField (Fields .TOTAL_SIZE_IN_BYTES , Fields .TOTAL_SIZE , new ByteSizeValue (getIncrementalSize ()))
218
+ .humanReadableField (Fields .PROCESSED_SIZE_IN_BYTES , Fields .PROCESSED_SIZE , new ByteSizeValue (getProcessedSize ()))
219
+ // BWC part ends
220
+ .endObject ();
151
221
}
152
222
153
223
void add (SnapshotStats stats ) {
154
- numberOfFiles += stats .numberOfFiles ;
155
- processedFiles += stats .processedFiles ;
224
+ incrementalFileCount += stats .incrementalFileCount ;
225
+ totalFileCount += stats .totalFileCount ;
226
+ processedFileCount += stats .processedFileCount ;
156
227
228
+ incrementalSize += stats .incrementalSize ;
157
229
totalSize += stats .totalSize ;
158
230
processedSize += stats .processedSize ;
159
231
160
-
161
232
if (startTime == 0 ) {
162
233
// First time here
163
234
startTime = stats .startTime ;
0 commit comments