hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject [40/50] [abbrv] git commit: [HBASE-11379] fixed exception-handling in the writing of .regioninfo files
Date Thu, 31 Jul 2014 22:08:16 GMT
[HBASE-11379] fixed exception-handling in the writing of .regioninfo files

Summary: error exceptions when writing .regioninfo files were not being handled properly

Test Plan: n/a

Reviewers: elliott, daviddeng

Reviewed By: daviddeng

Subscribers: elliott, hbase-eng@

Differential Revision: https://phabricator.fb.com/D1418950

git-svn-id: svn+ssh://tubbs/svnhive/hadoop/branches/titan/VENDOR.hbase/hbase-trunk@43315 e7acf4d4-3532-417f-9e73-7a9ae25a1f51


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

Branch: refs/heads/0.89-fb
Commit: 451e39bf9c8c6820054ddb9c9be7830be5b9847b
Parents: 797de59
Author: yuq <yuq@e7acf4d4-3532-417f-9e73-7a9ae25a1f51>
Authored: Fri Jul 4 00:39:41 2014 +0000
Committer: Elliott Clark <elliott@fb.com>
Committed: Thu Jul 31 14:44:24 2014 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/HRegionInfo.java    | 41 ++++++++++----------
 .../org/apache/hadoop/hbase/master/HMaster.java | 32 +++++++--------
 .../hadoop/hbase/regionserver/HRegion.java      |  4 +-
 .../client/TestHBaseFsckFixRegionInfo.java      |  4 --
 4 files changed, 36 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/451e39bf/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
index 63701cb..54832ac 100644
--- a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
+++ b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
@@ -708,13 +708,12 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
    * This method writes the .regioninfo file. This method is synchronized so that no two
threads
    * attempt to write the same .regioninfo file at the same time.
    * @param conf
-   * @return true if the write was successful
    * @throws IOException
    */
-  public synchronized boolean writeToDisk(Configuration conf) throws IOException {
+  public synchronized void writeToDisk(Configuration conf) throws IOException {
     Path rootDir = new Path(conf.get(HConstants.HBASE_DIR));
     FileSystem fs = rootDir.getFileSystem(conf);
-    return writeToDisk(conf, fs);
+    writeToDisk(conf, fs);
   }
 
   /**
@@ -722,34 +721,34 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
    * attempt to write the same .regioninfo file at the same time.
    * @param conf
    * @param fs
-   * @return true if the write is successful
    * @throws IOException
    */
-  public synchronized boolean writeToDisk(Configuration conf, FileSystem fs) throws IOException
{
+  public synchronized void writeToDisk(Configuration conf, FileSystem fs) throws IOException
{
     Path tableDir =
         HTableDescriptor.getTableDir(FSUtils.getRootDir(conf), this.getTableDesc().getName());
     Path regionPath = HRegion.getRegionDir(tableDir, this.getEncodedName());
     Path regionInfoPath = new Path(regionPath, HRegion.REGIONINFO_FILE);
-    FSDataOutputStream out = fs.create(regionInfoPath, true);
-    boolean successfulWrite = true;
     try {
-      // we write to file the information necessary to reconstruct this HRegionInfo via readFields()
-      // this.toString() calls tableDesc.toString(), so this file will contain back-up information
-      // for the table
-      write(out);
-      out.write(NEWLINE);
-      out.write(NEWLINE);
-      out.write(Bytes.toBytes(this.toString()));
-      LOG.debug("Rewrote .regioninfo file of " + this.getRegionNameAsString() + " at "
-          + regionInfoPath);
+      FSDataOutputStream out = fs.create(regionInfoPath);
+      try {
+        // we write to file the information necessary to reconstruct this HRegionInfo via
+        // readFields()
+        // this.toString() calls tableDesc.toString(), so this file will contain back-up
information
+        // for the table
+        write(out);
+        out.write(NEWLINE);
+        out.write(NEWLINE);
+        out.write(Bytes.toBytes(this.toString()));
+        LOG.debug("Rewrote .regioninfo file of " + this.getRegionNameAsString() + " at "
+            + regionInfoPath);
+      } finally {
+        out.close();
+        LOG.debug(".regioninfo File Contents: " + this.toString());
+      }
     } catch (IOException e) {
-      successfulWrite = false;
       LOG.error("Could not rewrite the .regioninfo of " + this.getRegionNameAsString() +
" at "
           + regionInfoPath, e);
-    } finally {
-      out.close();
-      LOG.debug(".regioninfo File Contents: " + this.toString());
+      throw e;
     }
-    return successfulWrite;
   }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/451e39bf/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 9b51280..959a070 100755
--- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -42,6 +42,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -112,6 +113,7 @@ import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.hbase.util.ExceptionUtils;
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.HasThread;
 import org.apache.hadoop.hbase.util.InfoServer;
@@ -1670,38 +1672,32 @@ HMasterRegionInterface, Watcher, StoppableMaster {
    * This method rewrites all .regioninfo files for all regions belonging to the Table whose
name is
    * tableName
    * @param tableName
-   * @return true if all .regioninfo files that belong to the table are successfully rewritten.
    * @throws IOException
    * @throws ExecutionException
    * @throws InterruptedException
    */
-  public boolean writeRegionInfo(byte[] tableName) throws Exception {
+  public void writeRegionInfo(byte[] tableName) throws IOException, InterruptedException{
     List<Pair<HRegionInfo, HServerAddress>> tableRegions = getTableRegions(tableName);
     ExecutorService executor = Executors.newCachedThreadPool();
-    List<Future<Boolean>> futures = new ArrayList<>();
+    List<Future<Void>> futures = new ArrayList<>();
     for (final Pair<HRegionInfo, HServerAddress> entry : tableRegions) {
-      Callable<Boolean> writer = new Callable<Boolean>() {
+      Callable<Void> writer = new Callable<Void>() {
         
-        // return true if the write is successful
-        public Boolean call() {
+        public Void call() throws IOException {
           HRegionInfo hri = entry.getFirst();
-          try {
-            return hri.writeToDisk(conf);
-          } catch (IOException e) {
-            LOG.error("Failed to write .regioninfo for Region: " + hri.getRegionNameAsString(),
e);
-            return false;
-          }
+            hri.writeToDisk(conf);
+          return null;
         }
       };
-      Future<Boolean> future = executor.submit(writer);
-      futures.add(future);
+      futures.add(executor.submit(writer));
     }
-    for (Future<Boolean> f : futures) {
-      if (!f.get()) { // if any write was not successful
-        return false;
+    for (Future<Void> f : futures) {
+      try {
+        f.get();
+      } catch (ExecutionException e) {
+        throw ExceptionUtils.toIOException(e.getCause());
       }
     }
-    return true;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/451e39bf/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index de8ba0b..4f7b42c 100644
--- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -617,7 +617,7 @@ public class HRegion implements HeapSize, ConfigurationObserver, HRegionIf
{
     try {
       // Write HRI to a file in case we need to recover .META.
       status.setStatus("Writing region info on filesystem");
-      checkRegioninfoOnFilesystem();
+      writeRegioninfoOnFilesystem();
 
       // Remove temporary data left over from old regions
       status.setStatus("Cleaning up temporary data from old regions");
@@ -756,7 +756,7 @@ public class HRegion implements HeapSize, ConfigurationObserver, HRegionIf
{
    * mangled regions.
    * @throws IOException
    */
-  private void checkRegioninfoOnFilesystem() throws IOException {
+  private void writeRegioninfoOnFilesystem() throws IOException {
     // Name of this file has two leading and trailing underscores so it doesn't
     // clash w/ a store/family name.  There is possibility, but assumption is
     // that its slim (don't want to use control character in filename because

http://git-wip-us.apache.org/repos/asf/hbase/blob/451e39bf/src/test/java/org/apache/hadoop/hbase/client/TestHBaseFsckFixRegionInfo.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/hadoop/hbase/client/TestHBaseFsckFixRegionInfo.java
b/src/test/java/org/apache/hadoop/hbase/client/TestHBaseFsckFixRegionInfo.java
index 1bbdd34..ee9098f 100644
--- a/src/test/java/org/apache/hadoop/hbase/client/TestHBaseFsckFixRegionInfo.java
+++ b/src/test/java/org/apache/hadoop/hbase/client/TestHBaseFsckFixRegionInfo.java
@@ -123,10 +123,6 @@ public class TestHBaseFsckFixRegionInfo {
 
         // rewrite the original .regioninfo
         hriModified.writeToDisk(conf);
-        System.out.println("SUCCESSFULLY CORRUPTED:"
-            + !hriOriginal.toString().equals(hriModified.toString()));
-        System.out.println("Original " + hriOriginal.toString());
-        System.out.println("Modified: " + hriModified.toString());
         modifyCount++;
       }
     }


Mime
View raw message