hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [1/3] git commit: HBASE-3270 When we create the .version file, we should create it in a tmp location and then move it into place
Date Fri, 01 Aug 2014 17:11:32 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 40077a171 -> 5b00dbc63
  refs/heads/branch-1 d34c5d407 -> 85e317b3a
  refs/heads/master 8ec64ec0d -> aba9f5a7f


HBASE-3270 When we create the .version file, we should create it in a tmp location and then
move it into place


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

Branch: refs/heads/master
Commit: aba9f5a7f4067198073f678c81b4e3fbdb4f18ee
Parents: 8ec64ec
Author: Andrew Purtell <apurtell@apache.org>
Authored: Fri Aug 1 10:03:12 2014 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri Aug 1 10:03:12 2014 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/util/FSUtils.java   | 26 +++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/aba9f5a7/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
index 36d9588..23d3437 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
@@ -631,11 +631,31 @@ public abstract class FSUtils {
   public static void setVersion(FileSystem fs, Path rootdir, String version,
       int wait, int retries) throws IOException {
     Path versionFile = new Path(rootdir, HConstants.VERSION_FILE_NAME);
+    Path tempVersionFile = new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY + Path.SEPARATOR
+
+      HConstants.VERSION_FILE_NAME);
     while (true) {
       try {
-        FSDataOutputStream s = fs.create(versionFile);
-        s.write(toVersionByteArray(version));
-        s.close();
+        // Write the version to a temporary file
+        FSDataOutputStream s = fs.create(tempVersionFile);
+        try {
+          s.write(toVersionByteArray(version));
+          s.close();
+          s = null;
+          // Move the temp version file to its normal location. Returns false
+          // if the rename failed. Throw an IOE in that case.
+          if (!fs.rename(tempVersionFile, versionFile)) {
+            throw new IOException("Unable to move temp version file to " + versionFile);
+          }
+        } finally {
+          // Cleaning up the temporary if the rename failed would be trying
+          // too hard. We'll unconditionally create it again the next time
+          // through anyway, files are overwritten by default by create().
+
+          // Attempt to close the stream on the way out if it is still open.
+          try {
+            if (s != null) s.close();
+          } catch (IOException ignore) { }
+        }
         LOG.debug("Created version file at " + rootdir.toString() + " with version=" + version);
         return;
       } catch (IOException e) {


Mime
View raw message