Package org.apache.bookkeeper.client

Examples of org.apache.bookkeeper.client.LedgerHandle$EnsembleInfo


    @Test(timeout=60000)
    public void testFencingBadPassword() throws Exception {
        /*
         * Create ledger.
         */
        LedgerHandle writelh = null;
        writelh = bkc.createLedger(digestType, "password1".getBytes());

        String tmp = "BookKeeper is cool!";
        for (int i = 0; i < 10; i++) {
            writelh.addEntry(tmp.getBytes());
        }

        /*
         * Try to open ledger.
         */
        try {
            LedgerHandle readlh = bkc.openLedger(writelh.getId(), digestType, "badPassword".getBytes());
            fail("Should not have been able to open with a bad password");
        } catch (BKException.BKUnauthorizedAccessException uue) {
            // correct behaviour
        }
        // should have triggered recovery and fencing
View Full Code Here


        writelh.addEntry(tmp.getBytes());
    }

    @Test
    public void testFencingAndRestartBookies() throws Exception {
        LedgerHandle writelh = null;
        writelh = bkc.createLedger(digestType, "password".getBytes());

        String tmp = "BookKeeper is cool!";
        for (int i = 0; i < 10; i++) {
            writelh.addEntry(tmp.getBytes());
        }

        /*
         * Try to open ledger.
         */
        LedgerHandle readlh = bkc.openLedger(writelh.getId(), digestType,
                                             "password".getBytes());

        restartBookies();

        try {
            writelh.addEntry(tmp.getBytes());
            LOG.error("Should have thrown an exception");
            fail("Should have thrown an exception when trying to write");
        } catch (BKException.BKLedgerFencedException e) {
            // correct behaviour
        }

        readlh.close();
    }
View Full Code Here

            this.barrier = barrier;
        }
       
        @Override
        public void run() {
            LedgerHandle lh = null;
            BookKeeper bk = null;
            try {
                barrier.await();
                while(true) {
                    try {
                        bk = new BookKeeper(new ClientConfiguration(baseClientConf), bkc.getZkHandle());
                       
                        lh = bk.openLedger(ledgerId,
                                           digestType, "".getBytes());
                        lastConfirmedEntry = lh.getLastAddConfirmed();
                        lh.close();
                        break;
                    } catch (BKException.BKMetadataVersionException zke) {
                        LOG.info("Contention with someone else recovering");
                    } catch (BKException.BKLedgerRecoveryException bkre) {
                        LOG.info("Contention with someone else recovering");
                    } finally {
                        if (lh != null) {
                            lh.close();
                        }
                        if (bk != null) {
                            bk.close();
                            bk = null;
                        }
View Full Code Here

        bs.get(0).shutdown();
        bs.get(1).shutdown();
        bs.get(2).shutdown();

        byte[] passwd = "blah".getBytes();
        LedgerHandle lh = bkc.createLedger(1, 1,digestType, passwd);

        int numEntries = 100;
        for (int i=0; i< numEntries; i++) {
            byte[] data = (""+i).getBytes();
            lh.addEntry(data);
        }

        bs.get(3).shutdown();
        BookieServer server = new BookieServer(bsConfs.get(3));
        server.start();
        bs.set(3, server);

        assertEquals(numEntries - 1 , lh.getLastAddConfirmed());
        Enumeration<LedgerEntry> entries = lh.readEntries(0, lh.getLastAddConfirmed());

        int numScanned = 0;
        while (entries.hasMoreElements()) {
            assertEquals((""+numScanned), new String(entries.nextElement().getEntry()));
            numScanned++;
View Full Code Here

    }

    @Test(timeout=60000)
    public void testLedgerNoRecoveryOpenAfterBKCrashed() throws Exception {
        // Create a ledger
        LedgerHandle beforelh = bkc.createLedger(numBookies, numBookies, digestType, "".getBytes());

        int numEntries = 10;
        String tmp = "BookKeeper is cool!";
        for (int i=0; i<numEntries; i++) {
            beforelh.addEntry(tmp.getBytes());
        }

        // shutdown first bookie server
        killBookie(0);

        // try to open ledger no recovery
        LedgerHandle afterlh = bkc.openLedgerNoRecovery(beforelh.getId(), digestType, "".getBytes());

        assertEquals(numEntries - 2, afterlh.getLastAddConfirmed());

        startNewBookie();
        LedgerHandle beforelh2 = bkc.createLedger(numBookies, 1, digestType, "".getBytes());

        for (int i=0; i<numEntries; i++) {
            beforelh2.addEntry(tmp.getBytes());
        }

        // shutdown first bookie server
        killBookie(0);

        // try to open ledger no recovery
        try {
            bkc.openLedgerNoRecovery(beforelh2.getId(), digestType, "".getBytes());
            fail("Should have thrown exception");
        } catch (BKException.BKReadException e) {
            // correct behaviour
        }
    }
View Full Code Here

    }

    @Test(timeout=60000)
    public void testLedgerOpenAfterBKCrashed() throws Exception {
        // Create a ledger
        LedgerHandle beforelh = bkc.createLedger(numBookies, numBookies, digestType, "".getBytes());

        int numEntries = 10;
        String tmp = "BookKeeper is cool!";
        for (int i=0; i<numEntries; i++) {
            beforelh.addEntry(tmp.getBytes());
        }

        // shutdown first bookie server
        killBookie(0);
        startNewBookie();

        // try to open ledger no recovery
        LedgerHandle afterlh = bkc.openLedger(beforelh.getId(), digestType, "".getBytes());

        assertEquals(beforelh.getLastAddPushed(), afterlh.getLastAddConfirmed());

        LedgerHandle beforelh2 = bkc.createLedger(numBookies, 1, digestType, "".getBytes());

        for (int i=0; i<numEntries; i++) {
            beforelh2.addEntry(tmp.getBytes());
        }

        // shutdown first bookie server
        killBookie(0);

        // try to open ledger no recovery
        try {
            bkc.openLedger(beforelh2.getId(), digestType, "".getBytes());
            fail("Should have thrown exception");
        } catch (BKException.BKLedgerRecoveryException e) {
            // correct behaviour
        }
    }
View Full Code Here

    @Test(timeout=60000)
    public void testReadLastConfirmedOp() throws Exception {
        startNewBookie();
        startNewBookie();
        // Create a ledger
        LedgerHandle beforelh = bkc.createLedger(numBookies + 2,
                numBookies + 2, digestType, "".getBytes());

        int numEntries = 10;
        String tmp = "BookKeeper is cool!";
        for (int i = 0; i < numEntries; i++) {
            beforelh.addEntry(tmp.getBytes());
        }

        // shutdown first bookie server
        killBookie(0);
        startNewBookie();

        // create new bookie client, and forcing to establish new
        // PerChannelBookieClient connections for recovery flows.
        BookKeeperTestClient bkc1 = new BookKeeperTestClient(baseClientConf);
        // try to open ledger with recovery
        LedgerHandle afterlh = bkc1.openLedger(beforelh.getId(), digestType, ""
                .getBytes());

        assertEquals("Entries got missed", beforelh.getLastAddPushed(), afterlh
                .getLastAddConfirmed());
        bkc1.close();
    }
View Full Code Here

                                  +"running periodic check", ue);
                        processDone.countDown();
                        return;
                    }

                    LedgerHandle lh = null;
                    try {
                        lh = admin.openLedgerNoRecovery(ledgerId);
                        checker.checkLedger(lh, new ProcessLostFragmentsCb(lh, callback));
                    } catch (BKException.BKNoSuchLedgerExistsException bknsle) {
                        LOG.debug("Ledger was deleted before we could check it", bknsle);
                        callback.processResult(BKException.Code.OK,
                                               null, null);
                        return;
                    } catch (BKException bke) {
                        LOG.error("Couldn't open ledger " + ledgerId, bke);
                        callback.processResult(BKException.Code.BookieHandleNotAvailableException,
                                         null, null);
                        return;
                    } catch (InterruptedException ie) {
                        LOG.error("Interrupted opening ledger", ie);
                        Thread.currentThread().interrupt();
                        callback.processResult(BKException.Code.InterruptedException, null, null);
                        return;
                    } finally {
                        if (lh != null) {
                            try {
                                lh.close();
                            } catch (BKException bke) {
                                LOG.warn("Couldn't close ledger " + ledgerId, bke);
                            } catch (InterruptedException ie) {
                                LOG.warn("Interrupted closing ledger " + ledgerId, ie);
                                Thread.currentThread().interrupt();
View Full Code Here

     * Tests that replication worker should replicate the failed bookie
     * fragments to target bookie given to the worker.
     */
    @Test(timeout = 30000)
    public void testRWShouldReplicateFragmentsToTargetBookie() throws Exception {
        LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32,
                TESTPASSWD);

        for (int i = 0; i < 10; i++) {
            lh.addEntry(data);
        }
        InetSocketAddress replicaToKill = LedgerHandleAdapter
                .getLedgerMetadata(lh).getEnsembles().get(0L).get(0);

        LOG.info("Killing Bookie", replicaToKill);
        killBookie(replicaToKill);

        int startNewBookie = startNewBookie();
        for (int i = 0; i < 10; i++) {
            lh.addEntry(data);
        }

        InetSocketAddress newBkAddr = new InetSocketAddress(InetAddress
                .getLocalHost().getHostAddress(), startNewBookie);
        LOG.info("New Bookie addr :" + newBkAddr);

        ReplicationWorker rw = new ReplicationWorker(zkc, baseConf, newBkAddr);

        rw.start();
        try {

            underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                    replicaToKill.toString());

            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
                    .getId(), basePath)) {
                Thread.sleep(100);
            }

            killAllBookies(lh, newBkAddr);
View Full Code Here

     * bookies available for replication
     */
    @Test(timeout = 60000)
    public void testRWShouldRetryUntilThereAreEnoughBksAvailableForReplication()
            throws Exception {
        LedgerHandle lh = bkc.createLedger(1, 1, BookKeeper.DigestType.CRC32,
                TESTPASSWD);

        for (int i = 0; i < 10; i++) {
            lh.addEntry(data);
        }
        lh.close();
        InetSocketAddress replicaToKill = LedgerHandleAdapter
                .getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
        LOG.info("Killing Bookie", replicaToKill);
        ServerConfiguration killedBookieConfig = killBookie(replicaToKill);

        int startNewBookie = startNewBookie();
        InetSocketAddress newBkAddr = new InetSocketAddress(InetAddress
                .getLocalHost().getHostAddress(), startNewBookie);
        LOG.info("New Bookie addr :" + newBkAddr);

        killAllBookies(lh, newBkAddr);
        ReplicationWorker rw = new ReplicationWorker(zkc, baseConf, newBkAddr);

        rw.start();
        try {
            underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                    replicaToKill.toString());
            int counter = 100;
            while (counter-- > 0) {
                assertTrue("Expecting that replication should not complete",
                        ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
                                .getId(), basePath));
                Thread.sleep(100);
            }
            // restart killed bookie
            bs.add(startBookie(killedBookieConfig));
            bsConfs.add(killedBookieConfig);
            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
                    .getId(), basePath)) {
                Thread.sleep(100);
            }
            // Should be able to read the entries from 0-9
            verifyRecoveredLedgers(lh, 0, 9);
View Full Code Here

TOP

Related Classes of org.apache.bookkeeper.client.LedgerHandle$EnsembleInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.