brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/4] git commit: FileBasedObjectStore.put: try rename before mv
Date Tue, 01 Jul 2014 10:53:50 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 490ebbd86 -> 9ca8250bd


FileBasedObjectStore.put: try rename before mv

- system call for `mv` is *very* expensive (about 20ms on my machine),
  and CPU intensive, versus `file.rename` which is < 1ms.
- This change therefore allows us to persist 1000s of entities per
  second, rather than < 50 (because done single-threaded currently).


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

Branch: refs/heads/master
Commit: cbb0ffa0d52e89656c0d596e4dccd4ff91c0e5b4
Parents: b1e27d8
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Jul 1 11:06:07 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Jul 1 11:06:33 2014 +0100

----------------------------------------------------------------------
 .../rebind/persister/FileBasedObjectStore.java  | 28 ++++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cbb0ffa0/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
index 0033f0f..ac00946 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
@@ -308,27 +308,27 @@ public class FileBasedObjectStore implements PersistenceObjectStore
{
      * TODO Java 7 gives an atomic Files.move() which would be preferred.
      */
     static void moveFile(File srcFile, File destFile) throws IOException, InterruptedException
{
+        // Try rename first - it is a *much* cheaper call than invoking a system call in
Java. 
+        // However, rename is not guaranteed cross platform to succeed if the destination
exists,
+        // and not guaranteed to be atomic, but it usually seems to do the right thing...
+        boolean result;
+        result = srcFile.renameTo(destFile);
+        if (result) {
+            if (log.isTraceEnabled()) log.trace("java rename of {} to {} completed", srcFile,
destFile);
+            return;
+        }
+        
         if (!Os.isMicrosoftWindows()) {
             // this command, if it succeeds, is guaranteed to be atomic, and it will usually
overwrite
-            int result;
             String cmd = "mv '"+srcFile.getAbsolutePath()+"' '"+destFile.getAbsolutePath()+"'";
             
-            result = new ProcessTool().execCommands(MutableMap.<String,String>of(),
MutableList.of(cmd), null);
+            int exitStatus = new ProcessTool().execCommands(MutableMap.<String,String>of(),
MutableList.of(cmd), null);
             // prefer the above to the below because it wraps it in the appropriate bash
 //            Process proc = Runtime.getRuntime().exec(cmd);
 //            result = proc.waitFor();
             
-            log.trace("FS move of {} to {} completed, code {}", new Object[] { srcFile, destFile,
result });
-            if (result == 0) return;
-        }
-        
-        boolean result;
-        // this is not guaranteed cross platform to succeed if the destination exists,
-        // and not guaranteed to be atomic, but it usually seems to do the right thing...
-        result = srcFile.renameTo(destFile);
-        if (result) {
-            log.trace("java rename of {} to {} completed", srcFile, destFile);
-            return;
+            if (log.isTraceEnabled()) log.trace("FS move of {} to {} completed, code {}",
new Object[] { srcFile, destFile, exitStatus });
+            if (exitStatus == 0) return;
         }
         
         // finally try a delete - but explicitly warn this is not going to be atomic
@@ -339,7 +339,7 @@ public class FileBasedObjectStore implements PersistenceObjectStore {
         }
         destFile.delete();
         result = srcFile.renameTo(destFile);
-        log.trace("java delete and rename of {} to {} completed, code {}", new Object[] {
srcFile, destFile, result });
+        if (log.isTraceEnabled()) log.trace("java delete and rename of {} to {} completed,
code {}", new Object[] { srcFile, destFile, result });
         if (result) 
             return;
         Files.copy(srcFile, destFile);


Mime
View raw message