You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2013/01/05 17:33:25 UTC
svn commit: r1429326 - in /commons/proper/vfs/trunk:
core/src/main/java/org/apache/commons/vfs2/provider/hdfs/
core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/ src/changes/
Author: ggregory
Date: Sat Jan 5 16:33:25 2013
New Revision: 1429326
URL: http://svn.apache.org/viewvc?rev=1429326&view=rev
Log:
[VFS-449] HDFS Provider is not removing cached files.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/HdfsFileProviderTest.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java?rev=1429326&r1=1429325&r2=1429326&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java Sat Jan 5 16:33:25 2013
@@ -86,6 +86,7 @@ public class HdfsFileObject extends Abst
}
catch (final FileNotFoundException e)
{
+ this.stat = null;
return;
}
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java?rev=1429326&r1=1429325&r2=1429326&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java Sat Jan 5 16:33:25 2013
@@ -23,6 +23,7 @@ import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs2.CacheStrategy;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
@@ -121,7 +122,16 @@ public class HdfsFileSystem extends Abst
}
}
- FileObject file = this.getFileFromCache(name);
+ boolean useCache = (null != getContext().getFileSystemManager().getFilesCache());
+ FileObject file;
+ if (useCache)
+ {
+ file = this.getFileFromCache(name);
+ }
+ else
+ {
+ file = null;
+ }
if (null == file)
{
String path = null;
@@ -135,13 +145,19 @@ public class HdfsFileSystem extends Abst
}
final Path filePath = new Path(path);
file = new HdfsFileObject((AbstractFileName) name, this, fs, filePath);
- this.putFileToCache(file);
- return file;
- }
- else
- {
- return file;
+ if (useCache)
+ {
+ this.putFileToCache(file);
+ }
+ /**
+ * resync the file information if requested
+ */
+ if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE))
+ {
+ file.refresh();
+ }
}
+ return file;
}
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/HdfsFileProviderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/HdfsFileProviderTest.java?rev=1429326&r1=1429325&r2=1429326&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/HdfsFileProviderTest.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/hdfs/test/HdfsFileProviderTest.java Sat Jan 5 16:33:25 2013
@@ -230,10 +230,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
final FileObject dir = file.getParent();
final FileObject[] children = dir.getChildren();
@@ -247,10 +248,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
// Get a handle to the same file
final FileObject file2 = manager.resolveFile(TEST_FILE1);
Assert.assertEquals(file, file2);
@@ -261,10 +263,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
final Map<String, Object> attributes = file.getContent().getAttributes();
Assert.assertTrue(attributes.containsKey(HdfsFileAttributes.BLOCK_SIZE.toString()));
Assert.assertTrue(attributes.containsKey(HdfsFileAttributes.GROUP.toString()));
@@ -280,10 +283,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
Assert.assertEquals(0, file.getContent().getSize());
}
@@ -292,10 +296,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
file.getContent().getInputStream().close();
}
@@ -304,6 +309,7 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_FILE1);
Assert.assertNotNull(fo);
+ Assert.assertFalse(fo.exists());
}
@Test
@@ -311,10 +317,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
Assert.assertFalse(file.isHidden());
}
@@ -323,10 +330,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
Assert.assertTrue(file.isReadable());
}
@@ -335,10 +343,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
Assert.assertFalse(file.isWriteable());
}
@@ -347,10 +356,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
Assert.assertFalse(-1 == file.getContent().getLastModifiedTime());
}
@@ -359,10 +369,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
file.getContent().getRandomAccessContent(RandomAccessMode.READWRITE).close();
}
@@ -371,10 +382,11 @@ public class HdfsFileProviderTest
{
final FileObject fo = manager.resolveFile(TEST_DIR1);
Assert.assertNotNull(fo);
- Assert.assertTrue(fo.exists());
+ Assert.assertFalse(fo.exists());
// Create the test file
final FileObject file = createTestFile(hdfs);
+ Assert.assertTrue(fo.exists());
file.getContent().getRandomAccessContent(RandomAccessMode.READ).close();
}
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1429326&r1=1429325&r2=1429326&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Sat Jan 5 16:33:25 2013
@@ -26,6 +26,9 @@
<!-- <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
<!-- [Local] Need an easy way to convert from a FileObject to a File. -->
<!-- </action> -->
+ <action issue="VFS-449" dev="ggregory" type="fix" due-to="dlmarion">
+ HDFS Provider is not removing cached files.
+ </action>
<action issue="VFS-442" dev="ggregory" type="add" due-to="dlmarion">
Add an HDFS FileSystem Provider.
</action>