From bccd10de1123f82e89feee2a8e3216ed24edc5d1 Mon Sep 17 00:00:00 2001 From: jxiang Date: Thu, 24 Oct 2013 01:14:30 +0000 Subject: [PATCH] HBASE-9827 Intermittent TestLogRollingNoCluster#testContendedLogRolling failure git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1535254 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/wal/FSHLog.java | 8 +++++--- .../hbase/regionserver/wal/TestHLog.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java index d7839bdab96..4d0ab78cad5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java @@ -27,7 +27,6 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -50,13 +49,12 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Syncable; -import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; import org.apache.hadoop.hbase.util.DrainBarrier; @@ -499,6 +497,10 @@ class FSHLog implements HLog, Syncable { } this.filenum = System.currentTimeMillis(); Path newPath = computeFilename(); + while (fs.exists(newPath)) { + this.filenum++; + newPath = computeFilename(); + } // Tell our listeners that a new log is about to be created if (!this.listeners.isEmpty()) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java index e295a42ccd9..0654752c654 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java @@ -711,6 +711,24 @@ public class TestHLog { } } + @Test + public void testFailedToCreateHLogIfParentRenamed() throws IOException { + FSHLog log = (FSHLog)HLogFactory.createHLog( + fs, hbaseDir, "testFailedToCreateHLogIfParentRenamed", conf); + long filenum = System.currentTimeMillis(); + Path path = log.computeFilename(filenum); + HLogFactory.createWALWriter(fs, path, conf); + Path parent = path.getParent(); + path = log.computeFilename(filenum + 1); + Path newPath = new Path(parent.getParent(), parent.getName() + "-splitting"); + fs.rename(parent, newPath); + try { + HLogFactory.createWALWriter(fs, path, conf); + fail("It should fail to create the new WAL"); + } catch (IOException ioe) { + // expected, good. + } + } @Test public void testGetServerNameFromHLogDirectoryName() throws IOException {