Skip to content

Commit 39fa184

Browse files
committed
tweak
1 parent 616a770 commit 39fa184

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ abstract class ClientsHolder<K> implements Closeable {
256256
*/
257257
abstract ProjectId projectId();
258258

259-
/**
260-
* Determine the client name from the given repository metadata.
261-
*/
262-
String clientName(RepositoryMetadata repositoryMetadata) {
263-
return S3Repository.CLIENT_NAME.get(repositoryMetadata.settings());
264-
}
265-
266259
/**
267260
* Similar to {@link #singleClientSettings(K)} but from the given repository metadata.
268261
*/
@@ -290,20 +283,14 @@ final AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
290283
}
291284

292285
final var settings = singleClientSettings(clientKey);
293-
if (settings == null) {
294-
throw new IllegalArgumentException(
295-
"s3 client [" + clientName(repositoryMetadata) + "] does not exist for project [" + projectId() + "]"
296-
);
297-
}
298-
299286
synchronized (this) {
300287
final var existing = clientsCache.get(clientKey);
301288
if (existing != null && existing.tryIncRef()) {
302289
return existing;
303290
}
304291
if (closed.get()) {
305292
// Not adding a new client once the manager is closed since there won't be anything to close it
306-
throw new IllegalStateException("client manager is closed");
293+
throw new IllegalStateException("clients holder is closed");
307294
}
308295
// The close() method maybe called after we checked it, it is ok since we are already inside the synchronized block.
309296
// The clearCache() will clear the newly added client.
@@ -350,6 +337,7 @@ final class PerProjectClientsHolder extends ClientsHolder<String> {
350337
private final Map<String, S3ClientSettings> clientSettings;
351338

352339
PerProjectClientsHolder(ProjectId projectId, Map<String, S3ClientSettings> clientSettings) {
340+
assert ProjectId.DEFAULT.equals(projectId) == false;
353341
this.projectId = projectId;
354342
this.clientSettings = clientSettings;
355343
}
@@ -366,7 +354,11 @@ String clientKey(RepositoryMetadata repositoryMetadata) {
366354

367355
@Override
368356
S3ClientSettings singleClientSettings(String clientKey) {
369-
return clientSettings.get(clientKey);
357+
final S3ClientSettings settings = clientSettings.get(clientKey);
358+
if (settings == null) {
359+
throw new IllegalArgumentException("s3 client [" + clientKey + "] does not exist for project [" + projectId + "]");
360+
}
361+
return settings;
370362
}
371363

372364
@Override

0 commit comments

Comments
 (0)