BufferedContentDiskDriver getFileInfomation now updates file state timestamps.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29669 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2011-08-10 17:07:56 +00:00
parent abae741e01
commit 552a6cb85f
5 changed files with 179 additions and 31 deletions

View File

@@ -30,6 +30,7 @@ import org.alfresco.jlan.server.core.DeviceContextException;
import org.alfresco.jlan.server.filesys.DiskDeviceContext; import org.alfresco.jlan.server.filesys.DiskDeviceContext;
import org.alfresco.jlan.server.filesys.DiskInterface; import org.alfresco.jlan.server.filesys.DiskInterface;
import org.alfresco.jlan.server.filesys.DiskSizeInterface; import org.alfresco.jlan.server.filesys.DiskSizeInterface;
import org.alfresco.jlan.server.filesys.FileAccessToken;
import org.alfresco.jlan.server.filesys.FileInfo; import org.alfresco.jlan.server.filesys.FileInfo;
import org.alfresco.jlan.server.filesys.FileOpenParams; import org.alfresco.jlan.server.filesys.FileOpenParams;
import org.alfresco.jlan.server.filesys.FileStatus; import org.alfresco.jlan.server.filesys.FileStatus;
@@ -39,6 +40,8 @@ import org.alfresco.jlan.server.filesys.NetworkFile;
import org.alfresco.jlan.server.filesys.SearchContext; import org.alfresco.jlan.server.filesys.SearchContext;
import org.alfresco.jlan.server.filesys.SrvDiskInfo; import org.alfresco.jlan.server.filesys.SrvDiskInfo;
import org.alfresco.jlan.server.filesys.TreeConnection; import org.alfresco.jlan.server.filesys.TreeConnection;
import org.alfresco.jlan.server.filesys.cache.FileState;
import org.alfresco.jlan.server.filesys.cache.FileStateCache;
import org.alfresco.jlan.server.locking.OpLockInterface; import org.alfresco.jlan.server.locking.OpLockInterface;
import org.alfresco.jlan.server.locking.OpLockManager; import org.alfresco.jlan.server.locking.OpLockManager;
import org.alfresco.jlan.smb.SMBException; import org.alfresco.jlan.smb.SMBException;
@@ -154,8 +157,7 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
} }
} }
@Override private FileInfo getFileInformationInternal(SrvSession sess, TreeConnection tree,
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree,
String path) throws IOException String path) throws IOException
{ {
@@ -191,6 +193,11 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
fileInfoCache.put(key, info); fileInfoCache.put(key, info);
} }
/**
* Some information is not persisted by the repo
*/
/* /*
* Dual Key the cache so it can be looked up by NodeRef or Path * Dual Key the cache so it can be looked up by NodeRef or Path
*/ */
@@ -203,6 +210,56 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
return info; return info;
} }
@Override
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree,
String path) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
FileInfo info = getFileInformationInternal(sess, tree, path);
/*
* Some information is not maintained by the repo
*/
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState(path, false);
if(fstate != null)
{
FileInfo finfo = new FileInfo();
finfo.copyFrom(info);
if(fstate.hasFileSize())
{
finfo.setFileSize(fstate.getFileSize());
}
if ( fstate.hasAccessDateTime())
{
finfo.setAccessDateTime(fstate.getAccessDateTime());
}
if ( fstate.hasChangeDateTime())
{
finfo.setChangeDateTime(fstate.getChangeDateTime());
}
if ( fstate.hasModifyDateTime())
{
finfo.setModifyDateTime(fstate.getModifyDateTime());
}
if ( fstate.hasAllocationSize() && fstate.getAllocationSize() > info.getAllocationSize())
{
finfo.setAllocationSize( fstate.getAllocationSize());
}
return finfo;
}
}
return info;
}
@Override @Override
public int fileExists(SrvSession sess, TreeConnection tree, String path) public int fileExists(SrvSession sess, TreeConnection tree, String path)
@@ -238,7 +295,7 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
{ {
try try
{ {
FileInfo lookup = getFileInformation(sess, tree, path); FileInfo lookup = getFileInformationInternal(sess, tree, path);
if(logger.isDebugEnabled()) if(logger.isDebugEnabled())
{ {
@@ -258,9 +315,6 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
return FileStatus.NotExist; return FileStatus.NotExist;
} }
} }
// Not in cache - use the repo directly
//return diskInterface.fileExists(sess, tree, path);
} }
@Override @Override

View File

@@ -148,6 +148,7 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
private static final Log logger = LogFactory.getLog(ContentDiskDriver2.class); private static final Log logger = LogFactory.getLog(ContentDiskDriver2.class);
private static final Log readLogger = LogFactory.getLog("org.alfresco.filesys.repo.ContentDiskDriver2.Read"); private static final Log readLogger = LogFactory.getLog("org.alfresco.filesys.repo.ContentDiskDriver2.Read");
private static final Log writeLogger = LogFactory.getLog("org.alfresco.filesys.repo.ContentDiskDriver2.Write");
// Services and helpers // Services and helpers
private CifsHelper cifsHelper; private CifsHelper cifsHelper;
@@ -1960,6 +1961,7 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
boolean isFolder = true; boolean isFolder = true;
ContentFileInfo cInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline); ContentFileInfo cInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline);
if ( cInfo != null && cInfo.isDirectory() == false) if ( cInfo != null && cInfo.isDirectory() == false)
{ {
isFolder = false; isFolder = false;
@@ -1977,6 +1979,15 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
} }
} }
} }
if( info.hasSetFlag(FileInfo.SetAllocationSize))
{
if ( logger.isDebugEnabled())
{
logger.debug("Set allocation size" + name + info.getAllocationSize());
}
// Not yet implemented
}
// Set the creation and modified date/time // Set the creation and modified date/time
Map<QName, Serializable> auditableProps = new HashMap<QName, Serializable>(5); Map<QName, Serializable> auditableProps = new HashMap<QName, Serializable>(5);
@@ -2181,13 +2192,16 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
if(readLogger.isDebugEnabled()) if(readLogger.isDebugEnabled())
{ {
readLogger.debug("read File" + file); readLogger.debug("read File:" + file + ", size" + size);
} }
if(file.isDirectory()) if(file.isDirectory())
{ {
logger.debug("read file called for a directory - throw AccessDeniedException"); if(logger.isDebugEnabled())
throw new AccessDeniedException(); {
logger.debug("read file called for a directory - throw AccessDeniedException");
}
throw new AccessDeniedException("read called for a directory");
} }
// Read a block of data from the file // Read a block of data from the file
@@ -2259,9 +2273,9 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
public int writeFile(SrvSession sess, TreeConnection tree, NetworkFile file, public int writeFile(SrvSession sess, TreeConnection tree, NetworkFile file,
byte[] buffer, int bufferOffset, int size, long fileOffset) throws IOException byte[] buffer, int bufferOffset, int size, long fileOffset) throws IOException
{ {
if(logger.isDebugEnabled()) if(writeLogger.isDebugEnabled())
{ {
logger.debug("write File:" + file); writeLogger.debug("write File:" + file + " size:" + size);
} }
// Check if there is a quota manager // Check if there is a quota manager
@@ -2286,8 +2300,23 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
extendSize = endOfWrite - file.getFileSize(); extendSize = endOfWrite - file.getFileSize();
// Allocate space for the file extend // Allocate space for the file extend
if(logger.isDebugEnabled())
{
logger.debug("writeFile: allocate more space fileName:" + file.getName());
}
quotaMgr.allocateSpace(sess, tree, file, extendSize); long alloc = quotaMgr.allocateSpace(sess, tree, file, extendSize);
if(file instanceof TempNetworkFile)
{
TempNetworkFile tnf = (TempNetworkFile)file;
FileState fstate = tnf.getFileState();
if(fstate != null)
{
fstate.setAllocationSize(alloc);
}
}
} }
} }
@@ -2313,9 +2342,9 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
// Debug // Debug
if (logger.isDebugEnabled()) if (writeLogger.isDebugEnabled())
{ {
logger.debug("Wrote bytes to file: network file=" + file + " buffer size=" + buffer.length + " size=" + size + " file offset=" + fileOffset); writeLogger.debug("Wrote bytes to file: network file=" + file + " buffer size=" + buffer.length + " size=" + size + " file offset=" + fileOffset);
} }
return size; return size;
@@ -3209,6 +3238,7 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
// Always allow write access to a newly created file // Always allow write access to a newly created file
netFile.setGrantedAccess(NetworkFile.READWRITE); netFile.setGrantedAccess(NetworkFile.READWRITE);
// Truncate the file so that the content stream is created // Truncate the file so that the content stream is created
//netFile.truncateFile( 0L); //netFile.truncateFile( 0L);

View File

@@ -156,8 +156,8 @@ public class ContentQuotaManager implements QuotaManager, Runnable {
* @param sess SrvSession * @param sess SrvSession
* @param tree TreeConnection * @param tree TreeConnection
* @param file NetworkFile * @param file NetworkFile
* @param alloc long * @param alloc long requested allocation size
* @return long * @return long granted allocation size
* @exception IOException * @exception IOException
*/ */
public long allocateSpace(SrvSession sess, TreeConnection tree, NetworkFile file, long alloc) public long allocateSpace(SrvSession sess, TreeConnection tree, NetworkFile file, long alloc)

View File

@@ -35,6 +35,7 @@ import org.alfresco.jlan.server.filesys.SearchContext;
import org.alfresco.jlan.server.filesys.TreeConnection; import org.alfresco.jlan.server.filesys.TreeConnection;
import org.alfresco.jlan.server.filesys.cache.FileState; import org.alfresco.jlan.server.filesys.cache.FileState;
import org.alfresco.jlan.server.filesys.cache.FileStateCache; import org.alfresco.jlan.server.filesys.cache.FileStateCache;
import org.alfresco.jlan.server.filesys.cache.NetworkFileStateInterface;
import org.alfresco.jlan.smb.SharingMode; import org.alfresco.jlan.smb.SharingMode;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -59,7 +60,7 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
PropertyCheck.mandatory(this, "diskInterface", diskInterface); PropertyCheck.mandatory(this, "diskInterface", diskInterface);
} }
private static final Log logger = LogFactory.getLog(NonTransactionalRuleContentDiskDriver.class); private static final Log logger = LogFactory.getLog(LegacyFileStateDriver.class);
@Override @Override
public void treeOpened(SrvSession sess, TreeConnection tree) public void treeOpened(SrvSession sess, TreeConnection tree)
@@ -96,6 +97,30 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
try try
{ {
NetworkFile newFile = diskInterface.createFile(sess, tree, params); NetworkFile newFile = diskInterface.createFile(sess, tree, params);
if(tctx.hasStateCache())
{
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
fstate.incrementOpenCount();
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
// Indicate that the file is open
fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists);
fstate.setAllocationSize( params.getAllocationSize());
if (newFile instanceof NodeRefNetworkFile)
{
NodeRefNetworkFile x = (NodeRefNetworkFile)newFile;
x.setFileState(fstate);
}
if (newFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)newFile;
x.setFileState(fstate);
}
}
if (newFile instanceof NodeRefNetworkFile) if (newFile instanceof NodeRefNetworkFile)
{ {
@@ -110,19 +135,6 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
x.setAccessToken(token); x.setAccessToken(token);
} }
if(tctx.hasStateCache())
{
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
fstate.incrementOpenCount();
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
fstate.setProcessId( params.getProcessId());
// Indicate that the file is open
fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists);
fstate.setAllocationSize( params.getAllocationSize());
}
return newFile; return newFile;
} }
@@ -255,6 +267,7 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
{ {
FileStateCache cache = tctx.getStateCache(); FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( param.getFullName(), true); FileState fstate = cache.findFileState( param.getFullName(), true);
if(fstate != null && param.getAccessToken() != null) if(fstate != null && param.getAccessToken() != null)
{ {
FileAccessToken token = param.getAccessToken(); FileAccessToken token = param.getAccessToken();

View File

@@ -1,6 +1,7 @@
package org.alfresco.filesys.repo; package org.alfresco.filesys.repo;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import org.alfresco.jlan.server.filesys.cache.FileState; import org.alfresco.jlan.server.filesys.cache.FileState;
@@ -52,6 +53,55 @@ public class TempNetworkFile extends JavaNetworkFile implements NetworkFileState
return "TempNetworkFile:" + getFullName() + " path: " + m_file.getAbsolutePath(); return "TempNetworkFile:" + getFullName() + " path: " + m_file.getAbsolutePath();
} }
@Override
public int readFile(byte[] buf, int len, int pos, long fileOff)
throws java.io.IOException
{
if(fileState != null)
{
fileState.updateAccessDateTime();
}
return super.readFile(buf, len, pos, fileOff);
}
@Override
public void writeFile(byte[] buf, int len, int pos) throws IOException
{
if(fileState != null)
{
fileState.updateModifyDateTime();
}
super.writeFile(buf, len, pos);
setFileSize(m_io.length());
}
@Override
public void writeFile(byte[] buffer, int length, int position, long fileOffset)
throws IOException
{
if(fileState != null)
{
fileState.updateModifyDateTime();
}
super.writeFile(buffer, length, position, fileOffset);
setFileSize(m_io.length());
}
@Override
public void truncateFile(long size) throws IOException
{
if(fileState != null)
{
fileState.updateModifyDateTime();
}
super.truncateFile(size);
setFileSize(size);
}
// For JLAN file state lock manager // For JLAN file state lock manager
public void setFileState(FileState fileState) public void setFileState(FileState fileState)
{ {
@@ -62,7 +112,8 @@ public class TempNetworkFile extends JavaNetworkFile implements NetworkFileState
public FileState getFileState() public FileState getFileState()
{ {
return fileState; return fileState;
} }
private FileState fileState; private FileState fileState;
} }