[Swift-commit] r4041 - SwiftApps/SwiftR/Swift/R

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Jan 27 11:32:06 CST 2011


Author: tga
Date: 2011-01-27 11:32:06 -0600 (Thu, 27 Jan 2011)
New Revision: 4041

Modified:
   SwiftApps/SwiftR/Swift/R/Swift.R
Log:
Bugfix: the next request ID to use and the base request directory were both stored in 
global variables which were saved as part of the R workspace.  This lead to a situation where the next request ID could be out of step with the file system if the following sequence of events occur:
* User opens a new workspace, runs a swift*apply function.  This initialises the request directory base to the current process id andthe requestcounter to 0
* User closes and saves the workspace
* User opens the workspace again and runs a swift*apply function.  This uses the previous request directory and a requestcounter of 1
* User closes and doesn't save the workspace
* User opens the workspace and runs a swift*apply function.  A request is executed with a requestcounter of 1 again and stale data from the previous request may still be in the directory.

Once the requestid and the filesystem are out of sync, there are various strange consequences: old request data is overwritten, and old requests are partially reexecuted. 
These did not affect the correctness of the swiftapply results, but could result in large delays as unnecessary tasks were executed.


Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R	2011-01-27 14:47:43 UTC (rev 4040)
+++ SwiftApps/SwiftR/Swift/R/Swift.R	2011-01-27 17:32:06 UTC (rev 4041)
@@ -72,29 +72,28 @@
   }
   user <- Sys.info()[["user"]]
 
-  # Initialize globals if first call in this workspace
-
-  requestdirbase = mget("swift.requestdirbase",envir=globalenv(),ifnotfound=list(NULL))[[1]] # FIXME: state more elegantly?
-  if(is.null(requestdirbase)) {
+  # Initialize globals if first call in this invocation of R
+  # Use the options mechanism so that setting is tied
+  # to lifetime of this R process.  If we stored this in a global
+  # variable, it is possible that, say, directory requests.55555/R0000005
+  # is created, the user exits the session without saving, and therefore
+  # the swift.requestid counter is out of step with the file system
+  requestdirbase = getOption("swift.requestdirbase") 
+  if(!is.null(requestdirbase)) {
+    requestid = getOption("swift.requestid") + 1;
+  }
+  else {
     requestdirbase = sprintf("%s/%s/SwiftR/requests.P%.5d",tmpdir,user,Sys.getpid())
     dir.create(requestdirbase,recursive=TRUE,showWarnings=FALSE)
-    assign("swift.requestdirbase",requestdirbase,globalenv())
+    options(swift.requestdirbase=requestdirbase)
     requestid = 0;
-    assign("swift.requestid",0,globalenv())
   }
-  else {
-    requestid = get("swift.requestid",envir=globalenv()) + 1;
-    assign("swift.requestid",requestid,globalenv())
-  }
+  options(swift.requestid=requestid)
 
   # Execute the calls in batches
 
-#  rundir <- system("mktemp -d SwiftR.run.XXXX",intern=TRUE)  # FIXME: put this in /tmp/$USER/SwiftR/requests
-#  basedir = paste("/tmp/",user,"/SwiftR/requests",sep="")
-#  reqdir <- system(paste("mktemp -d ", basedir, "/SwiftR.run.XXXX",sep=""),intern=TRUE)
   reqdir = sprintf("%s/R%.7d",requestdirbase,requestid)
   dir.create(reqdir,recursive=TRUE,showWarnings=FALSE)
-  #dir.create(reqdir,showWarnings=TRUE)
   if (! quiet) {
       cat("Swift request is in",reqdir,"\n")
   }  




More information about the Swift-commit mailing list