Add a back-off period when replacing cache entries fails
Closes #28388 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
parent
63e7523a6d
commit
355901dfd8
2 changed files with 65 additions and 40 deletions
|
@ -105,6 +105,7 @@ public class EmbeddedCachesChangesPerformer<K, V extends SessionEntity> implemen
|
|||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debugf("Replace failed for entity: %s, old version %s, new version %s. Will try again", key, oldVersion.getVersion(), newVersionEntity.getVersion());
|
||||
}
|
||||
backoff(iteration);
|
||||
|
||||
oldVersion = cache.get(key);
|
||||
|
||||
|
@ -129,6 +130,18 @@ public class EmbeddedCachesChangesPerformer<K, V extends SessionEntity> implemen
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait a random amount of time to avoid a conflict with other concurrent actors on the next attempt.
|
||||
*/
|
||||
private static void backoff(int iteration) {
|
||||
try {
|
||||
Thread.sleep(new Random().nextInt(iteration));
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private SessionEntityWrapper<V> generateNewVersionAndWrapEntity(V entity, Map<String, String> localMetadata) {
|
||||
return new SessionEntityWrapper<>(localMetadata, entity);
|
||||
}
|
||||
|
|
|
@ -254,6 +254,7 @@ public class InfinispanChangelogBasedTransaction<K, V extends SessionEntity> ext
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debugf("Replace failed for entity: %s, old version %s, new version %s. Will try again", key, oldVersion.getVersion(), newVersionEntity.getVersion());
|
||||
}
|
||||
backoff(iteration);
|
||||
|
||||
oldVersion = cache.get(key);
|
||||
|
||||
|
@ -278,6 +279,17 @@ public class InfinispanChangelogBasedTransaction<K, V extends SessionEntity> ext
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait a random amount of time to avoid a conflict with other concurrent actors on the next attempt.
|
||||
*/
|
||||
private static void backoff(int iteration) {
|
||||
try {
|
||||
Thread.sleep(new Random().nextInt(iteration));
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollbackImpl() {
|
||||
|
|
Loading…
Reference in a new issue