spring-attic / spring-cloud-gcp

Integration for Google Cloud Platform APIs with Spring
Apache License 2.0
704 stars 693 forks source link

Multiple active namespaces for datastore #2640

Closed amiyalenka82 closed 3 years ago

amiyalenka82 commented 3 years ago

In the earlier issues: https://github.com/spring-cloud/spring-cloud-gcp/issues/1289, https://github.com/spring-cloud/spring-cloud-gcp/issues/2204

It says multitenancy is fixed but I still see issues,

DatastoreNamespaceProvider only overrides the namespace provided in application.properties file. So, at a particular time, you have only one namespace available. How can I actually work on multiple namespaces? I can have multiple threads running in the same application and using different namespaces simultaneously.

dzou commented 3 years ago

Thanks for the report.

Which part of the Datastore API are you using? (i.e. are you using DatastoreTemplate or the spring data repository classes?)

dzou commented 3 years ago

@meltsufin -- Should we revisit the discussion about ThreadLocal context mentioned in #2204?

amiyalenka82 commented 3 years ago

I am using Autoconfiguration, it creates the DatastoreTemplate. I am referring the below documentation to implement multitenancy,

https://cloud.spring.io/spring-cloud-static/spring-cloud-gcp/1.2.0.M2/reference/html/spring-cloud-gcp.html#_partitioning_data_by_namespace

public interface DatastoreNamespaceProvider extends Supplier { }

DatastoreNamespaceProvider extends the Supplier with String type, it is only overriding the namespace provided in application.properties file. This helps if we are doing CRUD operations against only one namespace at a given time.

dzou commented 3 years ago

I see. It looks like another user posted a solution that may work; if you implement the DatastoreNamespaceProvider accessing state from ThreadLocal then you can have it set the namespace dynamically: https://github.com/spring-cloud/spring-cloud-gcp/issues/2204#issuecomment-780524911

We can improve the API on our end so you don't have to specify a default and document this better.

dzou commented 3 years ago

I copied over your issue to our 2.0.0 repo here: https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/317

We're planning for all of our new feature requests and updates to go into the 2.0.0 version.