1919
2020package org .elasticsearch .action .admin .cluster .snapshots .status ;
2121
22+ import org .elasticsearch .Version ;
2223import org .elasticsearch .common .io .stream .StreamInput ;
2324import org .elasticsearch .common .io .stream .StreamOutput ;
2425import org .elasticsearch .common .io .stream .Streamable ;
@@ -34,19 +35,25 @@ public class SnapshotStats implements Streamable, ToXContentFragment {
3435
3536 private long startTime ;
3637 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 ;
3942 private long totalSize ;
4043 private long processedSize ;
4144
4245 SnapshotStats () {
4346 }
4447
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 ) {
4651 this .startTime = startTime ;
4752 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 ;
5057 this .totalSize = totalSize ;
5158 this .processedSize = processedSize ;
5259 }
@@ -66,17 +73,31 @@ public long getTime() {
6673 }
6774
6875 /**
69- * Returns number of files in the snapshot
76+ * Returns incremental file count of the snapshot
7077 */
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 ;
7387 }
7488
7589 /**
7690 * Returns number of files in the snapshot that were processed so far
7791 */
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 ;
80101 }
81102
82103 /**
@@ -105,59 +126,109 @@ public void writeTo(StreamOutput out) throws IOException {
105126 out .writeVLong (startTime );
106127 out .writeVLong (time );
107128
108- out .writeVInt (numberOfFiles );
109- out .writeVInt (processedFiles );
129+ out .writeVInt (incrementalFileCount );
130+ out .writeVInt (processedFileCount );
110131
111- out .writeVLong (totalSize );
132+ out .writeVLong (incrementalSize );
112133 out .writeVLong (processedSize );
134+
135+ if (out .getVersion ().onOrAfter (Version .V_6_4_0 )) {
136+ out .writeVInt (totalFileCount );
137+ out .writeVLong (totalSize );
138+ }
113139 }
114140
115141 @ Override
116142 public void readFrom (StreamInput in ) throws IOException {
117143 startTime = in .readVLong ();
118144 time = in .readVLong ();
119145
120- numberOfFiles = in .readVInt ();
121- processedFiles = in .readVInt ();
146+ incrementalFileCount = in .readVInt ();
147+ processedFileCount = in .readVInt ();
122148
123- totalSize = in .readVLong ();
149+ incrementalSize = in .readVLong ();
124150 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+ }
125159 }
126160
127161 static final class Fields {
128162 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
129177 static final String NUMBER_OF_FILES = "number_of_files" ;
130178 static final String PROCESSED_FILES = "processed_files" ;
131- static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes" ;
132179 static final String TOTAL_SIZE = "total_size" ;
180+ static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes" ;
133181 static final String PROCESSED_SIZE_IN_BYTES = "processed_size_in_bytes" ;
134182 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+
138184 }
139185
140186 @ Override
141187 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 ();
151221 }
152222
153223 void add (SnapshotStats stats ) {
154- numberOfFiles += stats .numberOfFiles ;
155- processedFiles += stats .processedFiles ;
224+ incrementalFileCount += stats .incrementalFileCount ;
225+ totalFileCount += stats .totalFileCount ;
226+ processedFileCount += stats .processedFileCount ;
156227
228+ incrementalSize += stats .incrementalSize ;
157229 totalSize += stats .totalSize ;
158230 processedSize += stats .processedSize ;
159231
160-
161232 if (startTime == 0 ) {
162233 // First time here
163234 startTime = stats .startTime ;
0 commit comments