You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by si...@apache.org on 2013/06/26 03:27:04 UTC

svn commit: r1496705 - in /zookeeper/bookkeeper/trunk: CHANGES.txt bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java

Author: sijie
Date: Wed Jun 26 01:27:04 2013
New Revision: 1496705

URL: http://svn.apache.org/r1496705
Log:
BOOKKEEPER-623: LedgerChecker should avoid segments of closed ledger with higher start entryId than closed entry. (vinay via sijie)

Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1496705&r1=1496704&r2=1496705&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Wed Jun 26 01:27:04 2013
@@ -58,6 +58,8 @@ Trunk (unreleased changes)
 	
 	BOOKKEEPER-626: BOOKIE_EXTRA_OPTS are added twice (vinay via fpj)
 
+        BOOKKEEPER-623: LedgerChecker should avoid segments of closed ledger with higher start entryId than closed entry. (vinay via sijie)
+
       hedwig-client:
 
         BOOKKEEPER-598: Fails to compile - RESUBSCRIBE_EXCEPTION conflict (Matthew Farrellee via sijie)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java?rev=1496705&r1=1496704&r2=1496705&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerChecker.java Wed Jun 26 01:27:04 2013
@@ -204,9 +204,7 @@ public class LedgerChecker {
          * NoSuchEntry we can assume it was never written. If they respond with anything
          * else, we must assume the entry has been written, so we run the check.
          */
-        if (curEntryId != null
-            && !(lh.getLastAddConfirmed() == LedgerHandle.INVALID_ENTRY_ID
-                 && lh.getLedgerMetadata().isClosed())) {
+        if (curEntryId != null && !(lh.getLedgerMetadata().isClosed() && lh.getLastAddConfirmed() < curEntryId)) {
             long lastEntry = lh.getLastAddConfirmed();
 
             if (lastEntry < curEntryId) {

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java?rev=1496705&r1=1496704&r2=1496705&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCloseTest.java Wed Jun 26 01:27:04 2013
@@ -20,6 +20,7 @@ package org.apache.bookkeeper.client;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
+import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -29,6 +30,7 @@ import org.apache.bookkeeper.client.Asyn
 import org.apache.bookkeeper.client.BookKeeper.DigestType;
 import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback;
 import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import org.junit.Test;
@@ -57,12 +59,50 @@ public class LedgerCloseTest extends Boo
     @Test(timeout = 60000)
     public void testLedgerCloseDuringUnrecoverableErrors() throws Exception {
         int numEntries = 3;
+        LedgerHandle lh = bkc.createLedger(3, 3, 3, digestType, "".getBytes());
+        verifyMetadataConsistency(numEntries, lh);
+    }
+
+    @Test(timeout = 60000)
+    public void testLedgerCheckerShouldnotSelectInvalidLastFragments() throws Exception {
+        int numEntries = 10;
+        LedgerHandle lh = bkc.createLedger(3, 3, 3, digestType, "".getBytes());
+        // Add some entries before bookie failures
+        for (int i = 0; i < numEntries; i++) {
+            lh.addEntry("data".getBytes());
+        }
+        numEntries = 4; // add n*ensemleSize+1 entries async after bookies
+                        // failed.
+        verifyMetadataConsistency(numEntries, lh);
+
+        LedgerChecker checker = new LedgerChecker(bkc);
+        CheckerCallback cb = new CheckerCallback();
+        checker.checkLedger(lh, cb);
+        Set<LedgerFragment> result = cb.waitAndGetResult();
+        assertEquals("No fragments should be selected", 0, result.size());
+    }
+
+    class CheckerCallback implements GenericCallback<Set<LedgerFragment>> {
+        private Set<LedgerFragment> result = null;
+        private CountDownLatch latch = new CountDownLatch(1);
+
+        public void operationComplete(int rc, Set<LedgerFragment> result) {
+            this.result = result;
+            latch.countDown();
+        }
+
+        Set<LedgerFragment> waitAndGetResult() throws InterruptedException {
+            latch.await();
+            return result;
+        }
+    }
+
+    private void verifyMetadataConsistency(int numEntries, LedgerHandle lh)
+            throws Exception {
         final CountDownLatch addDoneLatch = new CountDownLatch(1);
         final CountDownLatch deadIOLatch = new CountDownLatch(1);
         final CountDownLatch recoverDoneLatch = new CountDownLatch(1);
         final CountDownLatch failedLatch = new CountDownLatch(1);
-
-        LedgerHandle lh = bkc.createLedger(3, 3, 3, digestType, "".getBytes());
         // kill first bookie to replace with a unauthorize bookie
         InetSocketAddress bookie = lh.getLedgerMetadata().currentEnsemble.get(0);
         ServerConfiguration conf = killBookie(bookie);