Retry cache return only if in DB
@@ -105,19 +105,25 @@ protected CacheEntry evict() {
public CacheEntry get(CacheEntry key) {
CacheEntry entry = super.get(key);
try {
- RetryCacheEntry existInDB = EntityManager.find(RetryCacheEntry.Finder.ByClientIdAndCallId, key.getClientId(), key.getCallId());
+ RetryCacheEntry existInDB = EntityManager.find(RetryCacheEntry.Finder.ByClientIdAndCallId, key.getClientId(), key.
+ getCallId());
if (existInDB != null && existInDB.getExpirationTime() > timer.now()) {
byte state = existInDB.getState() == CacheEntry.INPROGRESS ? CacheEntry.FAILED : existInDB.getState();
- RetryCacheDistributed.CacheEntry exist = new CacheEntryWithPayload(existInDB.getClientId(), existInDB.getCallId(), existInDB.getPayload(), existInDB.getExpirationTime(),state);
+ RetryCacheDistributed.CacheEntry exist = new CacheEntryWithPayload(existInDB.getClientId(), existInDB.
+ getCallId(), existInDB.getPayload(), existInDB.getExpirationTime(), state);
if (entry == null) {
super.put(exist, accessExpirationPeriod);
entry = exist;
}
existInDB.setExpirationTime(entry.getExpirationTime());
EntityManager.update(existInDB);
+ } else if (entry != null) {
+ super.remove(entry);
+ entry = null;
}
} catch (StorageException | TransactionContextException ex) {
LOG.error("failed to get or update entry in DB", ex);
+ entry = null;
}
return entry;
}
