Skip to content

Commit 132401f

Browse files
committed
fix tests
1 parent d9248b4 commit 132401f

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SnapshotInProgressAllocationDecider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
package org.elasticsearch.cluster.routing.allocation.decider;
1111

1212
import org.elasticsearch.cluster.SnapshotsInProgress;
13-
import org.elasticsearch.cluster.metadata.ProjectId;
1413
import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata;
1514
import org.elasticsearch.cluster.routing.RoutingNode;
1615
import org.elasticsearch.cluster.routing.ShardRouting;
1716
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
17+
import org.elasticsearch.core.FixForMultiProject;
1818

1919
import java.util.Objects;
2020

@@ -74,8 +74,9 @@ private static Decision canMove(ShardRouting shardRouting, RoutingAllocation all
7474
return YES_NOT_SNAPSHOTTED;
7575
}
7676

77-
final ProjectId projectId = allocation.metadata().projectFor(shardRouting.index()).id();
78-
for (final var entriesByRepo : snapshotsInProgress.entriesByRepo(projectId)) {
77+
@FixForMultiProject(description = "replace with entriesByRepo(ProjectId), see also ES-12195")
78+
final var entriesByRepoIterable = snapshotsInProgress.entriesByRepo();
79+
for (final var entriesByRepo : entriesByRepoIterable) {
7980
for (final var entry : entriesByRepo) {
8081
if (entry.isClone()) {
8182
// clones do not run on data nodes

server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ public static void updateRepositoryUuidInMetadata(
455455

456456
logger.info(
457457
Strings.format(
458-
"Registering repository [%s] with repository UUID [%s] and generation [%d]",
459-
repositoryName,
458+
"Registering repository %s with repository UUID [%s] and generation [%d]",
459+
projectRepoString(projectId, repositoryName),
460460
repositoryData.getUuid(),
461461
repositoryData.getGenId()
462462
)

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3891,7 +3891,8 @@ public String toString() {
38913891
return "BlobStoreRepository[" + toStringShort() + ", [" + blobStore.get() + ']' + ']';
38923892
}
38933893

3894-
private String toStringShort() {
3894+
// Package private for testing
3895+
String toStringShort() {
38953896
return projectRepoString(projectId, metadata.name());
38963897
}
38973898

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public final class SnapshotsService extends AbstractLifecycleComponent implement
198198

199199
private final SystemIndices systemIndices;
200200

201-
private final boolean supportsMultipleProjects;
201+
private final boolean serializeProjectMetadata;
202202

203203
private final MasterServiceTaskQueue<SnapshotTask> masterServiceTaskQueue;
204204

@@ -228,7 +228,7 @@ public SnapshotsService(
228228
TransportService transportService,
229229
ActionFilters actionFilters,
230230
SystemIndices systemIndices,
231-
boolean supportsMultipleProjects
231+
boolean serializeProjectMetadata
232232
) {
233233
this.clusterService = clusterService;
234234
this.rerouteService = rerouteService;
@@ -247,7 +247,7 @@ public SnapshotsService(
247247
.addSettingsUpdateConsumer(MAX_CONCURRENT_SNAPSHOT_OPERATIONS_SETTING, i -> maxConcurrentOperations = i);
248248
}
249249
this.systemIndices = systemIndices;
250-
this.supportsMultipleProjects = supportsMultipleProjects;
250+
this.serializeProjectMetadata = serializeProjectMetadata;
251251

252252
this.masterServiceTaskQueue = clusterService.createTaskQueue("snapshots-service", Priority.NORMAL, new SnapshotTaskExecutor());
253253
this.updateNodeIdsToRemoveQueue = clusterService.createTaskQueue(
@@ -808,7 +808,7 @@ private static UpdatedShardGenerations buildGenerations(SnapshotsInProgress.Entr
808808
private Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot, Metadata metadata, ProjectId projectId) {
809809
final ProjectMetadata snapshotProject = projectForSnapshot(snapshot, metadata.getProject(projectId));
810810
final Metadata.Builder builder;
811-
if (snapshot.includeGlobalState() == false || supportsMultipleProjects) {
811+
if (snapshot.includeGlobalState() == false || serializeProjectMetadata) {
812812
// Remove global state from the cluster state when
813813
// 1. The request explicitly demands that
814814
// 2. The snapshot is for a project in a multi-project cluster. Such a snapshot must not include cluster level info
@@ -1478,7 +1478,7 @@ private void leaveRepoLoop(ProjectId projectId, String repository) {
14781478
private void finalizeSnapshotEntry(Snapshot snapshot, Metadata metadata, RepositoryData repositoryData) {
14791479
final ProjectId projectId = snapshot.getProjectId();
14801480
final Metadata effectiveMetadata;
1481-
if (supportsMultipleProjects) {
1481+
if (serializeProjectMetadata) {
14821482
effectiveMetadata = Metadata.builder().put(metadata.getProject(projectId)).build();
14831483
} else {
14841484
effectiveMetadata = metadata;
@@ -1541,7 +1541,7 @@ protected void doRun() {
15411541
final Repository repo = repositoriesService.repository(projectId, repository);
15421542
if (entry.isClone()) {
15431543
threadPool.executor(ThreadPool.Names.SNAPSHOT).execute(ActionRunnable.supply(metadataListener, () -> {
1544-
final Metadata existingMetadata = repo.getSnapshotGlobalMetadata(entry.source(), supportsMultipleProjects);
1544+
final Metadata existingMetadata = repo.getSnapshotGlobalMetadata(entry.source(), serializeProjectMetadata);
15451545
final ProjectMetadata existingProject = existingMetadata.getProject(projectId);
15461546
final ProjectMetadata.Builder projBuilder = ProjectMetadata.builder(existingProject);
15471547
final Set<Index> existingIndices = new HashSet<>();
@@ -1623,7 +1623,7 @@ protected void doRun() {
16231623
final ListenableFuture<List<ActionListener<SnapshotInfo>>> snapshotListeners = new ListenableFuture<>();
16241624
repo.finalizeSnapshot(
16251625
new FinalizeSnapshotContext(
1626-
supportsMultipleProjects,
1626+
serializeProjectMetadata,
16271627
updatedShardGenerations,
16281628
repositoryData.getGenId(),
16291629
metaForSnapshot,

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataDataStreamsServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,8 @@ public void testDeleteMissing() {
559559

560560
public void testDeleteSnapshotting() {
561561
String dataStreamName = randomAlphaOfLength(5);
562-
Snapshot snapshot = new Snapshot("doesn't matter", new SnapshotId("snapshot name", "snapshot uuid"));
562+
var projectId = randomProjectIdOrDefault();
563+
Snapshot snapshot = new Snapshot(projectId, "doesn't matter", new SnapshotId("snapshot name", "snapshot uuid"));
563564
SnapshotsInProgress snaps = SnapshotsInProgress.EMPTY.withAddedEntry(
564565
SnapshotsInProgress.Entry.snapshot(
565566
snapshot,
@@ -578,7 +579,6 @@ public void testDeleteSnapshotting() {
578579
)
579580
);
580581
final DataStream dataStream = DataStreamTestHelper.randomInstance(dataStreamName);
581-
var projectId = randomProjectIdOrDefault();
582582
ProjectState state = ClusterState.builder(ClusterName.DEFAULT)
583583
.putCustom(SnapshotsInProgress.TYPE, snaps)
584584
.putProjectMetadata(ProjectMetadata.builder(projectId).put(dataStream))

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataDeleteIndexServiceTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public void testDeleteMissing() {
8888

8989
public void testDeleteSnapshotting() {
9090
String indexName = randomAlphaOfLength(5);
91-
Snapshot snapshot = new Snapshot("doesn't matter", new SnapshotId("snapshot name", "snapshot uuid"));
91+
final ProjectId projectId = randomProjectIdOrDefault();
92+
Snapshot snapshot = new Snapshot(projectId, "doesn't matter", new SnapshotId("snapshot name", "snapshot uuid"));
9293
SnapshotsInProgress snaps = SnapshotsInProgress.EMPTY.withAddedEntry(
9394
SnapshotsInProgress.Entry.snapshot(
9495
snapshot,
@@ -107,7 +108,7 @@ public void testDeleteSnapshotting() {
107108
)
108109
);
109110
final Index index = new Index(indexName, randomUUID());
110-
ClusterState state = ClusterState.builder(clusterState(index)).putCustom(SnapshotsInProgress.TYPE, snaps).build();
111+
ClusterState state = ClusterState.builder(clusterState(projectId, index)).putCustom(SnapshotsInProgress.TYPE, snaps).build();
111112
Exception e = expectThrows(
112113
SnapshotInProgressException.class,
113114
() -> MetadataDeleteIndexService.deleteIndices(state, Set.of(index), Settings.EMPTY)
@@ -125,9 +126,8 @@ public void testDeleteUnassigned() throws Exception {
125126
// Create an unassigned index
126127
String indexName = randomAlphaOfLength(5);
127128
Index index = new Index(indexName, randomUUID());
128-
ClusterState before = clusterState(index);
129-
130-
final var projectId = before.metadata().projectFor(index).id();
129+
final ProjectId projectId = randomProjectIdOrDefault();
130+
ClusterState before = clusterState(projectId, index);
131131

132132
// Mock the built reroute
133133
when(allocationService.reroute(any(ClusterState.class), anyString(), any())).then(i -> i.getArguments()[0]);
@@ -433,11 +433,10 @@ public void testDeleteIndicesFromMultipleProjects() {
433433
assertThat(after.metadata().projects(), aMapWithSize(numProjects));
434434
}
435435

436-
private ClusterState clusterState(Index index) {
436+
private ClusterState clusterState(ProjectId projectId, Index index) {
437437
final IndexMetadata indexMetadata = IndexMetadata.builder(index.getName())
438438
.settings(indexSettings(IndexVersionUtils.randomVersion(), index.getUUID(), 1, 1))
439439
.build();
440-
final ProjectId projectId = randomProjectIdOrDefault();
441440
final Metadata.Builder metadataBuilder = Metadata.builder().put(ProjectMetadata.builder(projectId).put(indexMetadata, false));
442441

443442
if (randomBoolean()) {
@@ -454,7 +453,7 @@ private ClusterState clusterState(Index index) {
454453
return ClusterState.builder(ClusterName.DEFAULT)
455454
.metadata(metadata)
456455
.routingTable(GlobalRoutingTableTestHelper.buildRoutingTable(metadata, RoutingTable.Builder::addAsNew))
457-
.blocks(ClusterBlocks.builder().addBlocks(indexMetadata))
456+
.blocks(ClusterBlocks.builder().addBlocks(projectId, indexMetadata))
458457
.build();
459458
}
460459
}

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ private static ClusterState addSnapshotIndex(
452452
);
453453
}
454454

455-
final Snapshot snapshot = new Snapshot(randomAlphaOfLength(10), new SnapshotId(randomAlphaOfLength(5), randomAlphaOfLength(5)));
455+
final Snapshot snapshot = new Snapshot(
456+
projectId,
457+
randomAlphaOfLength(10),
458+
new SnapshotId(randomAlphaOfLength(5), randomAlphaOfLength(5))
459+
);
456460
final SnapshotsInProgress.Entry entry = SnapshotsInProgress.Entry.snapshot(
457461
snapshot,
458462
randomBoolean(),

server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ public void testUuidCreationLogging() {
700700
"new repo uuid message",
701701
BlobStoreRepository.class.getCanonicalName(),
702702
Level.INFO,
703-
Strings.format("Generated new repository UUID [*] for repository [%s] in generation [*]", repoName)
703+
Strings.format("Generated new repository UUID [*] for repository %s in generation [*]", repo.toStringShort())
704704
)
705705
);
706706

@@ -729,7 +729,7 @@ public void testUuidCreationLogging() {
729729
"existing repo uuid message",
730730
RepositoriesService.class.getCanonicalName(),
731731
Level.INFO,
732-
Strings.format("Registering repository [%s] with repository UUID *", repoName)
732+
Strings.format("Registering repository %s with repository UUID *", repo.toStringShort())
733733
)
734734
);
735735

@@ -785,7 +785,7 @@ public void testUuidCreationLogging() {
785785
"existing repo uuid message",
786786
RepositoriesService.class.getCanonicalName(),
787787
Level.INFO,
788-
Strings.format("Registering repository [%s] with repository UUID *", repoName)
788+
Strings.format("Registering repository %s with repository UUID *", repo.toStringShort())
789789
)
790790
);
791791
},

0 commit comments

Comments
 (0)