Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property quarkus.hibernate-orm.multitenant-schema-datasource is apparently pointless #18564

Closed
yrodiere opened this issue Jul 9, 2021 · 4 comments · Fixed by #40680
Closed
Labels
Milestone

Comments

@yrodiere
Copy link
Member

yrodiere commented Jul 9, 2021

Description

quarkus.hibernate-orm.multitenant-schema-datasource seems to have the exact same purpose as quarkus.hibernate-orm.datasource: it sets the (single) datasource to be used for a given persistence unit.

The only difference I could see is that quarkus.hibernate-orm.multitenant-schema-datasource can only be used in a multi-tenancy scenario. All I can find in the documentation is this example, which isn't clear about what the purpose of the property is exactly:

# You could use a non-default datasource by using the following setting
# quarkus.hibernate-orm.multitenant-schema-datasource=other

There are apparently no tests involving the property multitenant-schema-datasource.

Also, judging from the code, unless multitenant-schema-datasource is set, the datasource is duplicated for each tenant:

    private static AgroalDataSource tenantDataSource(String dataSourceName, String tenantId, MultiTenancyStrategy strategy,
            String multiTenancySchemaDataSourceName) {
        if (strategy != MultiTenancyStrategy.SCHEMA) {
            return Arc.container().instance(AgroalDataSource.class, new DataSource.DataSourceLiteral(tenantId)).get();
        }

        if (multiTenancySchemaDataSourceName == null) {
            AgroalDataSource dataSource = getDataSource(dataSourceName);
            // HERE we duplicate the datasource (?)
            return createFrom(dataSource.getConfiguration());
        }

        return getDataSource(multiTenancySchemaDataSourceName);
    }

However, this difference is not documented, seems buggy (the created datasource is never closed) and I'm not sure what the point of copying the datasource even is?

Implementation ideas

We should either clarify the documentation, or fix the behavior and deprecate the property multitenant-schema-datasource for removal.

@yrodiere yrodiere added kind/enhancement New feature or request area/hibernate-orm Hibernate ORM labels Jul 9, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 9, 2021

/cc @Sanne, @gsmet

@yrodiere
Copy link
Member Author

yrodiere commented Jul 9, 2021

@gsmet I see you worked on this when you introduced multitenancy support with multiple persistence units (aabda57). Does this ring a bell?

@yrodiere yrodiere changed the title quarkus.hibernate-orm.multitenant-schema-datasource is apparently pointless Property quarkus.hibernate-orm.multitenant-schema-datasource is apparently pointless Jul 9, 2021
@yrodiere
Copy link
Member Author

Bump:

@gsmet I see you worked on this when you introduced multitenancy support with multiple persistence units (aabda57). Does this ring a bell?

@yrodiere
Copy link
Member Author

I found one explanation here: https://github.com/quarkusio/quarkus/pull/8545/files#diff-0ce52774c4cc571f0dd21946d42a8133b5a6e82ef34f93494b969fc94e06e1bc

This could be helpful if you for example want to separate the default database from the one used for tenant schemas. I would prefer to leave it as it is, to allow separation in case this is needed. We also have a good default if the user does not set it. But there is now still the option to separate the tenant stuff from the default data source.

This doesn't explain why someone would use quarkus.hibernate-orm.multitenant-schema-datasource rather than simply quarkus.hibernate-orm.datasource, though...

yrodiere added a commit to yrodiere/quarkus that referenced this issue May 16, 2024
There are no tests involving this configuration property.

`quarkus.hibernate-orm.datasource` serves the exact same purpose and is
more standardized and better handled (e.g. in Dev UI).

See quarkusio#18564
yrodiere added a commit to yrodiere/quarkus that referenced this issue May 16, 2024
There are no tests involving this configuration property.

`quarkus.hibernate-orm.datasource` serves the exact same purpose and is
more standardized and better handled (e.g. in Dev UI).

See quarkusio#18564
@quarkus-bot quarkus-bot bot added this to the 3.12 - main milestone May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant