[Swift-commit] r5818 - in trunk/src/org/griphyn/vdl: mapping/file util

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Fri Jul 6 01:15:36 CDT 2012


Author: hategan
Date: 2012-07-06 01:15:35 -0500 (Fri, 06 Jul 2012)
New Revision: 5818

Modified:
   trunk/src/org/griphyn/vdl/mapping/file/FileGarbageCollector.java
   trunk/src/org/griphyn/vdl/util/VDL2Config.java
   trunk/src/org/griphyn/vdl/util/VDL2ConfigProperties.java
Log:
added option to disable file garbage collection

Modified: trunk/src/org/griphyn/vdl/mapping/file/FileGarbageCollector.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/file/FileGarbageCollector.java	2012-07-05 01:56:35 UTC (rev 5817)
+++ trunk/src/org/griphyn/vdl/mapping/file/FileGarbageCollector.java	2012-07-06 06:15:35 UTC (rev 5818)
@@ -17,6 +17,7 @@
 
 package org.griphyn.vdl.mapping.file;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -26,6 +27,8 @@
 
 import org.apache.log4j.Logger;
 import org.griphyn.vdl.mapping.PhysicalFormat;
+import org.griphyn.vdl.util.VDL2Config;
+import org.griphyn.vdl.util.VDL2ConfigProperties;
 
 public class FileGarbageCollector implements Runnable {
     public static final Logger logger = Logger.getLogger(FileGarbageCollector.class);
@@ -43,22 +46,36 @@
     private Thread thread;
     private Map<PhysicalFormat, Integer> usageCount;
     private Set<PhysicalFormat> persistent;
-    private boolean shutdown, done;
+    private boolean shutdown, done, enabled;
     
     public FileGarbageCollector() {
         queue = new LinkedList<PhysicalFormat>();
         usageCount = new HashMap<PhysicalFormat, Integer>();
         persistent = new HashSet<PhysicalFormat>();
-        thread = new Thread(this, "File Garbage Collector");
-        thread.setDaemon(true);
-        thread.start();
+        try {
+            enabled = !"false".equals(VDL2Config.getConfig().getProperty(VDL2ConfigProperties.FILE_GC_ENABLED));
+        }
+        catch (IOException e) {
+            //enabled by default
+            enabled = true;
+        }
+        if (enabled) {
+            thread = new Thread(this, "File Garbage Collector");
+            thread.setDaemon(true);
+            thread.start();
+        }
     }
     
     public synchronized void markAsPersistent(PhysicalFormat pf) {
-        persistent.add(pf);
+        if (enabled) {
+            persistent.add(pf);
+        }
     }
     
     public synchronized void decreaseUsageCount(PhysicalFormat pf) {
+        if (!enabled) {
+            return;
+        }
         assert Thread.holdsLock(this);
         Integer c = usageCount.get(pf);
         if (c == null) {
@@ -84,6 +101,9 @@
     }
     
     public synchronized void increaseUsageCount(PhysicalFormat pf) {
+        if (!enabled) {
+            return;
+        }
         // a usage count of 1 is assumed if the key is not in the map
         // A remap of a remappable mapper would increase the usage count to 2 
         Integer c = usageCount.get(pf);
@@ -125,7 +145,7 @@
 
     public void waitFor() throws InterruptedException {
         shutdown = true;
-        while (!done) {
+        while (!done && enabled) {
             synchronized(this) {
                 notify();
             }

Modified: trunk/src/org/griphyn/vdl/util/VDL2Config.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/VDL2Config.java	2012-07-05 01:56:35 UTC (rev 5817)
+++ trunk/src/org/griphyn/vdl/util/VDL2Config.java	2012-07-06 06:15:35 UTC (rev 5818)
@@ -117,6 +117,8 @@
 		put("use.provider.staging", "false");
 		put("ticker.date.format", "");
 		put("ticker.prefix", "Progress:  time:");
+		
+		put(VDL2ConfigProperties.FILE_GC_ENABLED, "true");
 	}
 
 	private VDL2Config(VDL2Config other) {

Modified: trunk/src/org/griphyn/vdl/util/VDL2ConfigProperties.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/VDL2ConfigProperties.java	2012-07-05 01:56:35 UTC (rev 5817)
+++ trunk/src/org/griphyn/vdl/util/VDL2ConfigProperties.java	2012-07-06 06:15:35 UTC (rev 5818)
@@ -42,6 +42,7 @@
 	public static final String WRAPPERLOG_ALWAYS_TRANSFER = "wrapperlog.always.transfer";
 	public static final String SITEDIR_KEEP = "sitedir.keep";
 	public static final String PROVENANCE_LOG = "provenance.log";
+	public static final String FILE_GC_ENABLED = "file.gc.enabled";
 	public static final Map<String, PropInfo> PROPERTIES;
 
 	static {
@@ -133,6 +134,9 @@
 					"<true|false>",
 					"If set to true, will record provenance information in the log file"));
 
+		PROPERTIES.put(FILE_GC_ENABLED, new PropInfo("<true|false>", "Allows disabling the file garbage collector. " +
+				"If set to false, files mapped by collectable mappers (such as the concurrent mapper) will not be " +
+				"deleted when their swift variables go out of scope."));
 	}
 
 	public static Map<String, PropInfo> getPropertyDescriptions() {




More information about the Swift-commit mailing list