Changed the way to retrieve accounting persistence configuration due to deadlock which happen only in IC node
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120277 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8e527e0325
commit
54f2a86e07
|
@ -30,14 +30,14 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
|
||||
private static String fallbackLocation;
|
||||
|
||||
private static Map<String, AccountingPersistenceBackend> persistencePersistenceBackends;
|
||||
private static Map<String, AccountingPersistenceBackend> accountingPersistenceBackends;
|
||||
|
||||
public static final long FALLBACK_RETRY_TIME = 1000*60*10; // 10 min
|
||||
|
||||
protected static Map<String,Long> fallbackLastCheck;
|
||||
|
||||
static {
|
||||
persistencePersistenceBackends = new HashMap<String, AccountingPersistenceBackend>();
|
||||
accountingPersistenceBackends = new HashMap<String, AccountingPersistenceBackend>();
|
||||
fallbackLastCheck = new HashMap<String, Long>();
|
||||
}
|
||||
|
||||
|
@ -65,9 +65,6 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
protected static AccountingPersistenceBackend discoverAccountingPersistenceBackend(String scope){
|
||||
ServiceLoader<AccountingPersistenceBackend> serviceLoader = ServiceLoader.load(AccountingPersistenceBackend.class);
|
||||
for (AccountingPersistenceBackend foundPersistence : serviceLoader) {
|
||||
if(foundPersistence instanceof FallbackPersistence){
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
String foundPersistenceClassName = foundPersistence.getClass().getSimpleName();
|
||||
logger.debug("Testing {}", foundPersistenceClassName);
|
||||
|
@ -114,18 +111,16 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
return createFallback(null);
|
||||
}
|
||||
|
||||
AccountingPersistenceBackend persistence = persistencePersistenceBackends.get(scope);
|
||||
AccountingPersistenceBackend persistence = accountingPersistenceBackends.get(scope);
|
||||
if(persistence==null){
|
||||
persistence = discoverAccountingPersistenceBackend(scope);
|
||||
|
||||
if(persistence==null){
|
||||
logger.warn("Unable to find a usable {}. {} will be used.", AccountingPersistenceBackend.class.getSimpleName(), FallbackPersistence.class.getSimpleName());
|
||||
long now = Calendar.getInstance().getTimeInMillis();
|
||||
fallbackLastCheck.put(scope, now);
|
||||
persistence = createFallback(scope);
|
||||
}
|
||||
|
||||
persistencePersistenceBackends.put(scope, persistence);
|
||||
accountingPersistenceBackends.put(scope, persistence);
|
||||
|
||||
} else {
|
||||
if(persistence instanceof FallbackPersistence && fallbackLastCheck.get(scope)!=null){
|
||||
|
@ -137,9 +132,13 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
|
||||
AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope);
|
||||
if(discoveredPersistenceBackend!=null){
|
||||
// Passing the aggregator to the new AccountingPersistenceBackend
|
||||
// so that the buffered records will be persisted with the new method
|
||||
discoveredPersistenceBackend.setAggregationScheduler(persistence.getAggregationScheduler());
|
||||
|
||||
// Removing timestamp wich is no more needed
|
||||
fallbackLastCheck.remove(scope);
|
||||
persistencePersistenceBackends.put(scope, discoveredPersistenceBackend);
|
||||
accountingPersistenceBackends.put(scope, discoveredPersistenceBackend);
|
||||
try {
|
||||
persistence.close();
|
||||
} catch (Exception e) {
|
||||
|
@ -148,7 +147,9 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
discoveredPersistenceBackend.getClass().getSimpleName(), e);
|
||||
}
|
||||
persistence = discoveredPersistenceBackend;
|
||||
|
||||
}else{
|
||||
// Renewing timestamp
|
||||
fallbackLastCheck.put(scope, now);
|
||||
}
|
||||
}
|
||||
|
@ -164,8 +165,8 @@ public abstract class AccountingPersistenceBackendFactory {
|
|||
* @throws Exception
|
||||
*/
|
||||
public static void flushAll(long timeout, TimeUnit timeUnit) {
|
||||
for(String scope : persistencePersistenceBackends.keySet()){
|
||||
AccountingPersistenceBackend apb = persistencePersistenceBackends.get(scope);
|
||||
for(String scope : accountingPersistenceBackends.keySet()){
|
||||
AccountingPersistenceBackend apb = accountingPersistenceBackends.get(scope);
|
||||
try {
|
||||
logger.debug("Flushing records in scope {}", scope);
|
||||
apb.flush(timeout, timeUnit);
|
||||
|
|
Loading…
Reference in New Issue