Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.

Commit 6bcfcb8

Browse files
Include size of snapshot in snapshot metadata
Adds difference of number of files (and file sizes) between prev and current snapshot. Total number/size reflects total number/size of files in snapshot. Closes elastic#18543
1 parent e2d770d commit 6bcfcb8

File tree

8 files changed

+296
-65
lines changed

8 files changed

+296
-65
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ private SnapshotIndexShardStatus() {
7474
throw new IllegalArgumentException("Unknown stage type " + indexShardStatus.getStage());
7575
}
7676
this.stats = new SnapshotStats(indexShardStatus.getStartTime(), indexShardStatus.getTotalTime(),
77-
indexShardStatus.getNumberOfFiles(), indexShardStatus.getProcessedFiles(),
78-
indexShardStatus.getTotalSize(), indexShardStatus.getProcessedSize());
77+
indexShardStatus.getDifferenceOfNumberOfFiles(), indexShardStatus.getTotalNumberOfFiles(), indexShardStatus.getProcessedFiles(),
78+
indexShardStatus.getDifferenceOfSize(), indexShardStatus.getTotalSize(), indexShardStatus.getProcessedSize());
7979
this.failure = indexShardStatus.getFailure();
8080
this.nodeId = nodeId;
8181
}

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.admin.cluster.snapshots.status;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.common.io.stream.StreamInput;
2324
import org.elasticsearch.common.io.stream.StreamOutput;
2425
import 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 differenceOfNumberOfFiles;
39+
private int totalNumberOfFiles;
3840
private int processedFiles;
41+
private long differenceOfSize;
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 differenceOfNumberOfFiles, int totalNumberOfFiles, int processedFiles,
50+
long differenceOfSize, long totalSize, long processedSize) {
4651
this.startTime = startTime;
4752
this.time = time;
48-
this.numberOfFiles = numberOfFiles;
53+
this.differenceOfNumberOfFiles = differenceOfNumberOfFiles;
54+
this.totalNumberOfFiles = totalNumberOfFiles;
4955
this.processedFiles = processedFiles;
56+
this.differenceOfSize = differenceOfSize;
5057
this.totalSize = totalSize;
5158
this.processedSize = processedSize;
5259
}
@@ -66,10 +73,17 @@ public long getTime() {
6673
}
6774

6875
/**
69-
* Returns number of files in the snapshot
76+
* Returns difference of number of files between previous and this snapshot
7077
*/
71-
public int getNumberOfFiles() {
72-
return numberOfFiles;
78+
public int getDifferenceOfNumberOfFiles() {
79+
return differenceOfNumberOfFiles;
80+
}
81+
82+
/**
83+
* Returns total number of files in the snapshot
84+
*/
85+
public int getTotalNumberOfFiles() {
86+
return totalNumberOfFiles;
7387
}
7488

7589
/**
@@ -79,6 +93,13 @@ public int getProcessedFiles() {
7993
return processedFiles;
8094
}
8195

96+
/**
97+
* Return difference size of files between previous and this snapshot
98+
*/
99+
public long getDifferenceOfSize() {
100+
return differenceOfSize;
101+
}
102+
82103
/**
83104
* Returns total size of files in the snapshot
84105
*/
@@ -105,29 +126,45 @@ public void writeTo(StreamOutput out) throws IOException {
105126
out.writeVLong(startTime);
106127
out.writeVLong(time);
107128

108-
out.writeVInt(numberOfFiles);
129+
out.writeVInt(totalNumberOfFiles);
109130
out.writeVInt(processedFiles);
110131

111132
out.writeVLong(totalSize);
112133
out.writeVLong(processedSize);
134+
135+
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
136+
out.writeVInt(differenceOfNumberOfFiles);
137+
out.writeVLong(differenceOfSize);
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();
146+
totalNumberOfFiles = in.readVInt();
121147
processedFiles = in.readVInt();
122148

123149
totalSize = in.readVLong();
124150
processedSize = in.readVLong();
151+
152+
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
153+
differenceOfNumberOfFiles = in.readVInt();
154+
differenceOfSize = in.readVLong();
155+
} else {
156+
differenceOfNumberOfFiles = totalNumberOfFiles;
157+
differenceOfSize = totalSize;
158+
}
125159
}
126160

127161
static final class Fields {
128162
static final String STATS = "stats";
129-
static final String NUMBER_OF_FILES = "number_of_files";
163+
static final String DIFFERENCE_OF_NUMBER_OF_FILES = "difference_of_number_of_files";
164+
static final String TOTAL_NUMBER_OF_FILES = "total_number_of_files";
130165
static final String PROCESSED_FILES = "processed_files";
166+
static final String DIFFERENCE_OF_SIZE_IN_BYTES = "difference_of_size_in_bytes";
167+
static final String DIFFERENCE_OF_SIZE = "difference_of_size";
131168
static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes";
132169
static final String TOTAL_SIZE = "total_size";
133170
static final String PROCESSED_SIZE_IN_BYTES = "processed_size_in_bytes";
@@ -140,8 +177,10 @@ static final class Fields {
140177
@Override
141178
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
142179
builder.startObject(Fields.STATS);
143-
builder.field(Fields.NUMBER_OF_FILES, getNumberOfFiles());
180+
builder.field(Fields.DIFFERENCE_OF_NUMBER_OF_FILES, getDifferenceOfNumberOfFiles());
181+
builder.field(Fields.TOTAL_NUMBER_OF_FILES, getTotalNumberOfFiles());
144182
builder.field(Fields.PROCESSED_FILES, getProcessedFiles());
183+
builder.humanReadableField(Fields.DIFFERENCE_OF_SIZE_IN_BYTES, Fields.DIFFERENCE_OF_SIZE, new ByteSizeValue(getDifferenceOfSize()));
145184
builder.humanReadableField(Fields.TOTAL_SIZE_IN_BYTES, Fields.TOTAL_SIZE, new ByteSizeValue(getTotalSize()));
146185
builder.humanReadableField(Fields.PROCESSED_SIZE_IN_BYTES, Fields.PROCESSED_SIZE, new ByteSizeValue(getProcessedSize()));
147186
builder.field(Fields.START_TIME_IN_MILLIS, getStartTime());
@@ -151,9 +190,11 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
151190
}
152191

153192
void add(SnapshotStats stats) {
154-
numberOfFiles += stats.numberOfFiles;
193+
differenceOfNumberOfFiles += stats.differenceOfNumberOfFiles;
194+
totalNumberOfFiles += stats.totalNumberOfFiles;
155195
processedFiles += stats.processedFiles;
156196

197+
differenceOfSize += stats.differenceOfSize;
157198
totalSize += stats.totalSize;
158199
processedSize += stats.processedSize;
159200

server/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,39 @@ public enum Stage {
6060
private final AtomicReference<Stage> stage;
6161
private long startTime;
6262
private long totalTime;
63-
private int numberOfFiles;
63+
private int differenceOfNumberOfFiles;
64+
private int totalNumberOfFiles;
6465
private int processedFiles;
6566
private long totalSize;
67+
private long differenceOfSize;
6668
private long processedSize;
6769
private long indexVersion;
6870
private String failure;
6971

7072
private IndexShardSnapshotStatus(final Stage stage, final long startTime, final long totalTime,
71-
final int numberOfFiles, final int processedFiles, final long totalSize, final long processedSize,
73+
final int differenceOfNumberOfFiles, final int totalNumberOfFiles, final int processedFiles,
74+
final long differenceOfSize, final long totalSize, final long processedSize,
7275
final long indexVersion, final String failure) {
7376
this.stage = new AtomicReference<>(Objects.requireNonNull(stage));
7477
this.startTime = startTime;
7578
this.totalTime = totalTime;
76-
this.numberOfFiles = numberOfFiles;
79+
this.differenceOfNumberOfFiles = differenceOfNumberOfFiles;
80+
this.totalNumberOfFiles = totalNumberOfFiles;
7781
this.processedFiles = processedFiles;
7882
this.totalSize = totalSize;
7983
this.processedSize = processedSize;
84+
this.differenceOfSize = differenceOfSize;
8085
this.indexVersion = indexVersion;
8186
this.failure = failure;
8287
}
8388

84-
public synchronized Copy moveToStarted(final long startTime, final int numberOfFiles, final long totalSize) {
89+
public synchronized Copy moveToStarted(final long startTime, final int differenceOfNumberOfFiles, final int numberOfFiles,
90+
final long diffSize, final long totalSize) {
8591
if (stage.compareAndSet(Stage.INIT, Stage.STARTED)) {
8692
this.startTime = startTime;
87-
this.numberOfFiles = numberOfFiles;
93+
this.differenceOfNumberOfFiles = differenceOfNumberOfFiles;
94+
this.totalNumberOfFiles = numberOfFiles;
95+
this.differenceOfSize = diffSize;
8896
this.totalSize = totalSize;
8997
} else {
9098
throw new IllegalStateException("Unable to move the shard snapshot status to [STARTED]: " +
@@ -146,25 +154,30 @@ public synchronized void addProcessedFile(long size) {
146154
* @return a {@link IndexShardSnapshotStatus.Copy}
147155
*/
148156
public synchronized IndexShardSnapshotStatus.Copy asCopy() {
149-
return new IndexShardSnapshotStatus.Copy(stage.get(), startTime, totalTime, numberOfFiles, processedFiles, totalSize, processedSize,
150-
indexVersion, failure);
157+
return new IndexShardSnapshotStatus.Copy(stage.get(), startTime, totalTime,
158+
differenceOfNumberOfFiles, totalNumberOfFiles, processedFiles,
159+
differenceOfSize, totalSize, processedSize,
160+
indexVersion, failure);
151161
}
152162

153163
public static IndexShardSnapshotStatus newInitializing() {
154-
return new IndexShardSnapshotStatus(Stage.INIT, 0L, 0L, 0, 0, 0, 0, 0, null);
164+
return new IndexShardSnapshotStatus(Stage.INIT, 0L, 0L, 0, 0, 0, 0, 0, 0, 0, null);
155165
}
156166

157167
public static IndexShardSnapshotStatus newFailed(final String failure) {
158168
assert failure != null : "expecting non null failure for a failed IndexShardSnapshotStatus";
159169
if (failure == null) {
160170
throw new IllegalArgumentException("A failure description is required for a failed IndexShardSnapshotStatus");
161171
}
162-
return new IndexShardSnapshotStatus(Stage.FAILURE, 0L, 0L, 0, 0, 0, 0, 0, failure);
172+
return new IndexShardSnapshotStatus(Stage.FAILURE, 0L, 0L, 0, 0, 0, 0, 0, 0, 0, failure);
163173
}
164174

165-
public static IndexShardSnapshotStatus newDone(final long startTime, final long totalTime, final int files, final long size) {
175+
public static IndexShardSnapshotStatus newDone(final long startTime, final long totalTime,
176+
final int differenceOfNumberOfFiles, final int files,
177+
final long differenceOfSize, final long size) {
166178
// The snapshot is done which means the number of processed files is the same as total
167-
return new IndexShardSnapshotStatus(Stage.DONE, startTime, totalTime, files, files, size, size, 0, null);
179+
return new IndexShardSnapshotStatus(Stage.DONE, startTime, totalTime, differenceOfNumberOfFiles, files, differenceOfNumberOfFiles,
180+
differenceOfSize, size, differenceOfSize, 0, null);
168181
}
169182

170183
/**
@@ -175,23 +188,28 @@ public static class Copy {
175188
private final Stage stage;
176189
private final long startTime;
177190
private final long totalTime;
178-
private final int numberOfFiles;
191+
private final int differenceOfNumberOfFiles;
192+
private final int totalNumberOfFiles;
179193
private final int processedFiles;
180194
private final long totalSize;
181195
private final long processedSize;
196+
private final long differenceOfSize;
182197
private final long indexVersion;
183198
private final String failure;
184199

185200
public Copy(final Stage stage, final long startTime, final long totalTime,
186-
final int numberOfFiles, final int processedFiles, final long totalSize, final long processedSize,
201+
final int differenceOfNumberOfFiles, final int totalNumberOfFiles, final int processedFiles,
202+
final long differenceOfSize, final long totalSize, final long processedSize,
187203
final long indexVersion, final String failure) {
188204
this.stage = stage;
189205
this.startTime = startTime;
190206
this.totalTime = totalTime;
191-
this.numberOfFiles = numberOfFiles;
207+
this.differenceOfNumberOfFiles = differenceOfNumberOfFiles;
208+
this.totalNumberOfFiles = totalNumberOfFiles;
192209
this.processedFiles = processedFiles;
193210
this.totalSize = totalSize;
194211
this.processedSize = processedSize;
212+
this.differenceOfSize = differenceOfSize;
195213
this.indexVersion = indexVersion;
196214
this.failure = failure;
197215
}
@@ -208,14 +226,22 @@ public long getTotalTime() {
208226
return totalTime;
209227
}
210228

211-
public int getNumberOfFiles() {
212-
return numberOfFiles;
229+
public int getDifferenceOfNumberOfFiles() {
230+
return differenceOfNumberOfFiles;
231+
}
232+
233+
public int getTotalNumberOfFiles() {
234+
return totalNumberOfFiles;
213235
}
214236

215237
public int getProcessedFiles() {
216238
return processedFiles;
217239
}
218240

241+
public long getDifferenceOfSize() {
242+
return differenceOfSize;
243+
}
244+
219245
public long getTotalSize() {
220246
return totalSize;
221247
}
@@ -238,8 +264,10 @@ public String toString() {
238264
"stage=" + stage +
239265
", startTime=" + startTime +
240266
", totalTime=" + totalTime +
241-
", numberOfFiles=" + numberOfFiles +
267+
", differenceOfNumberOfFiles=" + differenceOfNumberOfFiles +
268+
", totalNumberOfFiles=" + totalNumberOfFiles +
242269
", processedFiles=" + processedFiles +
270+
", differenceOfSize=" + differenceOfSize +
243271
", totalSize=" + totalSize +
244272
", processedSize=" + processedSize +
245273
", indexVersion=" + indexVersion +

0 commit comments

Comments
 (0)