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 now = Calendar.getInstance().getTimeInMillis();
|
||||||
Long lastCheckTimestamp = fallbackLastCheck.get(scope);
|
Long lastCheckTimestamp = fallbackLastCheck.get(scope);
|
||||||
logger.debug("Last check for scope {} was {}", scope, lastCheckTimestamp);
|
logger.debug("Last check for scope {} was {}", scope, lastCheckTimestamp);
|
||||||
|
boolean myTurn = false;
|
||||||
if( (lastCheckTimestamp + FALLBACK_RETRY_TIME) <= now ){
|
synchronized (accountingPersistenceBackends) {
|
||||||
logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.",
|
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());
|
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);
|
AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope);
|
||||||
|
|
||||||
synchronized (accountingPersistenceBackends) {
|
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){
|
if(discoveredPersistenceBackend!=null){
|
||||||
/*
|
/*
|
||||||
* Passing the aggregator to the new AccountingPersistenceBackend
|
* Passing the aggregator to the new AccountingPersistenceBackend
|
||||||
|
|
Loading…
Reference in New Issue