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:
Derek Hulley
2007-06-12 22:57:09 +00:00
parent 7ba2f7e011
commit c0f4f6daa7

View File

@@ -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,19 +216,38 @@ public class ContentStoreCleaner
public void execute() public void execute()
{ {
checkProperties(); checkProperties();
Set<String> validUrls = getValidUrls(); try
// now clean each store in turn
for (ContentStore store : stores)
{ {
try Set<String> validUrls = getValidUrls();
// now clean each store in turn
for (ContentStore store : stores)
{ {
clean(validUrls, store); try
{
clean(validUrls, store);
}
catch (UnsupportedOperationException e)
{
throw new ContentIOException(
"Unable to clean store as the necessary operations are not supported: " + store,
e);
}
} }
catch (UnsupportedOperationException e) }
catch (ContentIOException e)
{
throw e;
}
catch (Throwable e)
{
// If the VM is shutting down, then ignore
if (vmShutdownListener.isVmShuttingDown())
{ {
throw new ContentIOException( // Ignore
"Unable to clean store as the necessary operations are not supported: " + store, }
e); else
{
logger.error("Exception during cleanup of content", e);
} }
} }
} }