accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [2/5] git commit: ACCUMULO-2174 Provide a better VFS tmpdir default that won't collide across processes
Date Sat, 11 Jan 2014 00:15:32 GMT
ACCUMULO-2174 Provide a better VFS tmpdir default that won't collide across processes


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/db56d8d2
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/db56d8d2
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/db56d8d2

Branch: refs/heads/master
Commit: db56d8d21dc636e6d271ae4c710ed27196a24506
Parents: 56230eb
Author: Josh Elser <elserj@apache.org>
Authored: Fri Jan 10 17:51:29 2014 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Fri Jan 10 18:34:46 2014 -0500

----------------------------------------------------------------------
 .../classloader/vfs/AccumuloVFSClassLoader.java |  8 +++--
 .../classloader/vfs/UniqueFileReplicator.java   | 32 ++++++++++++--------
 2 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/db56d8d2/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
index eb653bc..90c6358 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.start.classloader.vfs;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.lang.ref.WeakReference;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -259,8 +260,9 @@ public class AccumuloVFSClassLoader {
     vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
     vfs.setFilesCache(new SoftRefFilesCache());
     String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, "");
-    File cacheDir = new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-"
+ System.getProperty("user.name", "nouser"));
-    if (!("".equals(cacheDirPath)))
+    String procName = ManagementFactory.getRuntimeMXBean().getName();
+    File cacheDir = new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-"
+ procName + "-" + System.getProperty("user.name", "nouser"));
+    if (!cacheDirPath.isEmpty())
       cacheDir = new File(cacheDirPath);
     vfs.setReplicator(new UniqueFileReplicator(cacheDir));
     vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
@@ -364,7 +366,7 @@ public class AccumuloVFSClassLoader {
     
     return contextManager;
   }
-  
+
   public static void close() {
     for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) {
       DefaultFileSystemManager ref = vfsInstance.get();

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db56d8d2/start/src/main/java/org/apache/accumulo/start/classloader/vfs/UniqueFileReplicator.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/UniqueFileReplicator.java
b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/UniqueFileReplicator.java
index cc19b6e..cdc5248 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/UniqueFileReplicator.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/UniqueFileReplicator.java
@@ -30,18 +30,20 @@ import org.apache.commons.vfs2.provider.FileReplicator;
 import org.apache.commons.vfs2.provider.UriParser;
 import org.apache.commons.vfs2.provider.VfsComponent;
 import org.apache.commons.vfs2.provider.VfsComponentContext;
+import org.apache.log4j.Logger;
 
 /**
  * 
  */
 public class UniqueFileReplicator implements VfsComponent, FileReplicator {
-  
+
   private static final char[] TMP_RESERVED_CHARS = new char[] {'?', '/', '\\', ' ', '&',
'"', '\'', '*', '#', ';', ':', '<', '>', '|'};
+  private static final Logger log = Logger.getLogger(UniqueFileReplicator.class);
   
   private File tempDir;
   private VfsComponentContext context;
   private List<File> tmpFiles = Collections.synchronizedList(new ArrayList<File>());
-  
+
   public UniqueFileReplicator(File tempDir) {
     this.tempDir = tempDir;
   }
@@ -49,38 +51,38 @@ public class UniqueFileReplicator implements VfsComponent, FileReplicator
{
   @Override
   public File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException
{
     String baseName = srcFile.getName().getBaseName();
-    
+
     try {
       tempDir.mkdirs();
       String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_');
       File file = File.createTempFile("vfsr_", "_" + safeBasename, tempDir);
       file.deleteOnExit();
-      
+
       final FileObject destFile = context.toFileObject(file);
       destFile.copyFrom(srcFile, selector);
-      
+
       return file;
     } catch (IOException e) {
       throw new FileSystemException(e);
     }
   }
-  
+
   @Override
   public void setLogger(Log logger) {
     // TODO Auto-generated method stub
-    
+
   }
-  
+
   @Override
   public void setContext(VfsComponentContext context) {
     this.context = context;
   }
-  
+
   @Override
   public void init() throws FileSystemException {
-    
+
   }
-  
+
   @Override
   public void close() {
     synchronized (tmpFiles) {
@@ -88,7 +90,11 @@ public class UniqueFileReplicator implements VfsComponent, FileReplicator
{
         tmpFile.delete();
       }
     }
-    
-    tempDir.delete();
+
+    if (tempDir.exists()) {
+      int numChildren = tempDir.list().length;
+      if (0 == numChildren && !tempDir.delete())
+        log.warn("Cannot delete empty directory: " + tempDir);
+    }
   }
 }


Mime
View raw message