Offline sessions lazy loaded by default #9619
martin-kanis
started this conversation in
Ideas
Replies: 1 comment
-
|
@martin-kanis The proposal looks good to me. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In #9414 I switched the default behavior regarding offline sessions preloading. An offline session is lazy loaded from a database when requested. The previous behavior where offline sessions were preloaded from the database caused problems with slow server startup in deployments with many offline sessions.
Required changes
To keep Keycloak working with lazy loading of offline sessions I needed to change several things that are described below.
Search offline sessions by broker session ID
We can obtain stream of offline sessions filtered by
userId,brokerUserIdorbrokerSessionIdin current code base. However, thePersistentUserSessionEntityhas onlyuserIdas a property (column) from those three fields. The rest is encoded as JSON in data property (column). That means, we need to figure out how to searchPersistentUserSessionEntityby those two fields.Search by
brokerUserIdcan be accomplished in two steps:UserModelby searchable attributesUserModel.IDP_ALIASandUserModel.IDP_USER_IDUserModelSearch by
brokerSessionIdis more problematic though. There is no searchablebrokerSessionIdfield/attribute inUserModel. Looking at usages from the current code base, it's used only from the back channel logout. So here is how I changed the behavior. We can first leveragebrokerUserIdfrom a logout token to obtain offline user sessions and then usebrokerSessionIdfrom the token to filter down obtained offline user sessions which will be then revoked.Enable preloading in crossDC tests
One of the CrossDC tests in the base testsuite tests whether the offline sessions were correctly preloaded and then distributed to another DC. This test requires the preloading to be enabled. However, I only managed to turn on preloading globally for all CrossDC tests.
The scenario where the offline session preloading is turned off in CrossDC environment is covered by model tests, where I added couple of tests.
Queries for offline sessions by delegated clients from external storage
Queries by clients Id for clients delegated from external storage didn't work because we put "external" as a client Id for
PersistentClientSessionEntity. Therefore I needed to add some logic toJpaUserSessionPersisterProviderand introduce new queries that search byexternalClientIdandclientStorageProvider.@mposolda @stianst I would be interested in your opinions on this. Feedback from others is also welcomed. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions