You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/02/18 08:38:45 UTC

[GitHub] sijie commented on a change in pull request #1163: Issue 1162 - Test for unsetSuccessAndSendWriteRequest with LedgerHand?

sijie commented on a change in pull request #1163: Issue 1162 - Test for unsetSuccessAndSendWriteRequest with LedgerHand?
URL: https://github.com/apache/bookkeeper/pull/1163#discussion_r168943620
 
 

 ##########
 File path: bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
 ##########
 @@ -710,6 +711,83 @@ public void testLedgerCreateAdvWithAsyncWritesWithBookieFailures() throws Except
         lh2.close();
     }
 
+    /**
+     * LedgerHandleAdv out of order writers with ensemble changes.
+     * Verify that entry that was written to old ensemble will be
+     * written to new enseble too after ensemble change.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testLedgerHandleAdvOutOfOrderWriteAndFrocedEnsembleChange() throws Exception {
+        // Create a ledger
+        long ledgerId = 0xABCDEF;
+        SyncObj syncObj1 = new SyncObj();
+        ByteBuffer entry;
+        lh = bkc.createLedgerAdv(ledgerId, 3, 3, 3, digestType, ledgerPassword, null);
+        entry = ByteBuffer.allocate(4);
+        // Add entries 0-4
+        for (int i = 0; i < 5; i++) {
+            entry.rewind();
+            entry.putInt(rng.nextInt(maxInt));
+            lh.addEntry(i, entry.array());
+        }
+
+        // Add 10 as Async Entry, which goes to first ensemble
+        ByteBuffer entry1 = ByteBuffer.allocate(4);
+        entry1.putInt(rng.nextInt(maxInt));
+        lh.asyncAddEntry(10, entry1.array(), 0, entry1.capacity(), this, syncObj1);
+
+        Thread.sleep(5000);// wait 5 sec so entry-11 goes to the bookies and gets response.
+
+        CountDownLatch sleepLatch1 = new CountDownLatch(1);
+        ArrayList<BookieSocketAddress> ensemble;
+
+        ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
+
+        // Put all 3 bookies to sleep and start 3 new ones
+        sleepBookie(ensemble.get(0), sleepLatch1);
+        sleepBookie(ensemble.get(1), sleepLatch1);
+        sleepBookie(ensemble.get(2), sleepLatch1);
+        startNewBookie();
+        startNewBookie();
+        startNewBookie();
+
+        // Original bookies are in sleep, new bookies added.
+        // Now add entries 5-9 which forces ensemble changes
+        // So at this point entries 0-4, 10 went to first
+        // ensemble, 5-9 will go to new ensemble.
+        for (int i = 5; i < 10; i++) {
+            entry.rewind();
+            entry.putInt(rng.nextInt(maxInt));
+            lh.addEntry(i, entry.array());
+        }
+
+        // Wakeup all 3 bookies that went to sleep
+        sleepLatch1.countDown();
+
+        // Wait for all entries to be acknowledged for the first ledger
+        synchronized (syncObj1) {
+            while (syncObj1.counter < 1) {
+                syncObj1.wait();
+            }
+            assertEquals(BKException.Code.OK, syncObj1.rc);
+        }
+
+        // Close write handle
+        lh.close();
+
+        // Open read handle
+        lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
+
+        // Make sure to read all 10 entries.
+        for (int i = 0; i < 11; i++) {
+            lh.readEntries(i, i);
+        }
+        lh.close();
+        bkc.deleteLedger(ledgerId);
 
 Review comment:
   nit: you don't need this

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services