A couple of more special tricks to get better performance out of

AVMSyncService.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3811 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-16 16:11:21 +00:00
parent 14ebe1726f
commit f5e509c18b
4 changed files with 76 additions and 9 deletions

View File

@@ -136,6 +136,43 @@ public class AVMRepository
rep.createDirectory(pathParts[1], name);
}
/**
* Create a new directory. This assumes that the parent is already
* copied and therefore should only be used with great care.
* @param parent The parent node.
* @param name The name of the new directory.
* @return A descriptor for the newly created directory.
*/
public AVMNodeDescriptor createDirectory(AVMNodeDescriptor parent, String name)
{
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(parent.getId());
if (node == null)
{
throw new AVMNotFoundException(parent.getId() + " not found.");
}
if (!(node instanceof DirectoryNode))
{
throw new AVMWrongTypeException("Not a directory.");
}
// We need the store to do anything so...
String [] pathParts = SplitPath(parent.getPath());
AVMStore store = getAVMStoreByName(pathParts[0]);
DirectoryNode dir = (DirectoryNode)node;
DirectoryNode child = null;
if (dir instanceof LayeredDirectoryNode)
{
child = new LayeredDirectoryNodeImpl((String)null, store);
((LayeredDirectoryNode)child).setPrimaryIndirection(false);
((LayeredDirectoryNode)child).setLayerID(parent.getLayerID());
}
else
{
child = new PlainDirectoryNodeImpl(store);
}
dir.putChild(name, child);
return child.getDescriptor(parent.getPath(), name, parent.getIndirection());
}
/**
* Create a new layered directory.
* @param srcPath The target indirection for the new layered directory.
@@ -1311,12 +1348,14 @@ public class AVMRepository
* Force a copy on write.
* @param path The path to force.
*/
public void forceCopy(String path)
public AVMNodeDescriptor forceCopy(String path)
{
fLookupCount.set(1);
String [] pathParts = SplitPath(path);
AVMStore store = getAVMStoreByName(pathParts[0]);
// Just force a copy if needed by looking up in write mode.
store.lookup(-1, pathParts[1], true, false);
Lookup lPath = store.lookup(-1, pathParts[1], true, false);
AVMNode node = lPath.getCurrentNode();
return node.getDescriptor(lPath);
}
}

View File

@@ -307,6 +307,22 @@ public class AVMServiceImpl implements AVMService
fAVMRepository.createDirectory(path, name);
}
/**
* Create a new directory, in an already copy on written node.
* This should only be used if you really know what you're doing.
* @param parent The parent node.
* @param name The name of the new directory.
* @return A descriptor for the newly created directory.
*/
public AVMNodeDescriptor createDirectory(AVMNodeDescriptor parent, String name)
{
if (parent == null || name == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
return fAVMRepository.createDirectory(parent, name);
}
/**
* Create a new layered file. It must not exist.
* @param srcPath The src path. Ie the target for the layering.
@@ -1106,12 +1122,12 @@ public class AVMServiceImpl implements AVMService
* Force copy on write of a path.
* @param path The path to force.
*/
public void forceCopy(String path)
public AVMNodeDescriptor forceCopy(String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null Path.");
}
fAVMRepository.forceCopy(path);
return fAVMRepository.forceCopy(path);
}
}

View File

@@ -29,6 +29,7 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.apache.log4j.Logger;
/**
* This implements APIs that allow comparison and synchronization
@@ -38,6 +39,8 @@ import org.alfresco.service.cmr.avmsync.AVMSyncService;
*/
public class AVMSyncServiceImpl implements AVMSyncService
{
private static Logger fgLogger = Logger.getLogger(AVMSyncServiceImpl.class);
/**
* The AVMService.
*/
@@ -419,12 +422,13 @@ public class AVMSyncServiceImpl implements AVMSyncService
}
// Otherwise make a directory in the target parent, and recursiveCopy all the source
// children into it.
fAVMService.createDirectory(parent.getPath(), name);
AVMNodeDescriptor newParentDesc = fAVMService.lookup(parent, name);
AVMNodeDescriptor newParentDesc = fAVMService.createDirectory(parent, name);
fgLogger.error(newParentDesc);
Map<String, AVMNodeDescriptor> children =
fAVMService.getDirectoryListing(toCopy, true);
for (Map.Entry<String, AVMNodeDescriptor> entry : children.entrySet())
{
fgLogger.error(entry.getKey());
recursiveCopy(newParentDesc, entry.getKey(), entry.getValue());
}
}
@@ -593,8 +597,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
{
return true;
}
fAVMService.forceCopy(layer.getPath());
layer = fAVMService.lookup(-1, layer.getPath());
layer = fAVMService.forceCopy(layer.getPath());
// Grab the listing
Map<String, AVMNodeDescriptor> underListing =
fAVMService.getDirectoryListing(underlying, true);