Enlist JPA transaction in JpaMapStorageProvider.getStorage#11328
Enlist JPA transaction in JpaMapStorageProvider.getStorage#11328hmlnarik merged 1 commit intokeycloak:mainfrom
Conversation
There was a problem hiding this comment.
Please use the full inline class form, MapStorage is intentionally not marked as @FunctionalInterface as there might be methods added in the future
There was a problem hiding this comment.
Just followed what we have in LDAP:
There was a problem hiding this comment.
Thanks for spotting this one, I missed it there. Could you please file an issue for the LDAP and fix only the JPA code in this PR?
cc: @ahus1
|
Summary of changes
|
|
Testsuite results The base testsuite was run with all currently available Map JPA providers configured. Only one test is currently failing in this setting: All other tests from the same class run fine and have the |
eaf6bab to
861fce3
Compare
|
Testsuite update: I did previously run the testsuite with all JPA Map storages available in First I had to change things a little bit because I was hitting a Basically the code was trying to load the I had to create a new version of So the results are as follows:
|
|
@sguilhen - as a workaround until the reason for the transient instance has been identified, please try the following workaround. It allowed me to run I'll continue to analyze the reason. Another workaround would be to add cascade to |
|
@ahus1 This does indeed fix the tests I've listed, but introduces regressions in other tests, such as This all happens when trying to remove a group, and then several of tests fail after this one becaue the group wasn't properly removed from the DB. So I think we need to find a different way, unfortunately. |
861fce3 to
523f4ce
Compare
Due to the |
523f4ce to
86e5b23
Compare
|
I continued my analysis today. I manged to fix two issues, still some problems remain (e5bb5f6fcfe4d6c36c9b29dae08a70afa78fce3a):
More debugging ahead... |
|
Debugging continued until the results improved. See aece8e1. Key changes compared to the previous commit:
Let's discuss later today how to split these changes to different PRs or if you want to have separate commits in this PR for this. |
Ok, so as we've discussed today I've tried both approaches and # 1 falls short as some tests started to hang. I've then switched to # 2 and included your |
|
I agree with #2 - the |
|
@sguilhen - to elaborate on Hynek's comment: we discussed it in today's team meeting, and agreed that the new flush listener is the way to go, also as the smaller solution didn't work. With the LDAP test already addressed, I assume that after a rebase and with the new flush listener the tests should pass, and this PR is then ready for review & merge. |
|
@ahus1 Thanks! I will incorporate the |
86e5b23 to
456b587
Compare
ahus1
left a comment
There was a problem hiding this comment.
Thanks for preparing this PR, looks good to me!
|
Important note: with this change Keycloak doesn't start anymore with CockroachDB: |
|
@sguilhen - IMHO that shouldn't keep us from merging this. I'd be happy to tackle that in a separate ticket after this has been merged. |
There was a problem hiding this comment.
Should this be under synchronized guard, like e.g. here?
There was a problem hiding this comment.
I'm not sure about this one. I think this boils down to the question: can getStorage be called concurrently within the same session?
No idea, to be honest. I can see the table is created by Liquibase and right after that we get the error. |
456b587 to
5e97629
Compare
|
@hmlnarik So @ahus1 and I were investigating a bit and we think this is what is going on with CRDB:
Now, what seems to be happening is this: once the JPA tx is started as part of the There seems to be some further evidence that this is happening: If I re-start the server after the first failure, CRDB no longer complains about the So the bottom line is that for CRDB to work with these "longer" JPA transactions, the schema needs to be processed beforehand. Perhaps have some code that examines the config to determine which areas are using the JPA Map storage and pre-process all of those. Or require people to run the Liquibase changelogs manually before running Keycloak, but I'm not too keen on this one. |
Thank you for the analysis, it sounds likely. Would it be then possible to introduce a changelog aggregating all changelog files ( |
Yep, I think that will be the way to workaround this for the moment. I will look into it. |
Closes keycloak#11230 Co-authored-by: Alexander Schwartz <[email protected]>
5e97629 to
65b9c41
Compare
|
@hmlnarik @ahus1 Updated the PR, so now the Only downside of this approach is that we can end up creating tables that won't ever be used if some area is not configured to use the JPA Map storage, but I think it is the easiest solution for the moment. We can re-evaluate if we can do something smarter in the future. |
Closes #11230