-
Notifications
You must be signed in to change notification settings - Fork 73
Fix for occasional duplicate key errors on session create or update #711
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
Fix for occasional duplicate key errors on session create or update #711
Conversation
...jito/service/security/user/session/CustomCreateSessionAttributeInsertQueryConfiguration.java
Outdated
Show resolved
Hide resolved
* to change the Create Session Attribute query to use an MySQL UPDATE command to update the ATTRIBUTE_BYTES | ||
* of the existing row if a duplicate key is encountered. | ||
* | ||
* <b>NOTE:</b>This custom insert query should only be used with a MySQL database. |
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.
only be used with a MySQL database
, can this be made explicit with a @Conditional
?
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.
I've pushed an update containing a custom condition (MySQLDatabaseCondition) that checks the prefix of the spring.datasource.url
property, if the prefix matches "jdbc:mysql:" the condition passes
|
||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
String datasourceUrl = context.getEnvironment().getProperty("spring.datasource.url"); |
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.
could DBUtils
be reused/merged in some ways? not super important but if we can avoid duplication and have a single place with that logic.
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.
I missed the DBUtils class, I don't think it can be merged into the condition as the condition logic is executed before the DBUtils bean is initialised but I could remove the conditional and autowire it into the CreateSessionAttributeInsertQuery bean. I'll update to execute the check in there and if there's not a mysql db then we'll log a warning stating the custom query has not been set.
…y errors on session creation/update Fixed startup failures Updated implementation to extend JdbcHttpSessionConfiguration Added MySQLDatabaseCondition class conditional Fixing build failures Use DBUtils to check database type Use default table name if spring.session.jdbc.table-name is not set
…y errors on session creation/update (box#711)
Updates the CreateSessionAttribute query to perform an UPDATE on the attribute bytes if a duplicate session id is found, this is a workaround for an issue in spring session where concurrent requests adding the same attribute result in a duplicate key violation.
See spring-projects/spring-session#1213 for further details.