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:
Luca Frosini 2015-11-13 11:24:57 +00:00
parent 8e527e0325
commit 54f2a86e07
1 changed files with 13 additions and 12 deletions

View File

@ -30,14 +30,14 @@ public abstract class AccountingPersistenceBackendFactory {
private static String fallbackLocation; 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 public static final long FALLBACK_RETRY_TIME = 1000*60*10; // 10 min
protected static Map<String,Long> fallbackLastCheck; protected static Map<String,Long> fallbackLastCheck;
static { static {
persistencePersistenceBackends = new HashMap<String, AccountingPersistenceBackend>(); accountingPersistenceBackends = new HashMap<String, AccountingPersistenceBackend>();
fallbackLastCheck = new HashMap<String, Long>(); fallbackLastCheck = new HashMap<String, Long>();
} }
@ -65,9 +65,6 @@ public abstract class AccountingPersistenceBackendFactory {
protected static AccountingPersistenceBackend discoverAccountingPersistenceBackend(String scope){ protected static AccountingPersistenceBackend discoverAccountingPersistenceBackend(String scope){
ServiceLoader<AccountingPersistenceBackend> serviceLoader = ServiceLoader.load(AccountingPersistenceBackend.class); ServiceLoader<AccountingPersistenceBackend> serviceLoader = ServiceLoader.load(AccountingPersistenceBackend.class);
for (AccountingPersistenceBackend foundPersistence : serviceLoader) { for (AccountingPersistenceBackend foundPersistence : serviceLoader) {
if(foundPersistence instanceof FallbackPersistence){
continue;
}
try { try {
String foundPersistenceClassName = foundPersistence.getClass().getSimpleName(); String foundPersistenceClassName = foundPersistence.getClass().getSimpleName();
logger.debug("Testing {}", foundPersistenceClassName); logger.debug("Testing {}", foundPersistenceClassName);
@ -114,18 +111,16 @@ public abstract class AccountingPersistenceBackendFactory {
return createFallback(null); return createFallback(null);
} }
AccountingPersistenceBackend persistence = persistencePersistenceBackends.get(scope); AccountingPersistenceBackend persistence = accountingPersistenceBackends.get(scope);
if(persistence==null){ if(persistence==null){
persistence = discoverAccountingPersistenceBackend(scope); persistence = discoverAccountingPersistenceBackend(scope);
if(persistence==null){ if(persistence==null){
logger.warn("Unable to find a usable {}. {} will be used.", AccountingPersistenceBackend.class.getSimpleName(), FallbackPersistence.class.getSimpleName()); logger.warn("Unable to find a usable {}. {} will be used.", AccountingPersistenceBackend.class.getSimpleName(), FallbackPersistence.class.getSimpleName());
long now = Calendar.getInstance().getTimeInMillis(); long now = Calendar.getInstance().getTimeInMillis();
fallbackLastCheck.put(scope, now); fallbackLastCheck.put(scope, now);
persistence = createFallback(scope); persistence = createFallback(scope);
} }
accountingPersistenceBackends.put(scope, persistence);
persistencePersistenceBackends.put(scope, persistence);
} else { } else {
if(persistence instanceof FallbackPersistence && fallbackLastCheck.get(scope)!=null){ if(persistence instanceof FallbackPersistence && fallbackLastCheck.get(scope)!=null){
@ -137,9 +132,13 @@ public abstract class AccountingPersistenceBackendFactory {
AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope); AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope);
if(discoveredPersistenceBackend!=null){ 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()); discoveredPersistenceBackend.setAggregationScheduler(persistence.getAggregationScheduler());
// Removing timestamp wich is no more needed
fallbackLastCheck.remove(scope); fallbackLastCheck.remove(scope);
persistencePersistenceBackends.put(scope, discoveredPersistenceBackend); accountingPersistenceBackends.put(scope, discoveredPersistenceBackend);
try { try {
persistence.close(); persistence.close();
} catch (Exception e) { } catch (Exception e) {
@ -148,7 +147,9 @@ public abstract class AccountingPersistenceBackendFactory {
discoveredPersistenceBackend.getClass().getSimpleName(), e); discoveredPersistenceBackend.getClass().getSimpleName(), e);
} }
persistence = discoveredPersistenceBackend; persistence = discoveredPersistenceBackend;
}else{ }else{
// Renewing timestamp
fallbackLastCheck.put(scope, now); fallbackLastCheck.put(scope, now);
} }
} }
@ -164,8 +165,8 @@ public abstract class AccountingPersistenceBackendFactory {
* @throws Exception * @throws Exception
*/ */
public static void flushAll(long timeout, TimeUnit timeUnit) { public static void flushAll(long timeout, TimeUnit timeUnit) {
for(String scope : persistencePersistenceBackends.keySet()){ for(String scope : accountingPersistenceBackends.keySet()){
AccountingPersistenceBackend apb = persistencePersistenceBackends.get(scope); AccountingPersistenceBackend apb = accountingPersistenceBackends.get(scope);
try { try {
logger.debug("Flushing records in scope {}", scope); logger.debug("Flushing records in scope {}", scope);
apb.flush(timeout, timeUnit); apb.flush(timeout, timeUnit);