|
|
@@ -255,7 +255,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
Version version,
|
|
|
List<SnapshotFeatureInfo> featureStates
|
|
|
) {
|
|
|
- return new SnapshotsInProgress.Entry(
|
|
|
+ return Entry.snapshot(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|
|
|
@@ -291,23 +291,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
long repositoryStateId,
|
|
|
Version version
|
|
|
) {
|
|
|
- return new SnapshotsInProgress.Entry(
|
|
|
- snapshot,
|
|
|
- true,
|
|
|
- false,
|
|
|
- State.STARTED,
|
|
|
- indices,
|
|
|
- Collections.emptyList(),
|
|
|
- Collections.emptyList(),
|
|
|
- startTime,
|
|
|
- repositoryStateId,
|
|
|
- Map.of(),
|
|
|
- null,
|
|
|
- Collections.emptyMap(),
|
|
|
- version,
|
|
|
- source,
|
|
|
- Map.of()
|
|
|
- );
|
|
|
+ return Entry.createClone(snapshot, State.STARTED, indices, startTime, repositoryStateId, null, version, source, Map.of());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -692,7 +676,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
private final String failure;
|
|
|
|
|
|
// visible for testing, use #startedEntry and copy constructors in production code
|
|
|
- public Entry(
|
|
|
+ public static Entry snapshot(
|
|
|
Snapshot snapshot,
|
|
|
boolean includeGlobalState,
|
|
|
boolean partial,
|
|
|
@@ -707,7 +691,17 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
Map<String, Object> userMetadata,
|
|
|
Version version
|
|
|
) {
|
|
|
- this(
|
|
|
+ final Map<String, Index> res = Maps.newMapWithExpectedSize(indices.size());
|
|
|
+ final Map<RepositoryShardId, ShardSnapshotStatus> byRepoShardIdBuilder = Maps.newHashMapWithExpectedSize(shards.size());
|
|
|
+ for (Map.Entry<ShardId, ShardSnapshotStatus> entry : shards.entrySet()) {
|
|
|
+ final ShardId shardId = entry.getKey();
|
|
|
+ final IndexId indexId = indices.get(shardId.getIndexName());
|
|
|
+ final Index index = shardId.getIndex();
|
|
|
+ final Index existing = res.put(indexId.getName(), index);
|
|
|
+ assert existing == null || existing.equals(index) : "Conflicting indices [" + existing + "] and [" + index + "]";
|
|
|
+ byRepoShardIdBuilder.put(new RepositoryShardId(indexId, shardId.id()), entry.getValue());
|
|
|
+ }
|
|
|
+ return new Entry(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|
|
|
@@ -722,6 +716,38 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
userMetadata,
|
|
|
version,
|
|
|
null,
|
|
|
+ byRepoShardIdBuilder,
|
|
|
+ res
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Entry createClone(
|
|
|
+ Snapshot snapshot,
|
|
|
+ State state,
|
|
|
+ Map<String, IndexId> indices,
|
|
|
+ long startTime,
|
|
|
+ long repositoryStateId,
|
|
|
+ String failure,
|
|
|
+ Version version,
|
|
|
+ SnapshotId source,
|
|
|
+ Map<RepositoryShardId, ShardSnapshotStatus> shardStatusByRepoShardId
|
|
|
+ ) {
|
|
|
+ return new Entry(
|
|
|
+ snapshot,
|
|
|
+ true,
|
|
|
+ false,
|
|
|
+ state,
|
|
|
+ indices,
|
|
|
+ List.of(),
|
|
|
+ List.of(),
|
|
|
+ startTime,
|
|
|
+ repositoryStateId,
|
|
|
+ Map.of(),
|
|
|
+ failure,
|
|
|
+ Map.of(),
|
|
|
+ version,
|
|
|
+ source,
|
|
|
+ shardStatusByRepoShardId,
|
|
|
Map.of()
|
|
|
);
|
|
|
}
|
|
|
@@ -741,7 +767,8 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
Map<String, Object> userMetadata,
|
|
|
Version version,
|
|
|
@Nullable SnapshotId source,
|
|
|
- Map<RepositoryShardId, ShardSnapshotStatus> shardStatusByRepoShardId
|
|
|
+ Map<RepositoryShardId, ShardSnapshotStatus> shardStatusByRepoShardId,
|
|
|
+ Map<String, Index> snapshotIndices
|
|
|
) {
|
|
|
this.state = state;
|
|
|
this.snapshot = snapshot;
|
|
|
@@ -757,26 +784,8 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
this.userMetadata = userMetadata == null ? null : Map.copyOf(userMetadata);
|
|
|
this.version = version;
|
|
|
this.source = source;
|
|
|
- if (source == null) {
|
|
|
- assert shardStatusByRepoShardId == null || shardStatusByRepoShardId.isEmpty()
|
|
|
- : "Provided explict repo shard id statuses [" + shardStatusByRepoShardId + "] but no source";
|
|
|
- final Map<String, Index> res = Maps.newMapWithExpectedSize(indices.size());
|
|
|
- final Map<RepositoryShardId, ShardSnapshotStatus> byRepoShardIdBuilder = Maps.newHashMapWithExpectedSize(shards.size());
|
|
|
- for (Map.Entry<ShardId, ShardSnapshotStatus> entry : shards.entrySet()) {
|
|
|
- final ShardId shardId = entry.getKey();
|
|
|
- final IndexId indexId = indices.get(shardId.getIndexName());
|
|
|
- final Index index = shardId.getIndex();
|
|
|
- final Index existing = res.put(indexId.getName(), index);
|
|
|
- assert existing == null || existing.equals(index) : "Conflicting indices [" + existing + "] and [" + index + "]";
|
|
|
- byRepoShardIdBuilder.put(new RepositoryShardId(indexId, shardId.id()), entry.getValue());
|
|
|
- }
|
|
|
- this.shardStatusByRepoShardId = Map.copyOf(byRepoShardIdBuilder);
|
|
|
- this.snapshotIndices = Map.copyOf(res);
|
|
|
- } else {
|
|
|
- assert shards.isEmpty();
|
|
|
- this.shardStatusByRepoShardId = shardStatusByRepoShardId;
|
|
|
- this.snapshotIndices = Map.of();
|
|
|
- }
|
|
|
+ this.shardStatusByRepoShardId = Map.copyOf(shardStatusByRepoShardId);
|
|
|
+ this.snapshotIndices = snapshotIndices;
|
|
|
assert assertShardsConsistent(this.source, this.state, this.indices, this.shards, this.shardStatusByRepoShardId);
|
|
|
}
|
|
|
|
|
|
@@ -809,24 +818,26 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
RepositoryShardId::new,
|
|
|
ShardSnapshotStatus::readFrom
|
|
|
);
|
|
|
- final List<SnapshotFeatureInfo> featureStates = Collections.unmodifiableList(in.readList(SnapshotFeatureInfo::new));
|
|
|
- return new SnapshotsInProgress.Entry(
|
|
|
- snapshot,
|
|
|
- includeGlobalState,
|
|
|
- partial,
|
|
|
- state,
|
|
|
- indices,
|
|
|
- dataStreams,
|
|
|
- featureStates,
|
|
|
- startTime,
|
|
|
- repositoryStateId,
|
|
|
- shards,
|
|
|
- failure,
|
|
|
- userMetadata,
|
|
|
- version,
|
|
|
- source,
|
|
|
- clones
|
|
|
- );
|
|
|
+ final List<SnapshotFeatureInfo> featureStates = in.readImmutableList(SnapshotFeatureInfo::new);
|
|
|
+ if (source == null) {
|
|
|
+ return snapshot(
|
|
|
+ snapshot,
|
|
|
+ includeGlobalState,
|
|
|
+ partial,
|
|
|
+ state,
|
|
|
+ indices,
|
|
|
+ dataStreams,
|
|
|
+ featureStates,
|
|
|
+ startTime,
|
|
|
+ repositoryStateId,
|
|
|
+ shards,
|
|
|
+ failure,
|
|
|
+ userMetadata,
|
|
|
+ version
|
|
|
+ );
|
|
|
+ }
|
|
|
+ assert shards.isEmpty();
|
|
|
+ return Entry.createClone(snapshot, state, indices, startTime, repositoryStateId, failure, version, source, clones);
|
|
|
}
|
|
|
|
|
|
private static boolean assertShardsConsistent(
|
|
|
@@ -889,7 +900,8 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
userMetadata,
|
|
|
version,
|
|
|
source,
|
|
|
- source == null ? Map.of() : shardStatusByRepoShardId
|
|
|
+ shardStatusByRepoShardId,
|
|
|
+ snapshotIndices
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -922,7 +934,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
}
|
|
|
}
|
|
|
if (updatedIndices != null) {
|
|
|
- return new Entry(
|
|
|
+ return snapshot(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|
|
|
@@ -935,9 +947,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
shards,
|
|
|
failure,
|
|
|
userMetadata,
|
|
|
- version,
|
|
|
- source,
|
|
|
- Map.of()
|
|
|
+ version
|
|
|
);
|
|
|
}
|
|
|
return this;
|
|
|
@@ -948,19 +958,13 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
return this;
|
|
|
}
|
|
|
assert shards.isEmpty();
|
|
|
- return new Entry(
|
|
|
+ return Entry.createClone(
|
|
|
snapshot,
|
|
|
- includeGlobalState,
|
|
|
- partial,
|
|
|
completed(updatedClones.values()) ? (hasFailures(updatedClones) ? State.FAILED : State.SUCCESS) : state,
|
|
|
indices,
|
|
|
- dataStreams,
|
|
|
- featureStates,
|
|
|
startTime,
|
|
|
repositoryStateId,
|
|
|
- Map.of(),
|
|
|
failure,
|
|
|
- userMetadata,
|
|
|
version,
|
|
|
source,
|
|
|
updatedClones
|
|
|
@@ -1000,7 +1004,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
if (allQueued) {
|
|
|
return null;
|
|
|
}
|
|
|
- return new Entry(
|
|
|
+ return Entry.snapshot(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|
|
|
@@ -1013,9 +1017,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
Map.copyOf(shardsBuilder),
|
|
|
ABORTED_FAILURE_TEXT,
|
|
|
userMetadata,
|
|
|
- version,
|
|
|
- source,
|
|
|
- Map.of()
|
|
|
+ version
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -1029,7 +1031,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
*/
|
|
|
public Entry withShardStates(Map<ShardId, ShardSnapshotStatus> shards) {
|
|
|
if (completed(shards.values())) {
|
|
|
- return new Entry(
|
|
|
+ return Entry.snapshot(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|
|
|
@@ -1053,7 +1055,7 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
|
|
|
* shard snapshots on data nodes for a running snapshot.
|
|
|
*/
|
|
|
public Entry withStartedShards(Map<ShardId, ShardSnapshotStatus> shards) {
|
|
|
- final SnapshotsInProgress.Entry updated = new Entry(
|
|
|
+ final SnapshotsInProgress.Entry updated = Entry.snapshot(
|
|
|
snapshot,
|
|
|
includeGlobalState,
|
|
|
partial,
|