Dave Ward 4e7a0f6ef0 Merged V4.0-BUG-FIX to HEAD
33757: Merged BRANCHES/DEV/THOR1_SPRINTS to BRANCHES/DEV/V4.0-BUG-FIX
      33755: Latest Spring Surf libs:
             - Updates to convert FreeMarker directives for processing directives Spring Beans to allow their behaviour to be customized.
             - Changed Extensibility model objects to use a non-blocking GUID generator to avoid thread contention (small amount noticed with 1000 concurrent user test)
             - Removed old machine gun code to generate Object GUIDs, which weren't even valid GUIDs ironically.
             - Replaced with new non-blocking fast GUID generator in webscripts package.
             - Added Reentrant ReadWriteLock around resources in singleton Spring beans that are manipulated by multiple threads.
             - Added Reentrant ReadWriteLock around Advanced Component internal resources.
             - Surf performance improvements from Thor high load profiling in Jmeter/Jprofiler
             - Removed lock around ModelWriter (which is only used by a single request thread at a time)
             - Replaced StringBuffer with StringBuilder for Writer usage in extensibility framework to remove locking.
             - Performance improvements around retrieval of RemoteClient instance
             - avoid expensive Spring prototype bean retrieval, use a threadlocal clone of a base RemoteClient bean instead.
             - Concurrency fixes around CRUD operations on shared ModelObjects instances.
             - Surf ModelObjects are shared between all users in the model object caches - but the original machine gun code has no locking what-so-ever around CRUD operations - which meant that it was possible for incorrect property values to be received from a ModelObject in a heavily multi-threaded scenario on initialisation of a Surf application.
             - was causing nonsense warnings such as:
               WARN  [extensions.webscripts.WebTemplateProcessor] [http-8081-exec-10] Unable to find a valid template path for uri: freemarker
             - Modified default web-tier server response codes for read timeout and connect timeout to return more sensible codes to client browsers.
             - Fix for concurrency issue resolving SpringMVC View objects found during heavy thread testing on web-tier startup.
             - Improved caching strategy for WebScripts View Resolver - move techniques from Surf down to WebScripts layer.
             - Improved general View Resolver strategy by caching failed view requests.
             - WebScript resource bundle extension module application thread safety modifications   
   Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
      33684: Fixes for ALF-12628, ALF-12639 - timeout handling for READ_TIMEOUT from web-tier to Alfresco
   33771: ALF-12488 - CIFS error occurs if Hazelcast Config is enabled
   33773: ALF-12437 Switching from Lucene to Solr caused subsystems to be in inconsistent state and repository to hang
   - filter to include only updateable properties at persistence and start up time
   33775: ALF-11870 Handle the odd way that Outlook requests yearly repeating events, and add unit tests for the yearly recurrence cases
   33776: ALF-12569: org.postgresql.util.PSQLException Invalid ESCAPE on customizing alfresco share site dashboard   
      Added backwards compatible PostgreSQL-specific ESCAPE fragment - fixes for PostgreSQL 9.1.2.
   33784: Fixes: ALF-12111 - Publishing Error when authenticating Facebook channels using IE8. Required an update to stand-alone-auth-return.html.
   33787: Fix for ALF-12337 Remove patch.siteLoadPatch.swsdp from being run for upgrades
   - only add the sample site for new installs and not upgrades
   33794: ITALIAN: Translation updates based on EN r33523
   33807: Merged V3.4-BUG-FIX to V4.0-BUG-FIX
      33717: (RECORD ONLY) ALF-12632 Move the Site Service permissions to public-services-security-context.xml, to mirror the behaviour on 4.0, and add a (commented out) example of how to restrict site creation permissions with it
      33806: Merged V3.4 to V3.4-BUG-FIX
         33728: ALF-10976 Excel files bigger than 2mb cause soffice.exe to take 100% of one CPU for more than 2 minutes in previews.
            - Added configuration to limit older excel format 'xls' from Excel 5.0/95 and Excel 97-2003
              Already had configuration for xlsx Microsoft Office 2007
         33743: ALF-12724: Merge HEAD to V3.4 (3.4.8)
            Issue found while fixing ALF-9899 and again by QA when testing ALF-9899
            32941: ALF-11300:
              - fix locking issues
         33772: Merged DEV to V3.4
            33768: ALF-12685 : Search isn't working correctly
               Index delete events were not getting fired for the entire tree of affected nodes when a node was archive
               Added a deletion of child nodes from indexes in DbNodeServiceImpl.pullNodeChildrenToSameStore() method.
         33803: ALF-12724: Merged V4.0-BUG-FIX to V3.4 (Reverts previous revision and changes an error message to debug)
            33137: Activities feed generator: change info log messages to debug log messages
            33452: Fix for ALF-12536
            33536: Fix for ALF-12536: hopefully this will be the final fix.
         33805: ALF-12624: Fix regression introduced by ALF-9514


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-02-09 16:13:30 +00:00

489 lines
16 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.filesys.repo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import org.alfresco.filesys.alfresco.ExtendedDiskInterface;
import org.alfresco.filesys.config.ServerConfigurationBean;
import org.alfresco.jlan.server.SrvSession;
import org.alfresco.jlan.server.core.DeviceContext;
import org.alfresco.jlan.server.core.DeviceContextException;
import org.alfresco.jlan.server.filesys.FileAccessToken;
import org.alfresco.jlan.server.filesys.FileInfo;
import org.alfresco.jlan.server.filesys.FileOpenParams;
import org.alfresco.jlan.server.filesys.FileStatus;
import org.alfresco.jlan.server.filesys.NetworkFile;
import org.alfresco.jlan.server.filesys.SearchContext;
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.filesys.cache.NetworkFileStateInterface;
import org.alfresco.jlan.server.filesys.pseudo.PseudoFile;
import org.alfresco.jlan.smb.SharingMode;
import org.alfresco.model.ContentModel;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.config.ConfigElement;
/**
* The Legacy file state driver is used to update JLAN's file state cache.
* <p>
* This class decorates an ExtendedDiskInterface with odds and ends to keep JLan happy.
* <p>
* In particular this implementation cannot contain any code that requires access to the
* alfresco repository.
*
*/
public class LegacyFileStateDriver implements ExtendedDiskInterface
{
private ExtendedDiskInterface diskInterface;
public void init()
{
PropertyCheck.mandatory(this, "diskInterface", diskInterface);
}
private static final Log logger = LogFactory.getLog(LegacyFileStateDriver.class);
@Override
public void treeOpened(SrvSession sess, TreeConnection tree)
{
diskInterface.treeOpened(sess, tree);
}
@Override
public void treeClosed(SrvSession sess, TreeConnection tree)
{
diskInterface.treeClosed(sess, tree);
}
@Override
public NetworkFile createFile(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
FileAccessToken token = null;
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
token = cache.grantFileAccess(params, fstate, FileStatus.NotExist);
if(logger.isDebugEnabled())
{
logger.debug("create file created lock token:" + token);
}
}
try
{
NetworkFile newFile = diskInterface.createFile(sess, tree, params);
newFile.setAccessToken(token);
if(tctx.hasStateCache())
{
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
// Indicate that the file is open
fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists);
long allocationSize = params.getAllocationSize();
if(allocationSize > 0)
{
fstate.setAllocationSize(allocationSize);
fstate.setFileSize(allocationSize);
}
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)
{
NodeRefNetworkFile x = (NodeRefNetworkFile)newFile;
x.setProcessId( params.getProcessId());
x.setAccessToken(token);
}
if (newFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)newFile;
x.setAccessToken(token);
}
return newFile;
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("create file exception caught", ie);
}
if(tctx.hasStateCache() && token != null)
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), false);
if(fstate != null && token != null)
{
if(logger.isDebugEnabled())
{
logger.debug("create file release lock token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
}
throw ie;
}
}
@Override
public NetworkFile openFile(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
String path = params.getPath();
FileAccessToken token = null;
if(tctx.hasStateCache())
{
if(!params.isDirectory())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
token = cache.grantFileAccess(params, fstate, FileStatus.Unknown);
if(logger.isDebugEnabled())
{
logger.debug("open file created lock token:" + token);
}
}
}
try
{
NetworkFile openFile = diskInterface.openFile(sess, tree, params);
openFile.setAccessToken(token);
FileState fstate = null;
if(tctx.hasStateCache())
{
fstate = tctx.getStateCache().findFileState( path, true);
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
// Access date time is read/write time not open time
// fstate.updateAccessDateTime();
fstate.setFileSize(openFile.getFileSize());
fstate.updateChangeDateTime(openFile.getModifyDate());
fstate.updateModifyDateTime(openFile.getModifyDate());
}
if (openFile instanceof ContentNetworkFile)
{
ContentNetworkFile x = (ContentNetworkFile)openFile;
x.setProcessId( params.getProcessId());
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
else if (openFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)openFile;
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
else if (openFile instanceof AlfrescoFolder)
{
AlfrescoFolder x = (AlfrescoFolder)openFile;
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.DirectoryExists);
}
}
else if (openFile instanceof NetworkFile)
{
NetworkFile x = (NetworkFile)openFile;
if(fstate != null)
{
// NetworkFile does not have setFileState
//x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
return openFile;
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("open file exception caught", ie);
}
if(tctx.hasStateCache() && token != null)
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), false);
if(fstate != null)
{
if(logger.isDebugEnabled())
{
logger.debug("open file release lock token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
}
throw ie;
}
}
@Override
public void closeFile(SrvSession sess, TreeConnection tree,
NetworkFile param) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
if(logger.isDebugEnabled())
{
logger.debug("closeFile:" + param.getFullName() + ", accessToken:" + param.getAccessToken());
}
try
{
diskInterface.closeFile(sess, tree, param);
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( param.getFullName(), true);
if(fstate.getOpenCount() ==0 )
{
logger.debug("OpenCount = 0, reset shared access to READ WRITE DELETE");
fstate.setSharedAccess( SharingMode.READWRITE + SharingMode.DELETE);
fstate.setAllocationSize(-1);
fstate.setFileSize(-1);
fstate.updateChangeDateTime(0);
fstate.updateModifyDateTime(0);
}
if(fstate != null && param.getAccessToken() != null)
{
FileAccessToken token = param.getAccessToken();
if(logger.isDebugEnabled() && token != null)
{
logger.debug("close file release access token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
}
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("close file exception caught", ie);
}
throw ie;
}
}
@Override
public void registerContext(DeviceContext ctx) throws DeviceContextException
{
diskInterface.registerContext(ctx);
}
public void setDiskInterface(ExtendedDiskInterface diskInterface)
{
this.diskInterface = diskInterface;
}
public ExtendedDiskInterface getDiskInterface()
{
return diskInterface;
}
@Override
public void createDirectory(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
diskInterface.createDirectory(sess, tree, params);
}
@Override
public void deleteDirectory(SrvSession sess, TreeConnection tree, String dir)
throws IOException
{
diskInterface.deleteDirectory(sess, tree, dir);
}
@Override
public void deleteFile(SrvSession sess, TreeConnection tree, String name)
throws IOException
{
diskInterface.deleteFile(sess, tree, name);
}
@Override
public int fileExists(SrvSession sess, TreeConnection tree, String name)
{
return diskInterface.fileExists(sess, tree, name);
}
@Override
public void flushFile(SrvSession sess, TreeConnection tree, NetworkFile file)
throws IOException
{
diskInterface.flushFile(sess, tree, file);
}
@Override
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree,
String name) throws IOException
{
return diskInterface.getFileInformation(sess, tree, name);
}
@Override
public boolean isReadOnly(SrvSession sess, DeviceContext ctx)
throws IOException
{
return diskInterface.isReadOnly(sess, ctx);
}
@Override
public int readFile(SrvSession sess, TreeConnection tree, NetworkFile file,
byte[] buf, int bufPos, int siz, long filePos) throws IOException
{
return diskInterface.readFile(sess, tree, file, buf, bufPos, siz, filePos);
}
@Override
public void renameFile(SrvSession sess, TreeConnection tree,
String oldName, String newName) throws IOException
{
diskInterface.renameFile(sess, tree, oldName, newName);
}
@Override
public long seekFile(SrvSession sess, TreeConnection tree,
NetworkFile file, long pos, int typ) throws IOException
{
return diskInterface.seekFile(sess, tree, file, pos, typ);
}
@Override
public void setFileInformation(SrvSession sess, TreeConnection tree,
String name, FileInfo info) throws IOException
{
diskInterface.setFileInformation(sess, tree, name, info);
ContentContext tctx = (ContentContext) tree.getContext();
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( name, true);
// if ( info.hasSetFlag(FileInfo.SetCreationDate))
// {
// if ( logger.isDebugEnabled())
// {
// logger.debug("Set creation date in file state cache" + name + ", " + info.getCreationDateTime());
// }
// Date createDate = new Date( info.getCreationDateTime());
// fstate.u(createDate.getTime());
// }
if ( info.hasSetFlag(FileInfo.SetModifyDate))
{
if ( logger.isDebugEnabled())
{
logger.debug("Set modification date in file state cache" + name + ", " + info.getModifyDateTime());
}
Date modifyDate = new Date( info.getModifyDateTime());
fstate.updateModifyDateTime(modifyDate.getTime());
}
}
}
@Override
public SearchContext startSearch(SrvSession sess, TreeConnection tree,
String searchPath, int attrib) throws FileNotFoundException
{
return diskInterface.startSearch(sess, tree, searchPath, attrib);
}
@Override
public void truncateFile(SrvSession sess, TreeConnection tree,
NetworkFile file, long siz) throws IOException
{
diskInterface.truncateFile(sess, tree, file, siz);
}
@Override
public int writeFile(SrvSession sess, TreeConnection tree,
NetworkFile file, byte[] buf, int bufoff, int siz, long fileoff)
throws IOException
{
return diskInterface.writeFile(sess, tree, file, buf, bufoff, siz, fileoff);
}
@Override
public DeviceContext createContext(String shareName, ConfigElement args)
throws DeviceContextException
{
return diskInterface.createContext(shareName, args);
}
}