Skip to content

Commit 1a9da53

Browse files
committed
Shallow snapshot v2 - do create snapshot validations in a cluster state update
Signed-off-by: Gaurav Bafna <[email protected]>
1 parent 66c7780 commit 1a9da53

File tree

2 files changed

+391
-25
lines changed

2 files changed

+391
-25
lines changed

server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,38 @@ public static Entry startedEntry(
134134
);
135135
}
136136

137+
public static Entry startedEntry(
138+
Snapshot snapshot,
139+
boolean includeGlobalState,
140+
boolean partial,
141+
List<IndexId> indices,
142+
List<String> dataStreams,
143+
long startTime,
144+
long repositoryStateId,
145+
final Map<ShardId, ShardSnapshotStatus> shards,
146+
Map<String, Object> userMetadata,
147+
Version version,
148+
boolean remoteStoreIndexShallowCopy,
149+
boolean remoteStoreIndexShallowCopyV2
150+
) {
151+
return new SnapshotsInProgress.Entry(
152+
snapshot,
153+
includeGlobalState,
154+
partial,
155+
completed(shards.values()) ? State.SUCCESS : State.STARTED,
156+
indices,
157+
dataStreams,
158+
startTime,
159+
repositoryStateId,
160+
shards,
161+
null,
162+
userMetadata,
163+
version,
164+
remoteStoreIndexShallowCopy,
165+
remoteStoreIndexShallowCopyV2
166+
);
167+
}
168+
137169
/**
138170
* Creates the initial snapshot clone entry
139171
*
@@ -168,11 +200,42 @@ public static Entry startClone(
168200
version,
169201
source,
170202
Map.of(),
171-
false // initialising to false, will be updated in startCloning method of SnapshotsService while updating entry with
203+
false,
204+
false// initialising to false, will be updated in startCloning method of SnapshotsService while updating entry with
172205
// clone jobs
173206
);
174207
}
175208

209+
public static Entry startClone(
210+
Snapshot snapshot,
211+
SnapshotId source,
212+
List<IndexId> indices,
213+
long startTime,
214+
long repositoryStateId,
215+
Version version,
216+
boolean remoteStoreIndexShallowCopyV2
217+
) {
218+
return new SnapshotsInProgress.Entry(
219+
snapshot,
220+
true,
221+
false,
222+
State.STARTED,
223+
indices,
224+
Collections.emptyList(),
225+
startTime,
226+
repositoryStateId,
227+
Map.of(),
228+
null,
229+
Collections.emptyMap(),
230+
version,
231+
source,
232+
Map.of(),
233+
remoteStoreIndexShallowCopyV2,
234+
remoteStoreIndexShallowCopyV2// initialising to false, will be updated in startCloning method of SnapshotsService while updating entry with
235+
// clone jobs
236+
);
237+
}
238+
176239
/**
177240
* Entry in the collection.
178241
*
@@ -183,6 +246,8 @@ public static class Entry implements Writeable, ToXContent, RepositoryOperation
183246
private final Snapshot snapshot;
184247
private final boolean includeGlobalState;
185248
private final boolean remoteStoreIndexShallowCopy;
249+
250+
private final boolean remoteStoreIndexShallowCopyV2;
186251
private final boolean partial;
187252
/**
188253
* Map of {@link ShardId} to {@link ShardSnapshotStatus} tracking the state of each shard snapshot operation.
@@ -212,6 +277,42 @@ public static class Entry implements Writeable, ToXContent, RepositoryOperation
212277
@Nullable
213278
private final String failure;
214279

280+
public Entry(
281+
Snapshot snapshot,
282+
boolean includeGlobalState,
283+
boolean partial,
284+
State state,
285+
List<IndexId> indices,
286+
List<String> dataStreams,
287+
long startTime,
288+
long repositoryStateId,
289+
final Map<ShardId, ShardSnapshotStatus> shards,
290+
String failure,
291+
Map<String, Object> userMetadata,
292+
Version version,
293+
boolean remoteStoreIndexShallowCopy,
294+
boolean remoteStoreIndexShallowCopyV2
295+
) {
296+
this(
297+
snapshot,
298+
includeGlobalState,
299+
partial,
300+
state,
301+
indices,
302+
dataStreams,
303+
startTime,
304+
repositoryStateId,
305+
shards,
306+
failure,
307+
userMetadata,
308+
version,
309+
null,
310+
Map.of(),
311+
remoteStoreIndexShallowCopy,
312+
remoteStoreIndexShallowCopyV2
313+
);
314+
}
315+
215316
// visible for testing, use #startedEntry and copy constructors in production code
216317
public Entry(
217318
Snapshot snapshot,
@@ -243,11 +344,12 @@ public Entry(
243344
version,
244345
null,
245346
Map.of(),
246-
remoteStoreIndexShallowCopy
347+
remoteStoreIndexShallowCopy,
348+
false
247349
);
248350
}
249351

250-
private Entry(
352+
public Entry(
251353
Snapshot snapshot,
252354
boolean includeGlobalState,
253355
boolean partial,
@@ -262,7 +364,8 @@ private Entry(
262364
Version version,
263365
@Nullable SnapshotId source,
264366
@Nullable final Map<RepositoryShardId, ShardSnapshotStatus> clones,
265-
boolean remoteStoreIndexShallowCopy
367+
boolean remoteStoreIndexShallowCopy,
368+
boolean remoteStoreIndexShallowCopyV2
266369
) {
267370
this.state = state;
268371
this.snapshot = snapshot;
@@ -284,7 +387,8 @@ private Entry(
284387
this.clones = Collections.unmodifiableMap(clones);
285388
}
286389
this.remoteStoreIndexShallowCopy = remoteStoreIndexShallowCopy;
287-
assert assertShardsConsistent(this.source, this.state, this.indices, this.shards, this.clones);
390+
this.remoteStoreIndexShallowCopyV2 = remoteStoreIndexShallowCopyV2;
391+
assert this.remoteStoreIndexShallowCopyV2 || assertShardsConsistent(this.source, this.state, this.indices, this.shards, this.clones);
288392
}
289393

290394
private Entry(StreamInput in) throws IOException {
@@ -307,6 +411,11 @@ private Entry(StreamInput in) throws IOException {
307411
} else {
308412
remoteStoreIndexShallowCopy = false;
309413
}
414+
if (in.getVersion().onOrAfter(Version.CURRENT)) {
415+
remoteStoreIndexShallowCopyV2 = in.readBoolean();
416+
} else {
417+
remoteStoreIndexShallowCopyV2 = false;
418+
}
310419
}
311420

312421
private static boolean assertShardsConsistent(
@@ -428,7 +537,8 @@ public Entry withRepoGen(long newRepoGen) {
428537
version,
429538
source,
430539
clones,
431-
remoteStoreIndexShallowCopy
540+
remoteStoreIndexShallowCopy,
541+
remoteStoreIndexShallowCopyV2
432542
);
433543
}
434544

@@ -451,7 +561,8 @@ public Entry withClones(final Map<RepositoryShardId, ShardSnapshotStatus> update
451561
version,
452562
source,
453563
updatedClones,
454-
remoteStoreIndexShallowCopy
564+
remoteStoreIndexShallowCopy,
565+
remoteStoreIndexShallowCopyV2
455566
);
456567
}
457568

@@ -471,7 +582,8 @@ public Entry withRemoteStoreIndexShallowCopy(final boolean remoteStoreIndexShall
471582
version,
472583
source,
473584
clones,
474-
remoteStoreIndexShallowCopy
585+
remoteStoreIndexShallowCopy,
586+
remoteStoreIndexShallowCopyV2
475587
);
476588
}
477589

@@ -527,7 +639,8 @@ public Entry fail(final Map<ShardId, ShardSnapshotStatus> shards, State state, S
527639
version,
528640
source,
529641
clones,
530-
remoteStoreIndexShallowCopy
642+
remoteStoreIndexShallowCopy,
643+
remoteStoreIndexShallowCopyV2
531644
);
532645
}
533646

@@ -614,6 +727,10 @@ public boolean remoteStoreIndexShallowCopy() {
614727
return remoteStoreIndexShallowCopy;
615728
}
616729

730+
public boolean remoteStoreIndexShallowCopyV2() {
731+
return remoteStoreIndexShallowCopyV2;
732+
}
733+
617734
public Map<String, Object> userMetadata() {
618735
return userMetadata;
619736
}
@@ -678,6 +795,7 @@ public boolean equals(Object o) {
678795
if (Objects.equals(source, ((Entry) o).source) == false) return false;
679796
if (clones.equals(((Entry) o).clones) == false) return false;
680797
if (remoteStoreIndexShallowCopy != entry.remoteStoreIndexShallowCopy) return false;
798+
if (remoteStoreIndexShallowCopyV2 != entry.remoteStoreIndexShallowCopyV2) return false;
681799
return true;
682800
}
683801

@@ -695,6 +813,7 @@ public int hashCode() {
695813
result = 31 * result + (source == null ? 0 : source.hashCode());
696814
result = 31 * result + clones.hashCode();
697815
result = 31 * result + (remoteStoreIndexShallowCopy ? 1 : 0);
816+
result = 31 * result + (remoteStoreIndexShallowCopyV2 ? 1 : 0);
698817
return result;
699818
}
700819

@@ -766,6 +885,9 @@ public void writeTo(StreamOutput out) throws IOException {
766885
if (out.getVersion().onOrAfter(Version.V_2_9_0)) {
767886
out.writeBoolean(remoteStoreIndexShallowCopy);
768887
}
888+
if (out.getVersion().onOrAfter(Version.CURRENT)) {
889+
out.writeBoolean(remoteStoreIndexShallowCopyV2);
890+
}
769891
}
770892

771893
@Override

0 commit comments

Comments
 (0)