Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Add retry conig for gcp-datastore #2636

Open
NorthernDarkness opened this issue Feb 5, 2021 · 3 comments
Open

Add retry conig for gcp-datastore #2636

NorthernDarkness opened this issue Feb 5, 2021 · 3 comments
Labels

Comments

@NorthernDarkness
Copy link

NorthernDarkness commented Feb 5, 2021

GCP native java client allows to configure retries, but there is no way to do so if spring-data-datastore is used.

The native client is instantiated in a private method, so no way to change this. If a user defined Datastore bean with configured retries is exposed, this will not work because of namespaces. It is not possible to have both NamespaceProvider and Datastore at the same time. To add a custom datastore client, the entire namespace related instantiation logic have to be copied on user side. Suggestion is to add RestryConfigurationProperties read config from it and configure in getDatastore() method:

` private Datastore getDatastore(String namespace) {
DatastoreOptions.Builder builder = DatastoreOptions.newBuilder()
.setProjectId(this.projectId)
.setRetrySettings(getRetrySettings())//the magic happens here
.setHeaderProvider(new UserAgentHeaderProvider(this.getClass()))
.setCredentials(this.credentials);
if (namespace != null) {
builder.setNamespace(namespace);
}

	if (this.host != null) {
		builder.setHost(this.host);
	}
	return builder.build().getService();
}`
@elefeint
Copy link
Contributor

elefeint commented Feb 5, 2021

@NorthernDarkness Would the retry properties need to be unique for each namespace, or global across the application?

Either way would involve adding properties to GcpDatastoreProperties (either simple properties or a map of them) and using them in GcpDatastoreAutoConfiguration.

Would you be interested in contributing a PR for this?

@NorthernDarkness
Copy link
Author

This looks natural to have retry settings global for all namespaces because a client is not aware which specific cluster in google data center handles a specific namespace request, so no reason to control it separately.

This change certainly requires a new items in GcpDatastoreProperties(or probably just create a common RetryProperties to share with other GCP products as retry settings are basically the same across all GCP native clients )

I can try to make a draft and push it later next week maybe.

@meltsufin
Copy link
Contributor

One thing we can do is expose DatastoreOptions.Builder that Datastore getDatastore(String namespace) uses as a bean that can be overwritten. Alternatively, we can create a factory interface that takes a namespace and produces a Datastore object.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants