ebean
ebean copied to clipboard
multi tenancy aware sequences
Hey Rob,
the TestSequenceMultiTenant shows the problem with multi tenancy. To address this problem we implemented a delegator in the BeanDescriptorManager.
There is an older attempt of @rPraml where he uses TenantDataSourceProvider and CurrentTenantProvider and extends them to the SequenceIdGenerator:
https://github.com/FOCONIS/ebean/commit/2de1f215bbb164eef21b3f5cbe9f3d8475a78353
Do you have any other suggestions or is this simple attempt sufficient?
Hmmm, my initial thought is that this looks problematic.
Hmmm, my initial thought is that this looks problematic.
Hello @rbygrave ,
we tried to provide a test case for sequences in TenantMode.SCHEMA:
https://github.com/FOCONIS/ebean/commit/109958a1339f76f8dc336fc2ba29d7ad6ea78c45
We have tried to generate the schemas, when there is a UserContext-switch and provide the new schema.
An exception is raised in io.ebean.config.dbplatform.SequenceIdGenerator.getMoreIds(int) in line 158. To be more precise the exception comes from io.ebeaninternal.server.core.MultiTenantDbSchemaSupplier.SchemaDataSource.getConnection() where the schema is set for the connection.
This seems correct for us and may address the issue @rPraml sees.
But to dive deeper into this topic the test has to run over the problem that no schema seems to be generated.
After multiple hours of debugging and searching we are at our wits' end. Do you have an idea how to test TenantMode.SCHEMA with multiple schemas?
Statusupdate: We know, that sequences in a multi-tenant environment are problematic as the sequence may be stored in the wrong database. We do NOT use them. This PR is not part of our fork.
@rbygrave I think the problem still exists... If you decide to close this PR, then it should be mentioned as limitation in multi-tenant setups with one DB/schema per tenant.