-
Notifications
You must be signed in to change notification settings - Fork 7.9k
KEYCLOAK-18842: deleteExpiredClientSessions very slow on MariaDB #8415
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
Conversation
vramik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @rmartinc for the changes. The PR looks very good to me. I wonder if we should also add a note to documentation that it's now possible to override specific query depending the database.
Keycloak allows adding custom Jpa Entities to the keycloak data model: https://www.keycloak.org/docs/latest/server_development/index.html#_extensions_jpa (but it is marked as unsupported in docs) and if I understand correctly this feature could be also applicable to these custom entities.
|
Thanks @rmartinc for the contribution! |
| return em; | ||
| } | ||
|
|
||
| private void addSpecificNamedQueries(KeycloakSession session, Connection connection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hmlnarik @rmartinc We should avoid whenever possible performing blocking/costly operations during startup. Created https://issues.redhat.com/browse/KEYCLOAK-19274.
Also, would be possible to just use the connection metadata to obtain the database type rather than querying the liquibase provider? Asking because Liquibase operations are usually costly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Should be done in augmentation. I wonder if this is / should be done for the whole quarkus/runtime/src/main/java/org/keycloak/connections/jpa/QuarkusJpaConnectionProviderFactory.java?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ... There are other parts of the code that we can move to build time. For instance, anything that touches upgrade/migration should happen when re-augmenting the server. That could be done once (or manually triggered by the user) and just leave the very necessary bits to the runtime.
Issue: https://issues.redhat.com/browse/KEYCLOAK-18842
The
deleteExpiredClientSessionsquery is removed from the annotation and it's added via property files calling theaddNamedQuerymethod at initializing the JPA provider (quarkus or wildfly). The files are placed inside the model-jpa jar and there should be aqueries-default.propertiesand it can be overloaded by aqueries-<dbtype>.propertiesfile (the specific file can contain only part of the needed queries). Right now the files just contain the delete query in the two forms, jpql for the default file and native for mysql/mariadb databases.When HHH-14796 is fixed the annotation for
deleteExpiredClientSessionscan be restored and the default file will be unnecessary, the default annotation queries will be replaced using the ones in the specific database file directly.Comments are welcomed! @hmlnarik take a look to the PR when you have time.
Thanks!