mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed memory leak where transactional cache was NOT used during a transaction, i.e. cleanup was not being performed if the cache was not used
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2307 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -201,6 +201,12 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Failed to add txn caches to manager", e);
|
throw new AlfrescoRuntimeException("Failed to add txn caches to manager", e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// ensure that we get the transaction callbacks as we have bound the unique
|
||||||
|
// transactional caches to a common manager
|
||||||
|
AlfrescoTransactionSupport.bindListener(this);
|
||||||
|
}
|
||||||
AlfrescoTransactionSupport.bindResource(resourceKeyTxnData, data);
|
AlfrescoTransactionSupport.bindResource(resourceKeyTxnData, data);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@@ -324,12 +330,6 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
else // transaction present
|
else // transaction present
|
||||||
{
|
{
|
||||||
TransactionData txnData = getTransactionData();
|
TransactionData txnData = getTransactionData();
|
||||||
// register for callbacks
|
|
||||||
if (!txnData.listenerBound)
|
|
||||||
{
|
|
||||||
AlfrescoTransactionSupport.bindListener(this);
|
|
||||||
txnData.listenerBound = true;
|
|
||||||
}
|
|
||||||
// we have a transaction - add the item into the updated cache for this transaction
|
// we have a transaction - add the item into the updated cache for this transaction
|
||||||
// are we in an overflow condition?
|
// are we in an overflow condition?
|
||||||
if (txnData.updatedItemsCache.getMemoryStoreSize() >= maxCacheSize)
|
if (txnData.updatedItemsCache.getMemoryStoreSize() >= maxCacheSize)
|
||||||
@@ -378,12 +378,6 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
else // transaction present
|
else // transaction present
|
||||||
{
|
{
|
||||||
TransactionData txnData = getTransactionData();
|
TransactionData txnData = getTransactionData();
|
||||||
// register for callbacks
|
|
||||||
if (!txnData.listenerBound)
|
|
||||||
{
|
|
||||||
AlfrescoTransactionSupport.bindListener(this);
|
|
||||||
txnData.listenerBound = true;
|
|
||||||
}
|
|
||||||
// is the shared cache going to be cleared?
|
// is the shared cache going to be cleared?
|
||||||
if (txnData.isClearOn)
|
if (txnData.isClearOn)
|
||||||
{
|
{
|
||||||
@@ -440,12 +434,6 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionData txnData = getTransactionData();
|
TransactionData txnData = getTransactionData();
|
||||||
// register for callbacks
|
|
||||||
if (!txnData.listenerBound)
|
|
||||||
{
|
|
||||||
AlfrescoTransactionSupport.bindListener(this);
|
|
||||||
txnData.listenerBound = true;
|
|
||||||
}
|
|
||||||
// the shared cache must be cleared at the end of the transaction
|
// the shared cache must be cleared at the end of the transaction
|
||||||
// and also serves to ensure that the shared cache will be ignored
|
// and also serves to ensure that the shared cache will be ignored
|
||||||
// for the remainder of the transaction
|
// for the remainder of the transaction
|
||||||
@@ -498,7 +486,8 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionData txnData = getTransactionData();
|
TransactionData txnData = getTransactionData();
|
||||||
|
try
|
||||||
|
{
|
||||||
if (txnData.isClearOn)
|
if (txnData.isClearOn)
|
||||||
{
|
{
|
||||||
// clear shared cache
|
// clear shared cache
|
||||||
@@ -523,9 +512,8 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
logger.debug("Removed " + keys.size() + " values from shared cache");
|
logger.debug("Removed " + keys.size() + " values from shared cache");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer updates
|
// transfer updates
|
||||||
try
|
|
||||||
{
|
|
||||||
List<Serializable> keys = txnData.updatedItemsCache.getKeys();
|
List<Serializable> keys = txnData.updatedItemsCache.getKeys();
|
||||||
for (Serializable key : keys)
|
for (Serializable key : keys)
|
||||||
{
|
{
|
||||||
@@ -541,10 +529,10 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Failed to transfer updates to shared cache", e);
|
throw new AlfrescoRuntimeException("Failed to transfer updates to shared cache", e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
// drop caches from cachemanager
|
{
|
||||||
cacheManager.removeCache(txnData.updatedItemsCache.getName());
|
removeCaches(txnData);
|
||||||
cacheManager.removeCache(txnData.removedItemsCache.getName());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -553,8 +541,17 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
public void afterRollback()
|
public void afterRollback()
|
||||||
{
|
{
|
||||||
TransactionData txnData = getTransactionData();
|
TransactionData txnData = getTransactionData();
|
||||||
|
|
||||||
// drop caches from cachemanager
|
// drop caches from cachemanager
|
||||||
|
removeCaches(txnData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the transactional caches are removed from the common cache manager.
|
||||||
|
*
|
||||||
|
* @param txnData the data with references to the the transactional caches
|
||||||
|
*/
|
||||||
|
private void removeCaches(TransactionData txnData)
|
||||||
|
{
|
||||||
cacheManager.removeCache(txnData.updatedItemsCache.getName());
|
cacheManager.removeCache(txnData.updatedItemsCache.getName());
|
||||||
cacheManager.removeCache(txnData.removedItemsCache.getName());
|
cacheManager.removeCache(txnData.removedItemsCache.getName());
|
||||||
}
|
}
|
||||||
@@ -565,6 +562,5 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
|||||||
public Cache updatedItemsCache;
|
public Cache updatedItemsCache;
|
||||||
public Cache removedItemsCache;
|
public Cache removedItemsCache;
|
||||||
public boolean isClearOn;
|
public boolean isClearOn;
|
||||||
public boolean listenerBound;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user