mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Cleaner checks the failure mode to catch the VM shutting down during execution.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5925 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,8 +35,8 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
|||||||
import org.alfresco.repo.avm.AVMNodeDAO;
|
import org.alfresco.repo.avm.AVMNodeDAO;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.node.db.NodeDaoService;
|
import org.alfresco.repo.node.db.NodeDaoService;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.repository.ContentIOException;
|
|||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.PropertyCheck;
|
import org.alfresco.util.PropertyCheck;
|
||||||
|
import org.alfresco.util.VmShutdownListener;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -59,6 +60,8 @@ public class ContentStoreCleaner
|
|||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(ContentStoreCleaner.class);
|
private static Log logger = LogFactory.getLog(ContentStoreCleaner.class);
|
||||||
|
|
||||||
|
private static VmShutdownListener vmShutdownListener = new VmShutdownListener(ContentStoreCleaner.class.getName());
|
||||||
|
|
||||||
private DictionaryService dictionaryService;
|
private DictionaryService dictionaryService;
|
||||||
private NodeDaoService nodeDaoService;
|
private NodeDaoService nodeDaoService;
|
||||||
private TransactionService transactionService;
|
private TransactionService transactionService;
|
||||||
@@ -159,34 +162,30 @@ public class ContentStoreCleaner
|
|||||||
|
|
||||||
private Set<String> getValidUrls()
|
private Set<String> getValidUrls()
|
||||||
{
|
{
|
||||||
|
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||||
|
|
||||||
final DataTypeDefinition contentDataType = dictionaryService.getDataType(DataTypeDefinition.CONTENT);
|
final DataTypeDefinition contentDataType = dictionaryService.getDataType(DataTypeDefinition.CONTENT);
|
||||||
// wrap to make the request in a transaction
|
// wrap to make the request in a transaction
|
||||||
TransactionWork<List<Serializable>> getUrlsWork = new TransactionWork<List<Serializable>>()
|
RetryingTransactionCallback<List<Serializable>> getUrlsCallback = new RetryingTransactionCallback<List<Serializable>>()
|
||||||
{
|
{
|
||||||
public List<Serializable> doWork() throws Exception
|
public List<Serializable> execute() throws Throwable
|
||||||
{
|
{
|
||||||
return nodeDaoService.getPropertyValuesByActualType(contentDataType);
|
return nodeDaoService.getPropertyValuesByActualType(contentDataType);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
// execute in READ-ONLY txn
|
// execute in READ-ONLY txn
|
||||||
List<Serializable> values = TransactionUtil.executeInUserTransaction(
|
List<Serializable> values = txnHelper.doInTransaction(getUrlsCallback, true);
|
||||||
transactionService,
|
|
||||||
getUrlsWork,
|
|
||||||
true);
|
|
||||||
|
|
||||||
// Do the same for the AVM repository.
|
// Do the same for the AVM repository.
|
||||||
TransactionWork<List<String>> getAVMUrlsWork = new TransactionWork<List<String>>()
|
RetryingTransactionCallback<List<String>> getAVMUrlsCallback = new RetryingTransactionCallback<List<String>>()
|
||||||
{
|
{
|
||||||
public List<String> doWork() throws Exception
|
public List<String> execute() throws Exception
|
||||||
{
|
{
|
||||||
return avmNodeDAO.getContentUrls();
|
return avmNodeDAO.getContentUrls();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// execute in READ-ONLY txn
|
||||||
List<String> avmContentUrls = TransactionUtil.executeInUserTransaction(
|
List<String> avmContentUrls = txnHelper.doInTransaction(getAVMUrlsCallback, true);
|
||||||
transactionService,
|
|
||||||
getAVMUrlsWork,
|
|
||||||
true);
|
|
||||||
|
|
||||||
// get all valid URLs
|
// get all valid URLs
|
||||||
Set<String> validUrls = new HashSet<String>(values.size());
|
Set<String> validUrls = new HashSet<String>(values.size());
|
||||||
@@ -217,6 +216,8 @@ public class ContentStoreCleaner
|
|||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
checkProperties();
|
checkProperties();
|
||||||
|
try
|
||||||
|
{
|
||||||
Set<String> validUrls = getValidUrls();
|
Set<String> validUrls = getValidUrls();
|
||||||
// now clean each store in turn
|
// now clean each store in turn
|
||||||
for (ContentStore store : stores)
|
for (ContentStore store : stores)
|
||||||
@@ -233,6 +234,23 @@ public class ContentStoreCleaner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ContentIOException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
// If the VM is shutting down, then ignore
|
||||||
|
if (vmShutdownListener.isVmShuttingDown())
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.error("Exception during cleanup of content", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void clean(Set<String> validUrls, ContentStore store)
|
private void clean(Set<String> validUrls, ContentStore store)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user