Skip to content

Commit 6ce0828

Browse files
committed
update
1 parent 4d7bd69 commit 6ce0828

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3ClientsManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838

3939
import static java.util.Collections.emptyMap;
4040

41+
/**
42+
* The S3ClientsManager is responsible for managing Amazon S3 clients associated with either the cluster or projects.
43+
* To use a single data structure for all clients, the cluster clients are stored against the default project-id.
44+
* Note that the cluster level clients are created and refreshed based on the ReloadablePlugin interface, while
45+
* the project level clients are created and refreshed by cluster state updates. All clients are released when
46+
* the manager itself is closed.
47+
*/
4148
public class S3ClientsManager implements ClusterStateApplier {
4249

4350
private static final Logger logger = LogManager.getLogger(S3ClientsManager.class);
@@ -188,8 +195,8 @@ AmazonS3Reference client(ProjectId projectId, RepositoryMetadata repositoryMetad
188195
}
189196

190197
/**
191-
* Similar to S3Service#releaseCachedClients but only clears the cache for the given project.
192-
* All clients for the project are closed and will be recreated on next access, also similar to S3Service#releaseCachedClients
198+
* Clears the cache for the given project (default project-id is for the cluster level clients).
199+
* All clients for the project are closed and will be recreated on next access.
193200
*/
194201
void releaseCachedClients(ProjectId projectId) {
195202
final var old = clientsHolders.get(Objects.requireNonNull(projectId));
@@ -202,7 +209,6 @@ void releaseCachedClients(ProjectId projectId) {
202209

203210
/**
204211
* Shutdown the manager by closing all clients holders. This is called when the node is shutting down.
205-
* It attempts to wait (1 min) for any async client closing to complete.
206212
*/
207213
void close() {
208214
IOUtils.closeWhileHandlingException(clientsHolders.values());

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,19 @@ public AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
169169
}
170170

171171
/**
172-
* Attempts to retrieve a project client from the project client manager. Throws if project-id or the client name does not exist.
173-
* THe client maybe initialized lazily.
174-
* Delegates to {@link #client(RepositoryMetadata)} when either of the followings is true:
175-
* 1. Per-project client is disabled
176-
* 2. Blobstore is cluster level (projectId = null)
172+
* Attempts to retrieve either a cluster or project client from the client manager. Throws if project-id or
173+
* the client name does not exist. The client maybe initialized lazily.
174+
* @param projectId The project associated with the client, or null if the client is cluster level
177175
*/
178176
public AmazonS3Reference client(@Nullable ProjectId projectId, RepositoryMetadata repositoryMetadata) {
179-
return s3ClientsManager.client(projectId == null ? ProjectId.DEFAULT : projectId, repositoryMetadata);
177+
return s3ClientsManager.client(effectiveProjectId(projectId), repositoryMetadata);
178+
}
179+
180+
/**
181+
* We use the default project-id for cluster level clients.
182+
*/
183+
ProjectId effectiveProjectId(@Nullable ProjectId projectId) {
184+
return projectId == null ? ProjectId.DEFAULT : projectId;
180185
}
181186

182187
// visible for tests
@@ -418,13 +423,10 @@ public void onBlobStoreClose() {
418423
}
419424

420425
/**
421-
* Release all project clients.
422-
* Delegates to {@link #onBlobStoreClose()} when either of the followings is true:
423-
* 1. Per-project client is disabled
424-
* 2. Blobstore is cluster level (projectId = null)
426+
* Release clients for the specified project.
425427
*/
426428
public void onBlobStoreClose(@Nullable ProjectId projectId) {
427-
s3ClientsManager.releaseCachedClients(projectId == null ? ProjectId.DEFAULT : projectId);
429+
s3ClientsManager.releaseCachedClients(effectiveProjectId(projectId));
428430
}
429431

430432
@Override

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3ClientsManagerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ public void testProjectClientsDisabled() {
295295
TestProjectResolvers.DEFAULT_PROJECT_ONLY,
296296
mock(ResourceWatcherService.class),
297297
() -> Region.of("es-test-region")
298-
) {
299-
};
298+
);
300299
s3ServiceWithNoProjectSupport.refreshAndClearCache(S3ClientSettings.load(clusterService.getSettings()));
301300
s3ServiceWithNoProjectSupport.start();
302301
assertNotNull(s3ServiceWithNoProjectSupport.getS3PerProjectClientManager());
@@ -317,6 +316,7 @@ public void testProjectClientsDisabled() {
317316

318317
private Map<ProjectId, S3ClientsManager.ClientsHolder<?>> getClientsHoldersExcludeDefaultProject() {
319318
final var holders = s3ClientsManager.getClientsHolders();
319+
// Clients holder for the default project always exists
320320
assertThat(holders, hasKey(ProjectId.DEFAULT));
321321
return holders.entrySet()
322322
.stream()

0 commit comments

Comments
 (0)