Tighter handling of certain error conditions during content replication

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5900 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-09 01:20:14 +00:00
parent f30ccf8d6c
commit 1a415b73dc
2 changed files with 50 additions and 8 deletions

View File

@@ -36,6 +36,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.AbstractContentStore;
import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentExistsException;
import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.repository.ContentIOException;
@@ -441,8 +442,9 @@ public class ReplicatingContentStore extends AbstractContentStore
{
public void run()
{
for (ContentStore store : stores)
for (int i = 0; i < stores.size(); i++)
{
ContentStore store = stores.get(i);
try
{
// replicate the content to the store - we know the URL that we want to write to
@@ -457,22 +459,37 @@ public class ReplicatingContentStore extends AbstractContentStore
if (logger.isDebugEnabled())
{
logger.debug("Replicated content to store: \n" +
" url: " + contentUrl + "\n" +
" to store: " + store);
" Content: " + writer + "\n" +
" Store: " + store + "\n" +
" Number: " + i);
}
}
catch (UnsupportedOperationException e)
{
throw new ContentIOException(
"Unable to replicate content. The target store doesn't support replication: \n" +
" Content: " + writer.getContentUrl() + "\n" +
" To Store: " + store);
" Content: " + writer + "\n" +
" Store: " + store + "\n" +
" Number: " + i,
e);
}
catch (ContentExistsException e)
{
throw new ContentIOException(
"Content replication failed. " +
"The content URL already exists in the target (secondary) store: \n" +
" Content: " + writer + "\n" +
" Store: " + store + "\n" +
" Number: " + i);
}
catch (Throwable e)
{
throw new ContentIOException("Content replication failed: \n" +
" url: " + writer.getContentUrl() + "\n" +
" to store: " + store);
throw new ContentIOException(
"Content replication failed: \n" +
" Content: " + writer + "\n" +
" Store: " + store + "\n" +
" Number: " + i,
e);
}
}
}

View File

@@ -36,6 +36,7 @@ import org.alfresco.repo.content.AbstractWritableContentStoreTest;
import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.content.filestore.FileContentStore;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.util.GUID;
@@ -198,4 +199,28 @@ public class ReplicatingContentStoreTest extends AbstractWritableContentStoreTes
// this time, it must have been replicated to the primary store
checkForReplication(true, false, contentUrl, SOME_CONTENT);
}
public void testTargetContentUrlExists()
{
replicatingStore.setOutbound(true);
replicatingStore.setInbound(false);
// pick a secondary store and write some content to it
ContentStore secondaryStore = secondaryStores.get(2);
ContentWriter secondaryWriter = secondaryStore.getWriter(ContentContext.NULL_CONTEXT);
secondaryWriter.putContent("Content for secondary");
String secondaryContentUrl = secondaryWriter.getContentUrl();
// Now write to the primary store
ContentWriter replicatingWriter = replicatingStore.getWriter(new ContentContext(null, secondaryContentUrl));
String replicatingContent = "Content for primary";
try
{
replicatingWriter.putContent(replicatingContent);
fail("Replication should fail when the secondary store already has the content");
}
catch (ContentIOException e)
{
// Expected
}
}
}