Skip to content

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Jul 25, 2025

Similar to #127631, this PR adds per project client support for GCS repository.

@ywangd ywangd added >non-issue :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Jul 28, 2025
@ywangd ywangd requested review from DaveCTurner and pxsalehi July 28, 2025 23:56
@ywangd ywangd marked this pull request as ready for review July 29, 2025 00:01
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Jul 29, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Jul 29, 2025
for (var projectId : perProjectClientsHolders.keySet()) {
if (currentProjects.containsKey(projectId) == false) {
assert ProjectId.DEFAULT.equals(projectId) == false;
perProjectClientsHolders.remove(projectId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach for managing per-project clients is similar to what we did for s3 but simpler. It is simpler because there is no ref-counting for the clients and we don't actively close it when it is not needed. Therefore, we simply remove and replace it when needed.

Comment on lines 129 to 131
void refreshAndClearCacheForClusterClients(Map<String, GoogleCloudStorageClientSettings> clientsSettings) {
clusterClientsHolder.refreshAndClearCache(clientsSettings);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for stateful or cluster level clients to keep the behaviour identical to existing code.


public GoogleCloudStorageService(boolean isServerless) {
this.isServerless = isServerless;
@SuppressWarnings("this-escape")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to avoid this. You can add a static method to create the instance and then create the client manager.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added because we pass GoogleCloudStorageService#createClient to the clients manager. It's hard to make this method static because it uses other methods that are overridden in tests. Not entirely sure whether this is your suggestion?

Alternatively, I can move the clientsManager inside GoogleCloudStorageService and this problem should go away since they are in one file. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the client manager inside GoogleCloudStorageService seems like a good solution!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed ab073f8

clientCache = clientCache.entrySet()
.stream()
.filter(entry -> entry.getKey().equals(repositoryName) == false)
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, java.util.Map.Entry::getValue));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably drop the java.util.

continue;
}
final ProjectSecrets projectSecrets = project.custom(ProjectSecrets.TYPE);
// Project secrets can be null when node restarts. It may not have any s3 credentials if s3 is not in use.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/pasted code 🤦 pushed fbdd313

Comment on lines 95 to 97
// Skip project clients that have no credentials configured. This should not happen in serverless.
// But it is safer to skip them and is also a more consistent behaviour with the cases when
// project secrets are not present.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be a transient state? Does it worth a warn log?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a configuration problem on the CP side. Yes, we should log it. There is one for empty clients settings map after this. But I think we can combine them and continue the processing. Pushed 57de151 which also adds a test. I'll update it similarly for s3 in a separate PR.

@ywangd ywangd requested a review from pxsalehi July 31, 2025 02:30
Copy link
Member

@pxsalehi pxsalehi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending getting rid of the new @SuppressWarnings("this-escape").

@ywangd ywangd added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Aug 4, 2025
@elasticsearchmachine elasticsearchmachine merged commit 2559e28 into elastic:main Aug 4, 2025
33 checks passed
@ywangd ywangd deleted the ES-11715-gcs-per-project-clients branch August 4, 2025 02:55
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Aug 5, 2025
Log a message only when the client settings have actual changes. Relates: elastic#131899
elasticsearchmachine pushed a commit that referenced this pull request Aug 5, 2025
Log a message only when the client settings have actual changes. Relates: #131899
elasticsearchmachine pushed a commit that referenced this pull request Aug 13, 2025
This PR adds per project client support for Azure repository similar to #131899 (GCS) and #127631 (s3). Resolves: ES-11714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue serverless-linked Added by automation, don't add manually Team:Distributed Coordination Meta label for Distributed Coordination team v9.2.0

3 participants