From 3ca2bd733936b5c21a719930267fa3f09795099c Mon Sep 17 00:00:00 2001 From: jxiang Date: Fri, 3 May 2013 17:19:27 +0000 Subject: [PATCH] HBASE-8485 Retry to open a HLog on more exceptions git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1478880 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/wal/HLogFactory.java | 5 +++-- .../hadoop/hbase/regionserver/wal/TestHLogSplit.java | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogFactory.java index 83db320d4c7..fb97f221dc5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogFactory.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogFactory.java @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.regionserver.wal.HLog.Reader; import org.apache.hadoop.hbase.regionserver.wal.HLog.Writer; -import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CancelableProgressable; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; @@ -129,7 +128,9 @@ public class HLogFactory { } } catch (IOException e) { String msg = e.getMessage(); - if (msg != null && msg.contains("Cannot obtain block length")) { + if (msg != null && (msg.contains("Cannot obtain block length") + || msg.contains("Could not obtain the last block") + || msg.matches("Blocklist for [^ ]* has changed.*"))) { if (++nbAttempt == 1) { LOG.warn("Lease should have recovered. This is not expected. Will retry", e); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLogSplit.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLogSplit.java index 9438fb929db..83ef82d66c4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLogSplit.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLogSplit.java @@ -889,7 +889,8 @@ public class TestHLogSplit { fs.initialize(fs.getUri(), conf); FileSystem spiedFs = Mockito.spy(fs); - // The "Cannot obtain block length" part is very important, + // The "Cannot obtain block length", "Could not obtain the last block", + // and "Blocklist for [^ ]* has changed.*" part is very important, // that's how it comes out of HDFS. If HDFS changes the exception // message, this test needs to be adjusted accordingly. // @@ -898,11 +899,14 @@ public class TestHLogSplit { // last block is under recovery, HDFS may have problem to obtain // the block length, in which case, retry may help. Mockito.doAnswer(new Answer() { + private final String[] errors = new String[] { + "Cannot obtain block length", "Could not obtain the last block", + "Blocklist for " + OLDLOGDIR + " has changed"}; private int count = 0; public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable { - if (count++ < 3) { - throw new IOException("Cannot obtain block length"); + if (count < 3) { + throw new IOException(errors[count++]); } return (FSDataInputStream)invocation.callRealMethod(); }