You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2014/08/02 06:02:46 UTC

git commit: HBASE-11652 Port HBASE-3270 and HBASE-11650 to 0.94 - create cluster id and version file in a tmp location and move it into place. (LarsH, original patches by Andrew Purtell)

Repository: hbase
Updated Branches:
  refs/heads/0.94 b3b224ddc -> cce7a9770


HBASE-11652 Port HBASE-3270 and HBASE-11650 to 0.94 - create cluster id and version file in a tmp location and move it into place. (LarsH, original patches by Andrew Purtell)


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

Branch: refs/heads/0.94
Commit: cce7a9770cb8353ccd9faab9fb5cb44ef155101e
Parents: b3b224d
Author: Lars Hofhansl <la...@apache.org>
Authored: Fri Aug 1 21:01:55 2014 -0700
Committer: Lars Hofhansl <la...@apache.org>
Committed: Fri Aug 1 21:01:55 2014 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/util/FSUtils.java     | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/cce7a977/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java b/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
index fe30f4c..24dde30 100644
--- a/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
+++ b/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
@@ -470,13 +470,17 @@ 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 tmpFile = new Path(new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY), HConstants.VERSION_FILE_NAME);
     while (true) {
       try {
-        FSDataOutputStream s = fs.create(versionFile);
+        FSDataOutputStream s = fs.create(tmpFile);
         s.writeUTF(version);
+        s.close();
+        if (!fs.rename(tmpFile, versionFile)) {
+          throw new IOException("Unable to move temp version file to " + versionFile);
+        }
         LOG.debug("Created version file at " + rootdir.toString() +
             " set its version at:" + version);
-        s.close();
         return;
       } catch (IOException e) {
         if (retries > 0) {
@@ -567,14 +571,18 @@ public abstract class FSUtils {
    */
   public static void setClusterId(FileSystem fs, Path rootdir, String clusterId,
       int wait) throws IOException {
+    Path idFfile = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
+    Path tmpFile = new Path(new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY), HConstants.CLUSTER_ID_FILE_NAME);
     while (true) {
       try {
-        Path filePath = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
-        FSDataOutputStream s = fs.create(filePath);
+        FSDataOutputStream s = fs.create(tmpFile);
         s.writeUTF(clusterId);
         s.close();
+        if (!fs.rename(tmpFile, idFfile)) {
+          throw new IOException("Unable to move temp version file to " + idFfile);
+        }
         if (LOG.isDebugEnabled()) {
-          LOG.debug("Created cluster ID file at " + filePath.toString() +
+          LOG.debug("Created cluster ID file at " + idFfile.toString() +
               " with ID: " + clusterId);
         }
         return;