hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-16062 Improper error handling in WAL Reader/Writer creation (Vladimir Rodionov)
Date Wed, 22 Jun 2016 04:11:28 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 0cbad9c89 -> 5d1dac4ad


HBASE-16062 Improper error handling in WAL Reader/Writer creation (Vladimir Rodionov)


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

Branch: refs/heads/branch-1.3
Commit: 5d1dac4adc7e0b5d59083b76dab196c31b3eca2a
Parents: 0cbad9c
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Jun 21 21:11:19 2016 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Jun 21 21:11:19 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/wal/DefaultWALProvider.java    | 10 +++++++-
 .../org/apache/hadoop/hbase/wal/WALFactory.java | 26 +++++++++++++-------
 2 files changed, 26 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5d1dac4a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DefaultWALProvider.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DefaultWALProvider.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DefaultWALProvider.java
index d4299c9..b618a0f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DefaultWALProvider.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DefaultWALProvider.java
@@ -372,12 +372,20 @@ public class DefaultWALProvider implements WALProvider {
     // Configuration already does caching for the Class lookup.
     Class<? extends Writer> logWriterClass = conf.getClass("hbase.regionserver.hlog.writer.impl",
         ProtobufLogWriter.class, Writer.class);
+    Writer writer = null;
     try {
-      Writer writer = logWriterClass.newInstance();
+      writer = logWriterClass.newInstance();
       writer.init(fs, path, conf, overwritable);
       return writer;
     } catch (Exception e) {
       LOG.debug("Error instantiating log writer.", e);
+      if (writer != null) {
+        try{
+          writer.close();
+        } catch(IOException ee){
+          LOG.error("cannot close log writer", ee);
+        }
+      }
       throw new IOException("cannot get log writer", e);
     }
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/5d1dac4a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java
index 8ef3cab..cf704ba 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALFactory.java
@@ -290,11 +290,12 @@ public class WALFactory {
       long openTimeout = timeoutMillis + startWaiting;
       int nbAttempt = 0;
       FSDataInputStream stream = null;
+      DefaultWALProvider.Reader reader = null;
       while (true) {
         try {
           if (lrClass != ProtobufLogReader.class) {
             // User is overriding the WAL reader, let them.
-            DefaultWALProvider.Reader reader = lrClass.newInstance();
+            reader = lrClass.newInstance();
             reader.init(fs, path, conf, null);
             return reader;
           } else {
@@ -306,19 +307,27 @@ public class WALFactory {
             byte[] magic = new byte[ProtobufLogReader.PB_WAL_MAGIC.length];
             boolean isPbWal = (stream.read(magic) == magic.length)
                 && Arrays.equals(magic, ProtobufLogReader.PB_WAL_MAGIC);
-            DefaultWALProvider.Reader reader =
+            reader =
                 isPbWal ? new ProtobufLogReader() : new SequenceFileLogReader();
             reader.init(fs, path, conf, stream);
             return reader;
           }
         } catch (IOException e) {
-          try {
-            if (stream != null) {
+          if (stream != null) {
+            try {
               stream.close();
+            } catch (IOException exception) {
+              LOG.warn("Could not close DefaultWALProvider.Reader" + exception.getMessage());
+              LOG.debug("exception details", exception);
+            }
+          }
+          if (reader != null) {
+            try {
+              reader.close();
+            } catch (IOException exception) {
+              LOG.warn("Could not close FSDataInputStream" + exception.getMessage());
+              LOG.debug("exception details", exception);
             }
-          } catch (IOException exception) {
-            LOG.warn("Could not close FSDataInputStream" + exception.getMessage());
-            LOG.debug("exception details", exception);
           }
           String msg = e.getMessage();
           if (msg != null && (msg.contains("Cannot obtain block length")
@@ -332,8 +341,7 @@ public class WALFactory {
             }
             if (nbAttempt > 2 && openTimeout < EnvironmentEdgeManager.currentTime())
{
               LOG.error("Can't open after " + nbAttempt + " attempts and "
-                + (EnvironmentEdgeManager.currentTime() - startWaiting)
-                + "ms " + " for " + path);
+                  + (EnvironmentEdgeManager.currentTime() - startWaiting) + "ms " + " for
" + path);
             } else {
               try {
                 Thread.sleep(nbAttempt < 3 ? 500 : 1000);


Mime
View raw message