fixing race conditions
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120308 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7f5e0fc426
commit
459d95c8d5
|
@ -115,23 +115,23 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
Long now = Calendar.getInstance().getTimeInMillis();
|
||||
Long lastCheckTimestamp = fallbackLastCheck.get(scope);
|
||||
logger.debug("Last check for scope {} was {}", scope, lastCheckTimestamp);
|
||||
|
||||
if( (lastCheckTimestamp + FALLBACK_RETRY_TIME) <= now ){
|
||||
logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.",
|
||||
boolean myTurn = false;
|
||||
synchronized (accountingPersistenceBackends) {
|
||||
if( (lastCheckTimestamp + FALLBACK_RETRY_TIME) <= now ){
|
||||
logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.",
|
||||
AccountingPersistenceBackend.class.getSimpleName(), scope, actual.getClass().getSimpleName());
|
||||
|
||||
logger.trace("Renewing Last check Timestamp. The next one will be {}", now);
|
||||
fallbackLastCheck.put(scope, now);
|
||||
myTurn=true;
|
||||
logger.debug("I win. It is my turn to rediscover {} in scope {}",
|
||||
AccountingPersistenceBackend.class.getSimpleName(), scope);
|
||||
}
|
||||
}
|
||||
|
||||
if(myTurn){
|
||||
AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope);
|
||||
|
||||
synchronized (accountingPersistenceBackends) {
|
||||
logger.trace("Renewing Last check Timestamp. The next one will be {}", now);
|
||||
Long reCheckTimestamp = fallbackLastCheck.get(scope);
|
||||
if(lastCheckTimestamp.compareTo(reCheckTimestamp)!=0){
|
||||
// Someone else arrived here before. Stopping to try to
|
||||
logger.debug("Someone else arrived here before. Stopping to try to rediscover AccountingPersistenceBackend and getting the current");
|
||||
return accountingPersistenceBackends.get(scope);
|
||||
}
|
||||
|
||||
fallbackLastCheck.put(scope, now);
|
||||
if(discoveredPersistenceBackend!=null){
|
||||
/*
|
||||
* Passing the aggregator to the new AccountingPersistenceBackend
|
||||
|
|
Loading…
Reference in New Issue