Closed
Description
In what version(s) of Spring Integration are you seeing this issue?
For example:
5.5.14
Describe the bug
When using DefaultLockRepository The following error is shown in postgres log under high load:
STATEMENT: INSERT INTO INT_LOCK (REGION, LOCK_KEY, CLIENT_ID, CREATED_DATE) VALUES ($1, $2, $3, $4)
ERROR: duplicate key value violates unique constraint "int_lock_pk"
To Reproduce
Use DefaultLockRepository with high load with postgres
Expected behavior
No error
** Workaround **
We use below workaround, but would be nice if this can be solved somewhere in spring integration itself:
DefaultLockRepository repository = new DefaultLockRepository(datasource) {
@Override
public void afterPropertiesSet() {
// Postgres specific fix to have no 'duplicate key value violates unique constraint "int_lock_pk"' in the log.
if(asList(environment.getActiveProfiles()).contains("postgres")) {
addOnConflictDoNothing();
}
super.afterPropertiesSet();
}
private void addOnConflictDoNothing() {
String fieldName = "insertQuery";
try {
Field field = DefaultLockRepository.class.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(this, field.get(this) + " ON CONFLICT DO NOTHING");
} catch(Exception e) {
log.warn("Unable to change spring integration '" + fieldName + "' query", e);
}
}
};
return repository;
}