summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java
blob: 51c8bcf5d7e27b6ee1747dba74f32bebcd7f3c7d (plain)
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
/*
 * 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.
 */

package org.elasticsearch.index.snapshots;

/**
 * Represent shard snapshot status
 */
public class IndexShardSnapshotStatus {

    /**
     * Snapshot stage
     */
    public static enum Stage {
        /**
         * Snapshot hasn't started yet
         */
        INIT,
        /**
         * Index files are being copied
         */
        STARTED,
        /**
         * Snapshot metadata is being written
         */
        FINALIZE,
        /**
         * Snapshot completed successfully
         */
        DONE,
        /**
         * Snapshot failed
         */
        FAILURE
    }

    private Stage stage = Stage.INIT;

    private long startTime;

    private long time;

    private int numberOfFiles;

    private volatile int processedFiles;

    private long totalSize;

    private volatile long processedSize;

    private long indexVersion;

    private boolean aborted;

    private String failure;

    /**
     * Returns current snapshot stage
     *
     * @return current snapshot stage
     */
    public Stage stage() {
        return this.stage;
    }

    /**
     * Sets new snapshot stage
     *
     * @param stage new snapshot stage
     */
    public void updateStage(Stage stage) {
        this.stage = stage;
    }

    /**
     * Returns snapshot start time
     *
     * @return snapshot start time
     */
    public long startTime() {
        return this.startTime;
    }

    /**
     * Sets snapshot start time
     *
     * @param startTime snapshot start time
     */
    public void startTime(long startTime) {
        this.startTime = startTime;
    }

    /**
     * Returns snapshot processing time
     *
     * @return processing time
     */
    public long time() {
        return this.time;
    }

    /**
     * Sets snapshot processing time
     *
     * @param time snapshot processing time
     */
    public void time(long time) {
        this.time = time;
    }

    /**
     * Returns true if snapshot process was aborted
     *
     * @return true if snapshot process was aborted
     */
    public boolean aborted() {
        return this.aborted;
    }

    /**
     * Marks snapshot as aborted
     */
    public void abort() {
        this.aborted = true;
    }

    /**
     * Sets files stats
     *
     * @param numberOfFiles number of files in this snapshot
     * @param totalSize     total size of files in this snapshot
     */
    public void files(int numberOfFiles, long totalSize) {
        this.numberOfFiles = numberOfFiles;
        this.totalSize = totalSize;
    }

    /**
     * Sets processed files stats
     *
     * @param numberOfFiles number of files in this snapshot
     * @param totalSize     total size of files in this snapshot
     */
    public synchronized void processedFiles(int numberOfFiles, long totalSize) {
        processedFiles = numberOfFiles;
        processedSize = totalSize;
    }

    /**
     * Increments number of processed files
     */
    public synchronized void addProcessedFile(long size) {
        processedFiles++;
        processedSize += size;
    }

    /**
     * Number of files
     *
     * @return number of files
     */
    public int numberOfFiles() {
        return numberOfFiles;
    }

    /**
     * Total snapshot size
     *
     * @return snapshot size
     */
    public long totalSize() {
        return totalSize;
    }

    /**
     * Number of processed files
     *
     * @return number of processed files
     */
    public int processedFiles() {
        return processedFiles;
    }

    /**
     * Size of processed files
     *
     * @return size of processed files
     */
    public long processedSize() {
        return processedSize;
    }


    /**
     * Sets index version
     *
     * @param indexVersion index version
     */
    public void indexVersion(long indexVersion) {
        this.indexVersion = indexVersion;
    }

    /**
     * Returns index version
     *
     * @return index version
     */
    public long indexVersion() {
        return indexVersion;
    }

    /**
     * Sets the reason for the failure if the snapshot is in the {@link IndexShardSnapshotStatus.Stage#FAILURE} state
     */
    public void failure(String failure) {
        this.failure = failure;
    }

    /**
     * Returns the reason for the failure if the snapshot is in the {@link IndexShardSnapshotStatus.Stage#FAILURE} state
     */
    public String failure() {
        return failure;
    }
}