multi tenancy aware sequences#2305
Conversation
This test case generates following stack: ```java java.lang.NullPointerException at io.ebean.config.dbplatform.SequenceIdGenerator.getMoreIds(SequenceIdGenerator.java:158) at io.ebean.config.dbplatform.SequenceIdGenerator.loadMore(SequenceIdGenerator.java:117) at io.ebean.config.dbplatform.SequenceIdGenerator.nextId(SequenceIdGenerator.java:100) at io.ebeaninternal.server.deploy.BeanDescriptor.nextId(BeanDescriptor.java:1541) at io.ebeaninternal.server.core.DefaultServer.nextId(DefaultServer.java:851) at org.tests.idkeys.TestSequenceMultiTenant.test_multi_tenant_sequences(TestSequenceMultiTenant.java:35) ... ```
…erator instead of DataSource To support multi tenancy for sequences a delegator is implemented in the BeanDescriptorManager
| } | ||
|
|
||
| private PlatformIdGenerator get() { | ||
| return map.computeIfAbsent(dataSourceSupplier.getDataSource(), k -> create()); |
There was a problem hiding this comment.
FI: This works good for a DS-supplier that supplies different dataSources for different tenants (As it is done in TenantMode.DB/DB_WITH_MASTER - which is our use case @FOCONIS) - for other tenant modes like SCHEMA or CATALOG it may cause other problems. Maybe in a schema/catalog environment this should somehow configurable, where the Sequence lives.
|
Hmmm, my initial thought is that this looks problematic. |
Hello @rbygrave , We have tried to generate the schemas, when there is a An exception is raised in 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 |
| } | ||
|
|
||
| private static DataSource createDataSource(Object tenantId) { | ||
| private Database setupSchema() { |
There was a problem hiding this comment.
With the support of @rPraml we were able to write a failing test for tenantmode schema. THe main question seems to be, were the sequence schould live.
…cy-aware-sequences
should
```java
UserContext.set("5711", "2");
assertEquals(1L, db.nextId(GenKeySeqA.class));
```
or
```java
UserContext.set("5711", "2");
assertEquals(3L, db.nextId(GenKeySeqA.class));
```
Does the sequence live in tenant schema or globally?
…cy-aware-sequences
|
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. |
|
Hi @rbygrave we will not pursue this topic any further as we do not need multi-tenant sequences. |
Hey Rob,
the
TestSequenceMultiTenantshows the problem with multi tenancy. To address this problem we implemented a delegator in theBeanDescriptorManager.There is an older attempt of @rPraml where he uses
TenantDataSourceProviderandCurrentTenantProviderand extends them to theSequenceIdGenerator:FOCONIS@2de1f21
Do you have any other suggestions or is this simple attempt sufficient?