diff --git a/source/java/org/alfresco/repo/avm/AVMCrawlTestP.java b/source/java/org/alfresco/repo/avm/AVMCrawlTestP.java index d4ef18abf9..176a9dd212 100644 --- a/source/java/org/alfresco/repo/avm/AVMCrawlTestP.java +++ b/source/java/org/alfresco/repo/avm/AVMCrawlTestP.java @@ -35,8 +35,8 @@ public class AVMCrawlTestP extends AVMServiceTestBase */ public void testCrawl() { - int n = 8; // Number of Threads. - int m = 32; // How many multiples of content to start with. + int n = 4; // Number of Threads. + int m = 16; // How many multiples of content to start with. long runTime = 3600000; // 6 hours. fService.purgeAVMStore("main"); BulkLoader loader = new BulkLoader(); diff --git a/source/java/org/alfresco/repo/avm/AVMCrawler.java b/source/java/org/alfresco/repo/avm/AVMCrawler.java index 61f48b3569..38f4e1bc0e 100644 --- a/source/java/org/alfresco/repo/avm/AVMCrawler.java +++ b/source/java/org/alfresco/repo/avm/AVMCrawler.java @@ -31,9 +31,7 @@ import org.alfresco.service.cmr.avm.AVMException; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; -import org.alfresco.service.cmr.repository.InvalidNodeRefException; -import org.hibernate.HibernateException; -import org.springframework.dao.ConcurrencyFailureException; +import org.alfresco.service.cmr.repository.ContentIOException; /** @@ -230,22 +228,14 @@ class AVMCrawler implements Runnable { return; } + if (e instanceof ContentIOException) + { + return; + } if (e instanceof AlfrescoRuntimeException) { return; } - if (e instanceof ConcurrencyFailureException) - { - return; - } - if (e instanceof HibernateException) - { - return; - } - if (e instanceof InvalidNodeRefException) - { - return; - } throw new AVMException("Failure", e); } } diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 40c4872e76..3a9e56d3e9 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -596,11 +596,12 @@ public class AVMRepository throw new AVMNotFoundException("Path not found."); } DirectoryNode dstDir = (DirectoryNode)dPath.getCurrentNode(); - AVMNode dstNode = dstDir.lookupChild(dPath, dstName, false); - if (dstNode != null) + AVMNode child = dstDir.lookupChild(dPath, dstName, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Node exists: " + dstName); } + AVMNode dstNode = null; // We've passed the check, so we can go ahead and do the rename. if (srcNode.getType() == AVMNodeType.PLAIN_DIRECTORY) { @@ -682,9 +683,16 @@ public class AVMRepository srcDir.removeChild(sPath, srcName); srcDir.updateModTime(); dstNode.setVersionID(dstRepo.getNextVersionID()); + if (child != null) + { + dstNode.setAncestor(child); + } dstDir.putChild(dstName, dstNode); dstDir.updateModTime(); - dstNode.setAncestor(srcNode); + if (child == null) + { + dstNode.setAncestor(srcNode); + } } finally { diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index f1e453fad8..197a5c686f 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -71,6 +71,39 @@ import org.alfresco.util.Pair; */ public class AVMServiceTest extends AVMServiceTestBase { + /** + * Test relinking of nodes to history. + */ + public void testHistoryRelink() + { + try + { + setupBasicTree(); + fService.createAVMStore("branch"); + fService.createBranch(-1, "main:/a", "branch:/", "a"); + fService.removeNode("branch:/a/b/c/foo"); + List diffs = fSyncService.compare(-1, "branch:/a", -1, "main:/a", null); + assertEquals(1, diffs.size()); + assertEquals(AVMDifference.NEWER, diffs.get(0).getDifferenceCode()); + fService.createFile("branch:/a/b/c", "foo").close(); + diffs = fSyncService.compare(-1, "branch:/a", -1, "main:/a", null); + assertEquals(1, diffs.size()); + assertEquals(AVMDifference.NEWER, diffs.get(0).getDifferenceCode()); + fSyncService.update(diffs, null, false, false, false, false, null, null); + fService.removeNode("branch:/a/b/c/bar"); + fService.createFile("branch:/a/b/c", "pismo").close(); + fService.rename("branch:/a/b/c", "pismo", "branch:/a/b/c", "bar"); + diffs = fSyncService.compare(-1, "branch:/a", -1, "main:/a", null); + assertEquals(1, diffs.size()); + assertEquals(AVMDifference.NEWER, diffs.get(0).getDifferenceCode()); + } + catch (Exception e) + { + e.printStackTrace(); + fail(); + } + } + /** * Test renaming a store. */ @@ -775,13 +808,13 @@ public class AVMServiceTest extends AVMServiceTestBase { // Do nothing. } - // Get synced again by doing an override conflict. + // Get synced again by doing an override older. System.out.println(recursiveList("main", -1, true)); diffs.clear(); diffs.add(new AVMDifference(-1, "main:/a/monkey", -1, "main:/abranch/monkey", AVMDifference.NEWER)); - fSyncService.update(diffs, null, false, false, true, false, null, null); + fSyncService.update(diffs, null, false, false, false, true, null, null); assertEquals(0, fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder).size()); fService.createSnapshot("main", null, null); System.out.println(recursiveList("main", -1, true)); @@ -859,13 +892,13 @@ public class AVMServiceTest extends AVMServiceTestBase { // Do nothing. } - // Get synced again by doing an override conflict. + // Get synced again by doing an override older. System.out.println(recursiveList("main", -1, true)); diffs.clear(); diffs.add(new AVMDifference(-1, "main:/a/monkey", -1, "main:/layer/monkey", AVMDifference.NEWER)); - fSyncService.update(diffs, null, false, false, true, false, null, null); + fSyncService.update(diffs, null, false, false, false, true, null, null); assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder).size()); fService.createSnapshot("main", null, null); System.out.println(recursiveList("main", -1, true)); diff --git a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java index 9145a32c7a..71ef2b09c1 100644 --- a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java @@ -214,7 +214,8 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMNotFoundException("Path not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (dir.lookupChild(lPath, name, false) != null) + AVMNode child = dir.lookupChild(lPath, name, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } @@ -232,6 +233,10 @@ public class AVMStoreImpl implements AVMStore, Serializable newDir = new PlainDirectoryNodeImpl(this); } newDir.setVersionID(getNextVersionID()); + if (child != null) + { + newDir.setAncestor(child); + } dir.putChild(name, newDir); dir.updateModTime(); } @@ -251,7 +256,8 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMNotFoundException("Path not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (dir.lookupChild(lPath, name, false) != null) + AVMNode child = dir.lookupChild(lPath, name, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } @@ -270,6 +276,10 @@ public class AVMStoreImpl implements AVMStore, Serializable // Otherwise we issue a brand new layer id. newDir.setLayerID(fAVMRepository.issueLayerID()); } + if (child != null) + { + newDir.setAncestor(child); + } dir.putChild(name, newDir); dir.updateModTime(); newDir.setVersionID(getNextVersionID()); @@ -289,7 +299,8 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMNotFoundException("Path not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (dir.lookupChild(lPath, name, false) != null) + AVMNode child = dir.lookupChild(lPath, name, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } @@ -297,6 +308,10 @@ public class AVMStoreImpl implements AVMStore, Serializable file.setVersionID(getNextVersionID()); dir.putChild(name, file); dir.updateModTime(); + if (child != null) + { + file.setAncestor(child); + } file.setContentData(new ContentData(null, RawServices.Instance().getMimetypeService().guessMimetype(name), -1, @@ -319,7 +334,8 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMNotFoundException("Path not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (dir.lookupChild(lPath, name, false) != null) + AVMNode child = dir.lookupChild(lPath, name, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } @@ -327,6 +343,10 @@ public class AVMStoreImpl implements AVMStore, Serializable file.setVersionID(getNextVersionID()); dir.putChild(name, file); dir.updateModTime(); + if (child != null) + { + file.setAncestor(child); + } file.setContentData(new ContentData(null, RawServices.Instance().getMimetypeService().guessMimetype(name), -1, @@ -349,13 +369,18 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMNotFoundException("Path not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (dir.lookupChild(lPath, name, false) != null) + AVMNode child = dir.lookupChild(lPath, name, true); + if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } // TODO Reexamine decision to not check validity of srcPath. LayeredFileNodeImpl newFile = new LayeredFileNodeImpl(srcPath, this); + if (child != null) + { + newFile.setAncestor(child); + } dir.putChild(name, newFile); dir.updateModTime(); newFile.setVersionID(getNextVersionID());