Skip to content
Snippets Groups Projects
Commit 0a563da0 authored by anttil's avatar anttil
Browse files

SSDM-4003: New DSS FS (FTP / CIFS) resolvers: More caching, fix bug with CIFS...

SSDM-4003: New DSS FS (FTP / CIFS) resolvers: More caching, fix bug with CIFS session breaking on unavailable file

SVN: 36897
parent d7d8e1c1
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ public class DSSFileSearchContext extends SearchContext ...@@ -40,7 +40,7 @@ public class DSSFileSearchContext extends SearchContext
private int index; private int index;
public DSSFileSearchContext(DSSFileSystemView view, String normalizedSearchPath, int fileAttributes, public DSSFileSearchContext(DSSFileSystemView view, String normalizedSearchPath, int fileAttributes,
Cache cache) throws FileNotFoundException Cache cache) throws FileNotFoundException
{ {
String[] pathStr = FileName.splitPath(normalizedSearchPath, java.io.File.separatorChar); String[] pathStr = FileName.splitPath(normalizedSearchPath, java.io.File.separatorChar);
...@@ -77,7 +77,7 @@ public class DSSFileSearchContext extends SearchContext ...@@ -77,7 +77,7 @@ public class DSSFileSearchContext extends SearchContext
FtpFile file = view.getFile(path, cache); FtpFile file = view.getFile(path, cache);
if (file instanceof NonExistingFtpFile) if (file instanceof NonExistingFtpFile)
{ {
throw new FtpException(file.getAbsolutePath() + " doesn't exist. Reason: " throw new FtpException(file.getAbsolutePath() + " doesn't exist. Reason: "
+ ((NonExistingFtpFile) file).getErrorMessage()); + ((NonExistingFtpFile) file).getErrorMessage());
} }
return file; return file;
...@@ -114,8 +114,6 @@ public class DSSFileSearchContext extends SearchContext ...@@ -114,8 +114,6 @@ public class DSSFileSearchContext extends SearchContext
@Override @Override
public String nextFileName() public String nextFileName()
{ {
System.out.println("DSSFileSearchContext.nextFileName()");
// TODO Auto-generated method stub
return null; return null;
} }
...@@ -133,8 +131,6 @@ public class DSSFileSearchContext extends SearchContext ...@@ -133,8 +131,6 @@ public class DSSFileSearchContext extends SearchContext
@Override @Override
public boolean restartAt(FileInfo info) public boolean restartAt(FileInfo info)
{ {
System.out.println("DSSFileSearchContext.restartAt() "+info);
// TODO Auto-generated method stub
return false; return false;
} }
......
...@@ -30,6 +30,7 @@ import org.alfresco.jlan.server.filesys.DiskInterface; ...@@ -30,6 +30,7 @@ import org.alfresco.jlan.server.filesys.DiskInterface;
import org.alfresco.jlan.server.filesys.FileAttribute; import org.alfresco.jlan.server.filesys.FileAttribute;
import org.alfresco.jlan.server.filesys.FileInfo; import org.alfresco.jlan.server.filesys.FileInfo;
import org.alfresco.jlan.server.filesys.FileName; import org.alfresco.jlan.server.filesys.FileName;
import org.alfresco.jlan.server.filesys.FileOfflineException;
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;
import org.alfresco.jlan.server.filesys.NetworkFile; import org.alfresco.jlan.server.filesys.NetworkFile;
...@@ -226,12 +227,18 @@ public class DataSetCifsView implements DiskInterface ...@@ -226,12 +227,18 @@ public class DataSetCifsView implements DiskInterface
} }
operationLog.debug("Read from virtual file '" + file.getFullName() + "' at position " + filePos + " " operationLog.debug("Read from virtual file '" + file.getFullName() + "' at position " + filePos + " "
+ size + " bytes into the buffer of size " + buf.length + " at position " + bufPos + "."); + size + " bytes into the buffer of size " + buf.length + " at position " + bufPos + ".");
int rdlen = file.readFile(buf, size, bufPos, filePos); try
if (rdlen == -1) {
int rdlen = file.readFile(buf, size, bufPos, filePos);
if (rdlen == -1)
{
rdlen = 0;
}
return rdlen;
} catch (RuntimeException e)
{ {
rdlen = 0; throw new FileOfflineException();
} }
return rdlen;
} }
@Override @Override
......
...@@ -23,6 +23,7 @@ import java.util.Map; ...@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.ftpserver.ftplet.FtpFile; import org.apache.ftpserver.ftplet.FtpFile;
import ch.systemsx.cisd.common.utilities.ITimeProvider; import ch.systemsx.cisd.common.utilities.ITimeProvider;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpFile; import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpFile;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData;
...@@ -65,6 +66,10 @@ public class Cache ...@@ -65,6 +66,10 @@ public class Cache
private final Map<String, TimeStampedObject<V3FtpFile>> v3Responses = new HashMap<>(); private final Map<String, TimeStampedObject<V3FtpFile>> v3Responses = new HashMap<>();
private final Map<String, TimeStampedObject<IHierarchicalContent>> contents = new HashMap<>();
private final Map<String, TimeStampedObject<Boolean>> accessData = new HashMap<>();
public Cache(ITimeProvider timeProvider) public Cache(ITimeProvider timeProvider)
{ {
this.timeProvider = timeProvider; this.timeProvider = timeProvider;
...@@ -130,6 +135,26 @@ public class Cache ...@@ -130,6 +135,26 @@ public class Cache
v3Responses.put(key, timestamp(file)); v3Responses.put(key, timestamp(file));
} }
public IHierarchicalContent getContent(String key)
{
return getObject(contents, key);
}
public void putContent(String key, IHierarchicalContent content)
{
contents.put(key, timestamp(content));
}
public Boolean getAccess(String dataSetCode)
{
return getObject(accessData, dataSetCode);
}
public void putAccess(String dataSetCode, Boolean access)
{
accessData.put(dataSetCode, timestamp(access));
}
private <T> TimeStampedObject<T> timestamp(T object) private <T> TimeStampedObject<T> timestamp(T object)
{ {
return new TimeStampedObject<T>(object, timeProvider.getTimeInMilliseconds()); return new TimeStampedObject<T>(object, timeProvider.getTimeInMilliseconds());
......
...@@ -24,6 +24,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetc ...@@ -24,6 +24,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetc
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.DataSetPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.DataSetPermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.IDataSetId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.IDataSetId;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent; import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.Cache;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.FtpPathResolverContext; import ch.systemsx.cisd.openbis.dss.generic.server.ftp.FtpPathResolverContext;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpFile; import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpFile;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpNonExistingFile; import ch.systemsx.cisd.openbis.dss.generic.server.ftp.v3.file.V3FtpNonExistingFile;
...@@ -45,17 +46,33 @@ public class V3DataSetContentResolver implements V3Resolver ...@@ -45,17 +46,33 @@ public class V3DataSetContentResolver implements V3Resolver
@Override @Override
public V3FtpFile resolve(String fullPath, String[] subPath, FtpPathResolverContext context) public V3FtpFile resolve(String fullPath, String[] subPath, FtpPathResolverContext context)
{ {
// this fetching of data set is for authorization purposes, as content provider doesn't check if user has access to data set Cache cache = context.getCache();
IDataSetId id = new DataSetPermId(dataSetCode);
Map<IDataSetId, DataSet> dataSets =
context.getV3Api().getDataSets(context.getSessionToken(), Collections.singletonList(id), new DataSetFetchOptions());
if (dataSets.get(id) == null) Boolean hasAccess = cache.getAccess(dataSetCode);
if (hasAccess == null)
{
// this fetching of data set is for authorization purposes, as content provider doesn't check if user has access to data set
IDataSetId id = new DataSetPermId(dataSetCode);
Map<IDataSetId, DataSet> dataSets =
context.getV3Api().getDataSets(context.getSessionToken(), Collections.singletonList(id), new DataSetFetchOptions());
hasAccess = dataSets.containsKey(id);
cache.putAccess(dataSetCode, hasAccess);
}
if (hasAccess.booleanValue() == false)
{ {
return new V3FtpNonExistingFile(fullPath, "Path doesn't exist or unauthorized"); return new V3FtpNonExistingFile(fullPath, "Path doesn't exist or unauthorized");
} }
IHierarchicalContent content = context.getContentProvider().asContent(dataSetCode); IHierarchicalContent content = cache.getContent(dataSetCode);
if (content == null)
{
content = context.getContentProvider().asContentWithoutModifyingAccessTimestamp(dataSetCode);
cache.putContent(dataSetCode, content);
}
V3HierarchicalContentResolver resolver = new V3HierarchicalContentResolver(content); V3HierarchicalContentResolver resolver = new V3HierarchicalContentResolver(content);
return resolver.resolve(fullPath, subPath, context); return resolver.resolve(fullPath, subPath, context);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment