Skip to content

Commit 10fab8e

Browse files
Simplify and optimize deduplication of RepositoryData for a non-caching repository instance
This makes use of the new deduplicator infrastructure to move to more efficient deduplication mechanics. The existing solution hardly ever deduplicated because it would only deduplicate after the repository entered a consistent state. The adjusted solution is much simpler, in that it simply deduplicates such that only a single loading of `RepositoryData` will ever happen at a time, fixing memory issues from massively concurrent loading of the repo data as described in elastic#89952. closes elastic#89952
1 parent 751dc24 commit 10fab8e

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.elasticsearch.Version;
2626
import org.elasticsearch.action.ActionListener;
2727
import org.elasticsearch.action.ActionRunnable;
28-
import org.elasticsearch.action.ResultDeduplicator;
28+
import org.elasticsearch.action.SingleResultDeduplicator;
2929
import org.elasticsearch.action.StepListener;
3030
import org.elasticsearch.action.support.GroupedActionListener;
3131
import org.elasticsearch.action.support.ListenableActionFuture;
@@ -413,7 +413,7 @@ protected BlobStoreRepository(
413413
this.namedXContentRegistry = namedXContentRegistry;
414414
this.basePath = basePath;
415415
this.maxSnapshotCount = MAX_SNAPSHOTS_SETTING.get(metadata.settings());
416-
this.repoDataDeduplicator = new ResultDeduplicator<>(threadPool.getThreadContext());
416+
this.repoDataLoadDeduplicator = new SingleResultDeduplicator<>(threadPool.getThreadContext(), this::doGetRepositoryData);
417417
shardSnapshotTaskRunner = new ShardSnapshotTaskRunner(
418418
threadPool.info(ThreadPool.Names.SNAPSHOT).getMax(),
419419
threadPool.executor(ThreadPool.Names.SNAPSHOT),
@@ -1787,19 +1787,8 @@ public void getRepositoryData(ActionListener<RepositoryData> listener) {
17871787
metadata.name(),
17881788
latestKnownRepoGen
17891789
);
1790-
// Don't deduplicate repo data loading if we don't have strong consistency guarantees between the repo and the cluster state
1791-
// Also, if we are not caching repository data (for tests) we assume that the contents of the repository data at a given
1792-
// generation may change
1793-
final Executor executor = threadPool.executor(ThreadPool.Names.SNAPSHOT_META);
1794-
if (bestEffortConsistency || cacheRepositoryData == false) {
1795-
executor.execute(ActionRunnable.wrap(listener, this::doGetRepositoryData));
1796-
} else {
1797-
repoDataDeduplicator.executeOnce(
1798-
metadata,
1799-
listener,
1800-
(metadata, l) -> executor.execute(ActionRunnable.wrap(l, this::doGetRepositoryData))
1801-
);
1802-
}
1790+
threadPool.executor(ThreadPool.Names.SNAPSHOT_META)
1791+
.execute(ActionRunnable.wrap(listener, this.repoDataLoadDeduplicator::execute));
18031792
}
18041793
}
18051794

@@ -1912,7 +1901,7 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState)
19121901
),
19131902
onFailure
19141903
),
1915-
this::doGetRepositoryData
1904+
this.repoDataLoadDeduplicator::execute
19161905
)
19171906
);
19181907
} else {
@@ -1926,11 +1915,9 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState)
19261915
}
19271916

19281917
/**
1929-
* {@link RepositoryData} loading deduplicator. This may only be used with consistent generation repositories, meaning
1930-
* {@link #bestEffortConsistency} must be {@code false}, in which case we can assume that the {@link RepositoryData} loaded is
1931-
* unique for a given value of {@link #metadata} at any point in time.
1918+
* Deduplicator that deduplicates the physical loading of {@link RepositoryData} from the repositories' underlying storage.
19321919
*/
1933-
private final ResultDeduplicator<RepositoryMetadata, RepositoryData> repoDataDeduplicator;
1920+
private final SingleResultDeduplicator<RepositoryData> repoDataLoadDeduplicator;
19341921

19351922
private void doGetRepositoryData(ActionListener<RepositoryData> listener) {
19361923
// Retry loading RepositoryData in a loop in case we run into concurrent modifications of the repository.

0 commit comments

Comments
 (0)