diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java index 474f4975043..a6b6dd8dd6e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java @@ -95,8 +95,8 @@ public class ReplicationLogCleaner extends BaseLogCleanerDelegate implements Abo * not be included. */ private Set loadWALsFromQueues() throws KeeperException { - int v0 = replicationQueues.getQueuesZNodeCversion(); for (int retry = 0; ; retry++) { + int v0 = replicationQueues.getQueuesZNodeCversion(); List rss = replicationQueues.getListOfReplicators(); if (rss == null) { LOG.debug("Didn't find any region server that replicates, won't prevent any deletions."); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java index 768b0157392..f874523aac3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java @@ -20,7 +20,9 @@ package org.apache.hadoop.hbase.master.cleaner; import static org.junit.Assert.assertEquals; import java.io.IOException; +import java.lang.reflect.Field; import java.net.URLEncoder; +import java.util.LinkedList; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; @@ -36,6 +38,8 @@ import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.replication.ReplicationFactory; import org.apache.hadoop.hbase.replication.ReplicationQueues; +import org.apache.hadoop.hbase.replication.ReplicationQueuesClient; +import org.apache.hadoop.hbase.replication.master.ReplicationLogCleaner; import org.apache.hadoop.hbase.replication.regionserver.Replication; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -45,6 +49,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category({MasterTests.class, MediumTests.class}) public class TestLogsCleaner { @@ -126,6 +131,7 @@ public class TestLogsCleaner { assertEquals(34, fs.listStatus(oldLogDir).length); LogCleaner cleaner = new LogCleaner(1000, server, conf, fs, oldLogDir); + cleaner.chore(); // We end up with the current log file, a newer one and the 3 old log @@ -142,6 +148,24 @@ public class TestLogsCleaner { } } + @Test(timeout=5000) + public void testZnodeCversionChange() throws Exception { + Configuration conf = TEST_UTIL.getConfiguration(); + ReplicationLogCleaner cleaner = new ReplicationLogCleaner(); + cleaner.setConf(conf); + + ReplicationQueuesClient rqcMock = Mockito.mock(ReplicationQueuesClient.class); + Mockito.when(rqcMock.getQueuesZNodeCversion()).thenReturn(1, 2, 3, 4); + + Field rqc = ReplicationLogCleaner.class.getDeclaredField("replicationQueues"); + rqc.setAccessible(true); + + rqc.set(cleaner, rqcMock); + + // This should return eventually when cversion stabilizes + cleaner.getDeletableFiles(new LinkedList()); + } + static class DummyServer implements Server { @Override