You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2014/09/16 08:24:00 UTC

git commit: HBASE-11987 Make zk-less table states backward compatible (Andrey Stepachev)

Repository: hbase
Updated Branches:
  refs/heads/master cc6fe16e5 -> 43a8dea34


HBASE-11987 Make zk-less table states backward compatible (Andrey Stepachev)


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

Branch: refs/heads/master
Commit: 43a8dea347fb5c9a7082eaaa23a2d379cdaba9fe
Parents: cc6fe16
Author: stack <st...@apache.org>
Authored: Mon Sep 15 23:23:32 2014 -0700
Committer: stack <st...@apache.org>
Committed: Mon Sep 15 23:23:50 2014 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/util/FSTableDescriptors.java   | 23 +++++++++++++---
 .../hbase/util/TestFSTableDescriptors.java      | 28 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/43a8dea3/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
index bc8fc7f..f05575c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
@@ -596,17 +596,32 @@ public class FSTableDescriptors implements TableDescriptors {
     try {
       td = TableDescriptor.parseFrom(content);
     } catch (DeserializationException e) {
-      throw new IOException("content=" + Bytes.toShort(content), e);
+      // we have old HTableDescriptor here
+      try {
+        HTableDescriptor htd = HTableDescriptor.parseFrom(content);
+        LOG.warn("Found old table descriptor, converting to new format for table " +
+            htd.getTableName() + "; NOTE table will be in ENABLED state!");
+        td = new TableDescriptor(htd, TableState.State.ENABLED);
+        if (rewritePb) rewriteTableDescriptor(fs, status, td);
+      } catch (DeserializationException e1) {
+        throw new IOException("content=" + Bytes.toShort(content), e);
+      }
     }
     if (rewritePb && !ProtobufUtil.isPBMagicPrefix(content)) {
       // Convert the file over to be pb before leaving here.
-      Path tableInfoDir = status.getPath().getParent();
-      Path tableDir = tableInfoDir.getParent();
-      writeTableDescriptor(fs, td, tableDir, status);
+      rewriteTableDescriptor(fs, status, td);
     }
     return td;
   }
 
+  private static void rewriteTableDescriptor(final FileSystem fs, final FileStatus status,
+      final TableDescriptor td)
+  throws IOException {
+    Path tableInfoDir = status.getPath().getParent();
+    Path tableDir = tableInfoDir.getParent();
+    writeTableDescriptor(fs, td, tableDir, status);
+  }
+
   /**
    * Update table descriptor on the file system
    * @throws IOException Thrown if failed update.

http://git-wip-us.apache.org/repos/asf/hbase/blob/43a8dea3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
index 839091c..23b1310 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
@@ -28,6 +28,9 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Comparator;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.hbase.client.TableState;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -42,6 +45,7 @@ import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.TableDescriptors;
 import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.junit.Test;
@@ -175,6 +179,30 @@ public class TestFSTableDescriptors {
     assertTrue(td.equals(td2));
   }
 
+  @Test public void testReadingOldHTDFromFS() throws IOException, DeserializationException {
+    final String name = "testReadingOldHTDFromFS";
+    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
+    Path rootdir = UTIL.getDataTestDir(name);
+    FSTableDescriptors fstd = new FSTableDescriptors(fs, rootdir);
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
+    TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
+    Path descriptorFile = fstd.updateTableDescriptor(td);
+    try (FSDataOutputStream out = fs.create(descriptorFile, true)) {
+      out.write(htd.toByteArray());
+    }
+    FSTableDescriptors fstd2 = new FSTableDescriptors(fs, rootdir);
+    TableDescriptor td2 = fstd2.getDescriptor(htd.getTableName());
+    assertEquals(td, td2);
+    FileStatus descriptorFile2 =
+        FSTableDescriptors.getTableInfoPath(fs, fstd2.getTableDir(htd.getTableName()));
+    byte[] buffer = td.toByteArray();
+    try (FSDataInputStream in = fs.open(descriptorFile2.getPath())) {
+      in.readFully(buffer);
+    }
+    TableDescriptor td3 = TableDescriptor.parseFrom(buffer);
+    assertEquals(td, td3);
+  }
+
   @Test public void testHTableDescriptors()
   throws IOException, InterruptedException {
     final String name = "testHTableDescriptors";