Search in sources :

Example 1 with ZkLedgerUnderreplicationManager

use of org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager in project bookkeeper by apache.

the class BookieDecommissionTest method testDecommissionForLedgersWithMultipleSegmentsAndNotWriteClosed.

@Test
public void testDecommissionForLedgersWithMultipleSegmentsAndNotWriteClosed() throws Exception {
    ZkLedgerUnderreplicationManager urLedgerMgr = new ZkLedgerUnderreplicationManager(baseClientConf, zkc);
    BookKeeperAdmin bkAdmin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
    int numOfEntries = 2 * NUM_OF_BOOKIES;
    LedgerHandle lh1 = bkc.createLedgerAdv(1L, numBookies, 3, 3, digestType, PASSWORD.getBytes(), null);
    LedgerHandle lh2 = bkc.createLedgerAdv(2L, numBookies, 3, 3, digestType, PASSWORD.getBytes(), null);
    LedgerHandle lh3 = bkc.createLedgerAdv(3L, numBookies, 3, 3, digestType, PASSWORD.getBytes(), null);
    LedgerHandle lh4 = bkc.createLedgerAdv(4L, numBookies, 3, 3, digestType, PASSWORD.getBytes(), null);
    for (int j = 0; j < numOfEntries; j++) {
        lh1.addEntry(j, "data".getBytes());
        lh2.addEntry(j, "data".getBytes());
        lh3.addEntry(j, "data".getBytes());
        lh4.addEntry(j, "data".getBytes());
    }
    startNewBookie();
    assertEquals("Number of Available Bookies", NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size());
    ServerConfiguration killedBookieConf = killBookie(0);
    /*
         * since one of the bookie is killed, ensemble change happens when next
         * write is made.So new fragment will be created for those 2 ledgers.
         */
    for (int j = numOfEntries; j < 2 * numOfEntries; j++) {
        lh1.addEntry(j, "data".getBytes());
        lh2.addEntry(j, "data".getBytes());
    }
    /*
         * Here lh1 and lh2 have multiple fragments and are writeclosed. But lh3 and lh4 are
         * not writeclosed and contains only one fragment.
         */
    lh1.close();
    lh2.close();
    /*
         * If the last fragment of the ledger is underreplicated and if the
         * ledger is not closed then it will remain underreplicated for
         * openLedgerRereplicationGracePeriod (by default 30 secs). For more
         * info. Check BOOKKEEPER-237 and BOOKKEEPER-325. But later
         * ReplicationWorker will fence the ledger.
         */
    bkAdmin.decommissionBookie(Bookie.getBookieAddress(killedBookieConf));
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    Iterator<Long> ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    if (ledgersToRereplicate.hasNext()) {
        while (ledgersToRereplicate.hasNext()) {
            Long ledgerId = ledgersToRereplicate.next();
            log.error("Ledger: {} is underreplicated which is not expected", ledgerId);
        }
        fail("There are not supposed to be any underreplicatedledgers");
    }
    bkAdmin.close();
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) Test(org.junit.Test) FlakyTest(org.apache.bookkeeper.test.annotations.FlakyTest)

Example 2 with ZkLedgerUnderreplicationManager

use of org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager in project bookkeeper by apache.

the class BookKeeperAdminTest method testTriggerAudit.

@Test
public void testTriggerAudit() throws Exception {
    ZkLedgerUnderreplicationManager urLedgerMgr = new ZkLedgerUnderreplicationManager(baseClientConf, zkc);
    BookKeeperAdmin bkAdmin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
    int lostBookieRecoveryDelayValue = bkAdmin.getLostBookieRecoveryDelay();
    urLedgerMgr.disableLedgerReplication();
    try {
        bkAdmin.triggerAudit();
        fail("Trigger Audit should have failed because LedgerReplication is disabled");
    } catch (UnavailableException une) {
    // expected
    }
    assertEquals("LostBookieRecoveryDelay", lostBookieRecoveryDelayValue, bkAdmin.getLostBookieRecoveryDelay());
    urLedgerMgr.enableLedgerReplication();
    bkAdmin.triggerAudit();
    assertEquals("LostBookieRecoveryDelay", lostBookieRecoveryDelayValue, bkAdmin.getLostBookieRecoveryDelay());
    long ledgerId = 1L;
    LedgerHandle ledgerHandle = bkc.createLedgerAdv(ledgerId, numBookies, numBookies, numBookies, digestType, PASSWORD.getBytes(), null);
    ledgerHandle.addEntry(0, "data".getBytes());
    ledgerHandle.close();
    killBookie(1);
    /*
         * since lostBookieRecoveryDelay is set, when a bookie is died, it will
         * not start Audit process immediately. But when triggerAudit is called
         * it will force audit process.
         */
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    Iterator<Long> ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    assertTrue("There are supposed to be underreplicatedledgers", ledgersToRereplicate.hasNext());
    assertEquals("Underreplicated ledgerId", ledgerId, ledgersToRereplicate.next().longValue());
    bkAdmin.close();
}
Also used : UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) Test(org.junit.Test)

Example 3 with ZkLedgerUnderreplicationManager

use of org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager in project bookkeeper by apache.

the class BookieDecommissionTest method testDecommissionBookie.

@FlakyTest("https://github.com/apache/bookkeeper/issues/502")
public void testDecommissionBookie() throws Exception {
    ZkLedgerUnderreplicationManager urLedgerMgr = new ZkLedgerUnderreplicationManager(baseClientConf, zkc);
    BookKeeperAdmin bkAdmin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
    int numOfLedgers = 2 * NUM_OF_BOOKIES;
    int numOfEntries = 2 * NUM_OF_BOOKIES;
    for (int i = 0; i < numOfLedgers; i++) {
        LedgerHandle lh = bkc.createLedger(3, 2, digestType, PASSWORD.getBytes());
        for (int j = 0; j < numOfEntries; j++) {
            lh.addEntry("entry".getBytes());
        }
        lh.close();
    }
    /*
         * create ledgers having empty segments (segment with no entries)
         */
    for (int i = 0; i < numOfLedgers; i++) {
        LedgerHandle emptylh = bkc.createLedger(3, 2, digestType, PASSWORD.getBytes());
        emptylh.close();
    }
    try {
        /*
             * if we try to call decommissionBookie for a bookie which is not
             * shutdown, then it should throw BKIllegalOpException
             */
        bkAdmin.decommissionBookie(bs.get(0).getLocalAddress());
        fail("Expected BKIllegalOpException because that bookie is not shutdown yet");
    } catch (BKIllegalOpException bkioexc) {
    // expected IllegalException
    }
    ServerConfiguration killedBookieConf = killBookie(1);
    /*
         * this decommisionBookie should make sure that there are no
         * underreplicated ledgers because of this bookie
         */
    bkAdmin.decommissionBookie(Bookie.getBookieAddress(killedBookieConf));
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    Iterator<Long> ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    if (ledgersToRereplicate.hasNext()) {
        while (ledgersToRereplicate.hasNext()) {
            Long ledgerId = ledgersToRereplicate.next();
            log.error("Ledger: {} is underreplicated which is not expected", ledgerId);
        }
        fail("There are not supposed to be any underreplicatedledgers");
    }
    killedBookieConf = killBookie(0);
    bkAdmin.decommissionBookie(Bookie.getBookieAddress(killedBookieConf));
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    if (ledgersToRereplicate.hasNext()) {
        while (ledgersToRereplicate.hasNext()) {
            Long ledgerId = ledgersToRereplicate.next();
            log.error("Ledger: {} is underreplicated which is not expected", ledgerId);
        }
        fail("There are not supposed to be any underreplicatedledgers");
    }
    bkAdmin.close();
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BKIllegalOpException(org.apache.bookkeeper.client.BKException.BKIllegalOpException) ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) FlakyTest(org.apache.bookkeeper.test.annotations.FlakyTest)

Example 4 with ZkLedgerUnderreplicationManager

use of org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager in project bookkeeper by apache.

the class AuditorLedgerCheckerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    urLedgerMgr = new ZkLedgerUnderreplicationManager(baseClientConf, zkc);
    startAuditorElectors();
    // Initialize the Random
    rng = new Random(System.currentTimeMillis());
    urLedgerList = new HashSet<Long>();
    ledgerList = new ArrayList<Long>(2);
    baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
}
Also used : Random(java.util.Random) ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) Before(org.junit.Before)

Aggregations

ZkLedgerUnderreplicationManager (org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 FlakyTest (org.apache.bookkeeper.test.annotations.FlakyTest)2 Test (org.junit.Test)2 Random (java.util.Random)1 BKIllegalOpException (org.apache.bookkeeper.client.BKException.BKIllegalOpException)1 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)1 Before (org.junit.Before)1