Search in sources :

Example 16 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestAutoRecoveryAlongWithBookieServers method testAutoRecoveryAlongWithBookieServers.

/**
 * Tests that the auto recovery service along with Bookie servers itself.
 */
@Test
public void testAutoRecoveryAlongWithBookieServers() throws Exception {
    LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "testpasswd".getBytes());
    byte[] testData = "testBuiltAutoRecovery".getBytes();
    for (int i = 0; i < 10; i++) {
        lh.addEntry(testData);
    }
    lh.close();
    BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
    killBookie(replicaToKill);
    BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
    while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath)) {
        Thread.sleep(100);
    }
    // Killing all bookies except newly replicated bookie
    Set<Entry<Long, ArrayList<BookieSocketAddress>>> entrySet = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().entrySet();
    for (Entry<Long, ArrayList<BookieSocketAddress>> entry : entrySet) {
        ArrayList<BookieSocketAddress> bookies = entry.getValue();
        for (BookieSocketAddress bookie : bookies) {
            if (bookie.equals(newBkAddr)) {
                continue;
            }
            killBookie(bookie);
        }
    }
    // Should be able to read the entries from 0-9
    LedgerHandle lhs = bkc.openLedgerNoRecovery(lh.getId(), BookKeeper.DigestType.CRC32, "testpasswd".getBytes());
    Enumeration<LedgerEntry> entries = lhs.readEntries(0, 9);
    assertTrue("Should have the elements", entries.hasMoreElements());
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        assertEquals("testBuiltAutoRecovery", new String(entry.getEntry()));
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ArrayList(java.util.ArrayList) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Entry(java.util.Map.Entry) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Test(org.junit.Test)

Example 17 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestReplicationWorker method test2RWsShouldCompeteForReplicationOf2FragmentsAndCompleteReplication.

/**
 * Tests that replication worker1 should take one fragment replication and
 * other replication worker also should compete for the replication.
 */
@Test
public void test2RWsShouldCompeteForReplicationOf2FragmentsAndCompleteReplication() throws Exception {
    LedgerHandle lh = bkc.createLedger(2, 2, BookKeeper.DigestType.CRC32, TESTPASSWD);
    for (int i = 0; i < 10; i++) {
        lh.addEntry(data);
    }
    lh.close();
    BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
    LOG.info("Killing Bookie", replicaToKill);
    ServerConfiguration killedBookieConfig = killBookie(replicaToKill);
    killAllBookies(lh, null);
    // Starte RW1
    BookieSocketAddress newBkAddr1 = startNewBookieAndReturnAddress();
    LOG.info("New Bookie addr : {}", newBkAddr1);
    ReplicationWorker rw1 = new ReplicationWorker(zkc, baseConf);
    // Starte RW2
    BookieSocketAddress newBkAddr2 = startNewBookieAndReturnAddress();
    LOG.info("New Bookie addr : {}", newBkAddr2);
    ZooKeeper zkc1 = ZooKeeperClient.newBuilder().connectString(zkUtil.getZooKeeperConnectString()).sessionTimeoutMs(10000).build();
    ReplicationWorker rw2 = new ReplicationWorker(zkc1, baseConf);
    rw1.start();
    rw2.start();
    try {
        underReplicationManager.markLedgerUnderreplicated(lh.getId(), replicaToKill.toString());
        int counter = 10;
        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);
    } finally {
        rw1.shutdown();
        rw2.shutdown();
        zkc1.close();
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) Test(org.junit.Test)

Example 18 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestReplicationWorker method testRWShouldCleanTheLedgerFromUnderReplicationIfLedgerAlreadyDeleted.

/**
 * Tests that Replication worker should clean the leadger under replication
 * node of the ledger already deleted.
 */
@Test
public void testRWShouldCleanTheLedgerFromUnderReplicationIfLedgerAlreadyDeleted() throws Exception {
    LedgerHandle lh = bkc.createLedger(2, 2, BookKeeper.DigestType.CRC32, TESTPASSWD);
    for (int i = 0; i < 10; i++) {
        lh.addEntry(data);
    }
    lh.close();
    BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
    LOG.info("Killing Bookie", replicaToKill);
    killBookie(replicaToKill);
    BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
    LOG.info("New Bookie addr : {}", newBkAddr);
    ReplicationWorker rw = new ReplicationWorker(zkc, baseConf);
    rw.start();
    try {
        // Deleting the ledger
        bkc.deleteLedger(lh.getId());
        // Also mark ledger as in UnderReplication
        underReplicationManager.markLedgerUnderreplicated(lh.getId(), replicaToKill.toString());
        while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath)) {
            Thread.sleep(100);
        }
    } finally {
        rw.shutdown();
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Example 19 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestReplicationWorker method testRWShouldReplicateFragmentsToTargetBookie.

/**
 * Tests that replication worker should replicate the failed bookie
 * fragments to target bookie given to the worker.
 */
@Test
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);
    }
    BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
    LOG.info("Killing Bookie", replicaToKill);
    killBookie(replicaToKill);
    BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
    LOG.info("New Bookie addr : {}", newBkAddr);
    for (int i = 0; i < 10; i++) {
        lh.addEntry(data);
    }
    ReplicationWorker rw = new ReplicationWorker(zkc, baseConf);
    rw.start();
    try {
        underReplicationManager.markLedgerUnderreplicated(lh.getId(), replicaToKill.toString());
        while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath)) {
            Thread.sleep(100);
        }
        killAllBookies(lh, newBkAddr);
        // Should be able to read the entries from 0-9
        verifyRecoveredLedgers(lh, 0, 9);
    } finally {
        rw.shutdown();
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Example 20 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class BookieClientTest method testWriteGaps.

@Test
public void testWriteGaps() throws Exception {
    final Object notifyObject = new Object();
    byte[] passwd = new byte[20];
    Arrays.fill(passwd, (byte) 'a');
    BookieSocketAddress addr = bs.getLocalAddress();
    ResultStruct arc = new ResultStruct();
    BookieClient bc = new BookieClient(new ClientConfiguration(), eventLoopGroup, executor, scheduler, NullStatsLogger.INSTANCE);
    ByteBufList bb = createByteBuffer(1, 1, 1);
    bc.addEntry(addr, 1, passwd, 1, bb, wrcb, arc, BookieProtocol.FLAG_NONE);
    synchronized (arc) {
        arc.wait(1000);
        assertEquals(0, arc.rc);
        bc.readEntry(addr, 1, 1, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(1, arc.entry.getInt());
    }
    bb = createByteBuffer(2, 1, 2);
    bc.addEntry(addr, 1, passwd, 2, bb, wrcb, null, BookieProtocol.FLAG_NONE);
    bb = createByteBuffer(3, 1, 3);
    bc.addEntry(addr, 1, passwd, 3, bb, wrcb, null, BookieProtocol.FLAG_NONE);
    bb = createByteBuffer(5, 1, 5);
    bc.addEntry(addr, 1, passwd, 5, bb, wrcb, null, BookieProtocol.FLAG_NONE);
    bb = createByteBuffer(7, 1, 7);
    bc.addEntry(addr, 1, passwd, 7, bb, wrcb, null, BookieProtocol.FLAG_NONE);
    synchronized (notifyObject) {
        bb = createByteBuffer(11, 1, 11);
        bc.addEntry(addr, 1, passwd, 11, bb, wrcb, notifyObject, BookieProtocol.FLAG_NONE);
        notifyObject.wait();
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 6, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(BKException.Code.NoSuchEntryException, arc.rc);
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 7, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(7, arc.entry.getInt(), BookieProtocol.FLAG_NONE);
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 1, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(1, arc.entry.getInt());
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 2, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(2, arc.entry.getInt());
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 3, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(3, arc.entry.getInt());
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 4, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(BKException.Code.NoSuchEntryException, arc.rc);
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 11, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(11, arc.entry.getInt());
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 5, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(0, arc.rc);
        assertEquals(5, arc.entry.getInt());
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 10, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(BKException.Code.NoSuchEntryException, arc.rc);
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 12, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(BKException.Code.NoSuchEntryException, arc.rc);
    }
    synchronized (arc) {
        bc.readEntry(addr, 1, 13, recb, arc, BookieProtocol.FLAG_NONE);
        arc.wait(1000);
        assertEquals(BKException.Code.NoSuchEntryException, arc.rc);
    }
}
Also used : ByteBufList(org.apache.bookkeeper.util.ByteBufList) BookieClient(org.apache.bookkeeper.proto.BookieClient) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Aggregations

BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)254 Test (org.junit.Test)140 HashSet (java.util.HashSet)67 CountDownLatch (java.util.concurrent.CountDownLatch)42 ArrayList (java.util.ArrayList)40 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)38 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)37 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)29 HashMap (java.util.HashMap)28 Map (java.util.Map)24 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)23 IOException (java.io.IOException)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 BookieServer (org.apache.bookkeeper.proto.BookieServer)14 WriteCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback)13 Set (java.util.Set)11 ByteBuf (io.netty.buffer.ByteBuf)10 ByteBuffer (java.nio.ByteBuffer)10 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10