1212import org .elasticsearch .TransportVersion ;
1313import org .elasticsearch .TransportVersions ;
1414import org .elasticsearch .cluster .ClusterState .Custom ;
15+ import org .elasticsearch .cluster .metadata .Metadata ;
1516import org .elasticsearch .cluster .metadata .ProjectId ;
1617import org .elasticsearch .cluster .metadata .SingleNodeShutdownMetadata ;
1718import org .elasticsearch .cluster .node .DiscoveryNode ;
2324import org .elasticsearch .common .util .Maps ;
2425import org .elasticsearch .common .util .set .Sets ;
2526import org .elasticsearch .common .xcontent .ChunkedToXContentHelper ;
27+ import org .elasticsearch .core .FixForMultiProject ;
2628import org .elasticsearch .core .Nullable ;
2729import org .elasticsearch .core .SuppressForbidden ;
2830import org .elasticsearch .core .Tuple ;
5961import java .util .stream .Stream ;
6062
6163import static org .elasticsearch .repositories .RepositoryOperation .PROJECT_REPO_SERIALIZER ;
62- import static org .elasticsearch .repositories .RepositoryOperation .defaultProjectRepo ;
6364
6465/**
6566 * Meta data about snapshots that are currently executing
@@ -132,16 +133,18 @@ private SnapshotsInProgress(Map<ProjectRepo, ByRepo> entries, Set<String> nodesI
132133 assert assertConsistentEntries (this .entries );
133134 }
134135
136+ @ FixForMultiProject
135137 @ Deprecated (forRemoval = true )
136138 public SnapshotsInProgress withUpdatedEntriesForRepo (String repository , List <Entry > updatedEntries ) {
137- return withUpdatedEntriesForRepo (defaultProjectRepo ( repository ) , updatedEntries );
139+ return withUpdatedEntriesForRepo (Metadata . DEFAULT_PROJECT_ID , repository , updatedEntries );
138140 }
139141
140- public SnapshotsInProgress withUpdatedEntriesForRepo (ProjectRepo projectRepo , List <Entry > updatedEntries ) {
141- if (updatedEntries .equals (forRepo (projectRepo ))) {
142+ public SnapshotsInProgress withUpdatedEntriesForRepo (ProjectId projectId , String repository , List <Entry > updatedEntries ) {
143+ if (updatedEntries .equals (forRepo (projectId , repository ))) {
142144 return this ;
143145 }
144146 final Map <ProjectRepo , ByRepo > copy = new HashMap <>(this .entries );
147+ final var projectRepo = new ProjectRepo (projectId , repository );
145148 if (updatedEntries .isEmpty ()) {
146149 copy .remove (projectRepo );
147150 if (copy .isEmpty ()) {
@@ -154,24 +157,25 @@ public SnapshotsInProgress withUpdatedEntriesForRepo(ProjectRepo projectRepo, Li
154157 }
155158
156159 public SnapshotsInProgress withAddedEntry (Entry entry ) {
157- final List <Entry > forRepo = new ArrayList <>(forRepo (entry .projectRepo ()));
160+ final List <Entry > forRepo = new ArrayList <>(forRepo (entry .projectId (), entry . repository ()));
158161 forRepo .add (entry );
159- return withUpdatedEntriesForRepo (entry .projectRepo (), forRepo );
162+ return withUpdatedEntriesForRepo (entry .projectId (), entry . repository (), forRepo );
160163 }
161164
162165 /**
163166 * Returns the list of snapshots in the specified repository.
164167 */
168+ @ FixForMultiProject
165169 @ Deprecated (forRemoval = true )
166170 public List <Entry > forRepo (String repository ) {
167- return entries . getOrDefault ( defaultProjectRepo ( repository ), ByRepo . EMPTY ). entries ;
171+ return forRepo ( Metadata . DEFAULT_PROJECT_ID , repository ) ;
168172 }
169173
170174 /**
171175 * Returns the list of snapshots in the specified repository.
172176 */
173- public List <Entry > forRepo (ProjectRepo projectRepo ) {
174- return entries .getOrDefault (projectRepo , ByRepo .EMPTY ).entries ;
177+ public List <Entry > forRepo (ProjectId projectId , String repository ) {
178+ return entries .getOrDefault (new ProjectRepo ( projectId , repository ) , ByRepo .EMPTY ).entries ;
175179 }
176180
177181 public boolean isEmpty () {
@@ -196,7 +200,7 @@ public Stream<Entry> asStream() {
196200
197201 @ Nullable
198202 public Entry snapshot (final Snapshot snapshot ) {
199- return findSnapshotInList (snapshot , forRepo (snapshot .getProjectRepo ()));
203+ return findSnapshotInList (snapshot , forRepo (snapshot .getProjectId (), snapshot . getRepository ()));
200204 }
201205
202206 /**
@@ -224,12 +228,13 @@ private static Entry findSnapshotInList(Snapshot snapshotToFind, List<Entry> for
224228 * in-progress shard snapshots that were not yet finalized when it began. All these other in-progress shard snapshot lists are scheduled
225229 * for deletion now.
226230 */
231+ @ FixForMultiProject
227232 @ Deprecated (forRemoval = true )
228233 public Map <RepositoryShardId , Set <ShardGeneration >> obsoleteGenerations (
229234 String repository ,
230235 SnapshotsInProgress oldClusterStateSnapshots
231236 ) {
232- return obsoleteGenerations (defaultProjectRepo ( repository ) , oldClusterStateSnapshots );
237+ return obsoleteGenerations (Metadata . DEFAULT_PROJECT_ID , repository , oldClusterStateSnapshots );
233238 }
234239
235240 /**
@@ -243,13 +248,14 @@ public Map<RepositoryShardId, Set<ShardGeneration>> obsoleteGenerations(
243248 * for deletion now.
244249 */
245250 public Map <RepositoryShardId , Set <ShardGeneration >> obsoleteGenerations (
246- ProjectRepo projectRepo ,
251+ ProjectId projectId ,
252+ String repository ,
247253 SnapshotsInProgress oldClusterStateSnapshots
248254 ) {
249255 final Map <RepositoryShardId , Set <ShardGeneration >> obsoleteGenerations = new HashMap <>();
250- final List <Entry > latestSnapshots = forRepo (projectRepo );
256+ final List <Entry > latestSnapshots = forRepo (projectId , repository );
251257
252- for (Entry oldEntry : oldClusterStateSnapshots .forRepo (projectRepo )) {
258+ for (Entry oldEntry : oldClusterStateSnapshots .forRepo (projectId , repository )) {
253259 final Entry matchingLatestEntry = findSnapshotInList (oldEntry .snapshot (), latestSnapshots );
254260 if (matchingLatestEntry == null || matchingLatestEntry == oldEntry ) {
255261 // The snapshot progress has not changed.
@@ -456,7 +462,8 @@ private static boolean assertConsistentEntries(Map<ProjectRepo, ByRepo> entries)
456462 final ProjectRepo repository = repoEntries .getKey ();
457463 assert entriesForRepository .isEmpty () == false : "found empty list of snapshots for " + repository + " in " + entries ;
458464 for (Entry entry : entriesForRepository ) {
459- assert entry .projectRepo ().equals (repository ) : "mismatched repository " + entry + " tracked under " + repository ;
465+ assert new ProjectRepo (entry .projectId (), entry .repository ()).equals (repository )
466+ : "mismatched repository " + entry + " tracked under " + repository ;
460467 for (Map .Entry <RepositoryShardId , ShardSnapshotStatus > shard : entry .shardSnapshotStatusByRepoShardId ().entrySet ()) {
461468 final RepositoryShardId sid = shard .getKey ();
462469 final ShardSnapshotStatus shardSnapshotStatus = shard .getValue ();
@@ -1287,10 +1294,6 @@ public String repository() {
12871294 return snapshot .getRepository ();
12881295 }
12891296
1290- public ProjectRepo projectRepo () {
1291- return new ProjectRepo (projectId (), repository ());
1292- }
1293-
12941297 public Snapshot snapshot () {
12951298 return this .snapshot ;
12961299 }
@@ -1793,7 +1796,7 @@ private static final class SnapshotInProgressDiff implements NamedDiff<Custom> {
17931796 );
17941797 this .mapDiff = DiffableUtils .jdkMapDiffWithUpdatedKeys (
17951798 oldMapDiff ,
1796- RepositoryOperation :: defaultProjectRepo ,
1799+ repository -> new ProjectRepo ( ProjectId . DEFAULT , repository ) ,
17971800 PROJECT_REPO_SERIALIZER
17981801 );
17991802 } else {
@@ -1835,12 +1838,12 @@ public void writeTo(StreamOutput out) throws IOException {
18351838 if (out .getTransportVersion ().before (TransportVersions .PROJECT_ID_IN_SNAPSHOT )) {
18361839 DiffableUtils .jdkMapDiffWithUpdatedKeys (mapDiff , projectRepo -> {
18371840 if (ProjectId .DEFAULT .equals (projectRepo .projectId ()) == false ) {
1838- throw new IllegalArgumentException (
1839- "Cannot write instance with non-default project id "
1840- + projectRepo . projectId ()
1841- + " to version before "
1842- + TransportVersions . PROJECT_ID_IN_SNAPSHOT
1843- );
1841+ final var message = "Cannot write instance with non-default project id "
1842+ + projectRepo . projectId ()
1843+ + " to version before "
1844+ + TransportVersions . PROJECT_ID_IN_SNAPSHOT ;
1845+ assert false : message ;
1846+ throw new IllegalArgumentException ( message );
18441847 }
18451848 return projectRepo .repoName ();
18461849 }, DiffableUtils .getStringKeySerializer ()).writeTo (out );
0 commit comments