Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,14 @@ private Entry(Snapshot snapshot, boolean includeGlobalState, boolean partial, St
this.snapshot = snapshot;
this.includeGlobalState = includeGlobalState;
this.partial = partial;
this.indices = indices;
this.dataStreams = dataStreams;
this.indices = Map.copyOf(indices);
this.dataStreams = List.copyOf(dataStreams);
this.featureStates = Collections.unmodifiableList(featureStates);
this.startTime = startTime;
this.shards = shards;
this.repositoryStateId = repositoryStateId;
this.failure = failure;
this.userMetadata = userMetadata;
this.userMetadata = userMetadata == null ? null : Map.copyOf(userMetadata);
this.version = version;
this.source = source;
if (source == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,9 @@ private void finalizeSnapshotEntry(SnapshotsInProgress.Entry entry, Metadata met
entry.partial() ? shardGenerations.totalShards() : entry.shards().size(),
shardFailures,
entry.includeGlobalState(),
entry.userMetadata(),
// TODO: remove this hack making the metadata mutable once
// https://github.com/elastic/elasticsearch/pull/72776 has been merged
entry.userMetadata() == null ? null : new HashMap<>(entry.userMetadata()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with the linked test failure was that the map in the entry was mutated while a snapshot status request was iterating over it. We must not have mutable objects in the cluster state so even though this is a horrible hack it at least gives us safe behavior in how our state machines work.

entry.startTime(),
indexSnapshotDetails);
repo.finalizeSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ public Map<String, Object> adaptUserMetadata(Map<String, Object> userMetadata) {
localRepositoryPasswordSalt,
localRepositoryPasswordHash
);
// do not wrap in Map.of; we have to be able to modify the map (remove the added entries) when finalizing the snapshot
return snapshotUserMetadata;
return Map.copyOf(snapshotUserMetadata);
}

@Override
Expand Down