diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index 32ea610f53287..75ead529d5c1b 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -1360,6 +1360,12 @@ RepositoryData repositoryData() { @Override public void getRepositoryData(ActionListener listener) { + // RepositoryData is the responsibility of the elected master: we shouldn't be loading it on other nodes as we don't have good + // consistency guarantees there, but electedness is too ephemeral to assert. We can say for sure that this node should be + // master-eligible, which is almost as strong since all other snapshot-related activity happens on data nodes whether they be + // master-eligible or not. + assert clusterService.localNode().isMasterNode() : "should only load repository data on master nodes"; + if (latestKnownRepoGen.get() == RepositoryData.CORRUPTED_REPO_GEN) { listener.onFailure(corruptedStateException(null)); return; diff --git a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreTestUtil.java b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreTestUtil.java index 9cef26e39eeb0..0d1148eb0d142 100644 --- a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreTestUtil.java +++ b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreTestUtil.java @@ -349,6 +349,7 @@ private static ClusterService mockClusterService(ClusterState initialState) { when(clusterService.getClusterApplierService()).thenReturn(clusterApplierService); // Setting local node as master so it may update the repository metadata in the cluster state final DiscoveryNode localNode = new DiscoveryNode("", buildNewFakeTransportAddress(), Version.CURRENT); + when(clusterService.localNode()).thenReturn(localNode); final AtomicReference currentState = new AtomicReference<>( ClusterState.builder(initialState).nodes( DiscoveryNodes.builder().add(localNode).masterNodeId(localNode.getId()).localNodeId(localNode.getId()).build()).build()); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java index 0122e494520b9..ee67ae67a3601 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java @@ -182,7 +182,9 @@ public void testFilesStoredInThePersistentCacheAreMarkedAsReusedInRecoveryState( assertThat(repository, instanceOf(BlobStoreRepository.class)); final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository; - final RepositoryData repositoryData = ESBlobStoreRepositoryIntegTestCase.getRepositoryData(repository); + final RepositoryData repositoryData = ESBlobStoreRepositoryIntegTestCase.getRepositoryData( + internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class).repository(fsRepoName) + ); final IndexId indexId = repositoryData.resolveIndexId(indexName); long inMemoryCacheSize = 0; long expectedPhysicalCacheSize = 0;