-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Provide database specific JdbcIndexedSessionRepository customizers #1726
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
502333b
to
e4862f2
Compare
@jkuipers, since you also went at depth with this issue, I'd appreciate your feedback on the changes proposed by this PR? |
This commit provides JdbcIndexedSessionRepository customizers for the following SQL dialects: - PostgreSQL - MySQL (also used by MariaDB) - SQL Server - IBM DB2 - Oracle These customizers are intended to address the concurrency issues occurring on insert of new session attribute by applying SQL dialect specific SQL upsert/merge statement instead of a generic insert. Closes: spring-projects#1213
At present, the SQL statement used to insert a session attribute record contains a nested select statement that verifies the existence of parent record in the session table. Such approach can be susceptible to deadlocks on certain RDMBSs. This commit optimizes the SQL statement used to insert session attribute so that it doesn't perform a nested select statement. Closes: spring-projects#1550
This commit reduces the JDBC integration tests to only single (latest) version per RDBMS vendor, due to a growing number of integration tests. Additionally, the configuration of most containers is simplified due to improved defaults within the Testcontainers library.
Hey Vedran, I just had a look (sorry, wasn't able to get to this earlier). I like the approach that there can now be different SQL for different DBMSs. I also noticed a commit that makes the code use the session's primary key again instead of a nested select by session ID, which I think is the right approach. On another note: the new MS SQL Server SQL is I think semantically equivalent to what I came up with in my own fork. Both my version and the one currently on master still sporadically cause deadlocks in SQL Server, so even though it's a big improvement over the old code, the problem isn't solved 100% yet. |
Thanks for following up on this @jkuipers, good to hear you're seeing these changes as an improvement in practice. 👍 Regarding the remaining reasons for deadlocks, they are IMO due to expired session clean-up job. See #838 - this is something that to my knowledge affects MySQL/MariaDB and SQL Server users. I opened #1739 yesterday to take a closer look at improving the clean-up job, so feel free to track that one as well. |
Using my tests, after updating to a snapshot of Spring Session and registering the SqlServerJdbcIndexedSessionRepositoryCustomizer as a bean, I can trigger the deadlock by simply creating several sessions in parallel still. I therefore do not think that this is related to the cleanup, I don't think that cleanup ever runs during these tests. I've examined the problem yesterday evening. It appears that for some reason, the combination of INSERTing a new session and then using the MERGE statement to insert the corresponding session attributes can trigger deadlocks in MS SQL Server. I tried several things first like making the primary key clustered, changing isolation levels and some other things that didn't help. |
Pardon which release was this merged into? I'd like to try the MySQL specific customizations, but can't quite see whether a version is out that includes them. I'm confused a bit because while I used the -- The clean up job deadlocks, like #838, but requests timeout for a lock wait on updating the SPRING_SESSION too, which I think is related to the clean up deadlocking.
|
@dlamblin This will be a part of upcoming Spring Session |
This PR addresses several
JdbcIndexedSessionRepository
concerns.This first commit of this PR provides
JdbcIndexedSessionRepository
customizers for the following SQL dialects:These customizers are intended to address the concurrency issues occurring on insert of new session attribute by applying SQL dialect specific SQL upsert/merge statement instead of a generic insert.
This closes #1213.
The second commit optimizes the SQL statement used to insert session attribute so that it doesn't perform a nested select statement.
This closes #1550.
Final commit reduces the JDBC integration tests to only single (latest) version per RDBMS vendor, due to a growing number of integration tests. Additionally, the configuration of most containers is simplified due to improved defaults within the Testcontainers library.