From 8c50fd8db4808197112160cdc0faf8a596f2f2b5 Mon Sep 17 00:00:00 2001 From: Siddharth Boobna Date: Tue, 16 Feb 2016 16:49:01 -0800 Subject: [PATCH] BOOKKEEPER-900: release underreplicated lock when replicating to read only bookie Change-Id: I46782877af3db29b29c5e1585e54757086763bf0 --- .../replication/ReplicationWorker.java | 1 + .../replication/TestReplicationWorker.java | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java index 4239b6a0920..1a10667e673 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java @@ -252,6 +252,7 @@ private boolean rereplicate(long ledgerIdToReplicate) throws InterruptedExceptio LOG.warn("BKLedgerRecoveryException " + "while replicating the fragment", e); if (admin.getReadOnlyBookies().contains(targetBookie)) { + underreplicationManager.releaseUnderreplicatedLedger(ledgerIdToReplicate); throw new BKException.BKWriteOnReadOnlyBookieException(); } } diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java index 9591ef86b10..8aebae47ebc 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java @@ -19,6 +19,17 @@ */ package org.apache.bookkeeper.replication; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Map.Entry; +import java.util.Set; + import org.apache.bookkeeper.client.BKException; import org.apache.bookkeeper.client.BookKeeper; import org.apache.bookkeeper.client.ClientUtil; @@ -32,22 +43,12 @@ import org.apache.bookkeeper.proto.BookieServer; import org.apache.bookkeeper.test.MultiLedgerManagerTestCase; import org.apache.bookkeeper.util.BookKeeperConstants; -import org.apache.bookkeeper.util.ZkUtils; import org.apache.bookkeeper.zookeeper.ZooKeeperClient; -import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase; import org.apache.zookeeper.ZooKeeper; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Map.Entry; -import java.util.Set; - -import static org.junit.Assert.*; - /** * Test the ReplicationWroker, where it has to replicate the fragments from * failed Bookies to given target Bookie. @@ -58,6 +59,7 @@ public class TestReplicationWorker extends MultiLedgerManagerTestCase { private static final Logger LOG = LoggerFactory .getLogger(TestReplicationWorker.class); private String basePath = ""; + private String baseLockPath = ""; private LedgerManagerFactory mFactory; private LedgerUnderreplicationManager underReplicationManager; private static byte[] data = "TestReplicationWorker".getBytes(); @@ -72,6 +74,9 @@ public TestReplicationWorker(String ledgerManagerFactory) { basePath = baseClientConf.getZkLedgersRootPath() + '/' + BookKeeperConstants.UNDER_REPLICATION_NODE + BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH; + baseLockPath = baseClientConf.getZkLedgersRootPath() + '/' + + BookKeeperConstants.UNDER_REPLICATION_NODE + + "/locks"; baseConf.setRereplicationEntryBatchSize(3); } @@ -535,6 +540,7 @@ public void testRWShutdownOnLocalBookieReadonlyTransition() throws Exception { while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath) && rw.isRunning()) { Thread.sleep(100); } + assertNull(zkc.exists(String.format("%s/urL%010d", baseLockPath, lh.getId()), false)); assertFalse("RW should shutdown if the bookie is readonly", rw.isRunning()); } finally { rw.shutdown();