Search in sources :

Example 41 with BookieSocketAddress

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

the class BookieWriteLedgerTest method testWithMultipleBookieFailuresInLastEnsemble.

/**
 * Verify write when few bookie failures in last ensemble and forcing
 * ensemble reformation.
 */
@Test
public void testWithMultipleBookieFailuresInLastEnsemble() throws Exception {
    // Create a ledger
    lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
    LOG.info("Ledger ID: " + lh.getId());
    for (int i = 0; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        entries1.add(entry.array());
        lh.addEntry(entry.array());
    }
    // Start three more bookies
    startNewBookie();
    startNewBookie();
    startNewBookie();
    // Shutdown three bookies in the last ensemble and continue writing
    ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
    killBookie(ensemble.get(0));
    killBookie(ensemble.get(1));
    killBookie(ensemble.get(2));
    int i = numEntriesToWrite;
    numEntriesToWrite = numEntriesToWrite + 50;
    for (; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        entries1.add(entry.array());
        lh.addEntry(entry.array());
    }
    readEntries(lh, entries1);
    lh.close();
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 42 with BookieSocketAddress

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

the class BookieWriteLedgerTest method testAsyncWritesWithMultipleFailuresInLastEnsemble.

/**
 * Verify asynchronous writing when few bookie failures in last ensemble.
 */
@Test
public void testAsyncWritesWithMultipleFailuresInLastEnsemble() throws Exception {
    // Create ledgers
    lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
    lh2 = bkc.createLedger(5, 4, digestType, ledgerPassword);
    LOG.info("Ledger ID-1: " + lh.getId());
    LOG.info("Ledger ID-2: " + lh2.getId());
    for (int i = 0; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        entries1.add(entry.array());
        entries2.add(entry.array());
        lh.addEntry(entry.array());
        lh2.addEntry(entry.array());
    }
    // Start three more bookies
    startNewBookie();
    startNewBookie();
    startNewBookie();
    // Shutdown three bookies in the last ensemble and continue writing
    ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
    killBookie(ensemble.get(0));
    killBookie(ensemble.get(1));
    killBookie(ensemble.get(2));
    // adding one more entry to both the ledgers async after multiple bookie
    // failures. This will do asynchronously modifying the ledger metadata
    // simultaneously.
    numEntriesToWrite++;
    ByteBuffer entry = ByteBuffer.allocate(4);
    entry.putInt(rng.nextInt(maxInt));
    entry.position(0);
    entries1.add(entry.array());
    entries2.add(entry.array());
    SyncObj syncObj1 = new SyncObj();
    SyncObj syncObj2 = new SyncObj();
    lh.asyncAddEntry(entry.array(), this, syncObj1);
    lh2.asyncAddEntry(entry.array(), this, syncObj2);
    // wait for all entries to be acknowledged for the first ledger
    synchronized (syncObj1) {
        while (syncObj1.counter < 1) {
            LOG.debug("Entries counter = " + syncObj1.counter);
            syncObj1.wait();
        }
        assertEquals(BKException.Code.OK, syncObj1.rc);
    }
    // wait for all entries to be acknowledged for the second ledger
    synchronized (syncObj2) {
        while (syncObj2.counter < 1) {
            LOG.debug("Entries counter = " + syncObj2.counter);
            syncObj2.wait();
        }
        assertEquals(BKException.Code.OK, syncObj2.rc);
    }
    // reading ledger till the last entry
    readEntries(lh, entries1);
    readEntries(lh2, entries2);
    lh.close();
    lh2.close();
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 43 with BookieSocketAddress

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

the class BookieWriteLedgerTest method testLedgerCreateAdvWithLedgerId.

/**
 * Verify the functionality of Advanced Ledger which accepts ledgerId as input and returns
 * LedgerHandleAdv. LedgerHandleAdv takes entryId for addEntry, and let
 * user manage entryId allocation.
 *
 * @throws Exception
 */
@Test
public void testLedgerCreateAdvWithLedgerId() throws Exception {
    // Create a ledger
    long ledgerId = 0xABCDEF;
    lh = bkc.createLedgerAdv(ledgerId, 5, 3, 2, digestType, ledgerPassword, null);
    for (int i = 0; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        entries1.add(entry.array());
        lh.addEntry(i, entry.array());
    }
    // Start one more bookies
    startNewBookie();
    // Shutdown one bookie in the last ensemble and continue writing
    ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
    killBookie(ensemble.get(0));
    int i = numEntriesToWrite;
    numEntriesToWrite = numEntriesToWrite + 50;
    for (; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        entries1.add(entry.array());
        lh.addEntry(i, entry.array());
    }
    readEntries(lh, entries1);
    lh.close();
    bkc.deleteLedger(ledgerId);
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 44 with BookieSocketAddress

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

the class BookieWriteLedgerTest method testLedgerCreateAdvWithRandomAsyncWritesWithBookieFailures.

/**
 * Verify Advanced asynchronous writing with entryIds in pseudo random order.
 */
@Test
public void testLedgerCreateAdvWithRandomAsyncWritesWithBookieFailures() throws Exception {
    // Create ledgers
    lh = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
    lh2 = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
    LOG.info("Ledger ID-1: " + lh.getId());
    LOG.info("Ledger ID-2: " + lh2.getId());
    SyncObj syncObj1 = new SyncObj();
    SyncObj syncObj2 = new SyncObj();
    int batchSize = 5;
    int i, j;
    // Fill the result buffers first
    for (i = 0; i < numEntriesToWrite; i++) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        try {
            entries1.add(0, entry.array());
            entries2.add(0, entry.array());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (i = 0; i < batchSize; i++) {
        for (j = i; j < numEntriesToWrite; j = j + batchSize) {
            byte[] entry1 = entries1.get(j);
            byte[] entry2 = entries2.get(j);
            lh.asyncAddEntry(j, entry1, 0, entry1.length, this, syncObj1);
            lh2.asyncAddEntry(j, entry2, 0, entry2.length, this, syncObj2);
        }
    }
    // Start One more bookie and shutdown one from last ensemble before reading
    startNewBookie();
    ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
    killBookie(ensemble.get(0));
    // Wait for all entries to be acknowledged for the first ledger
    synchronized (syncObj1) {
        while (syncObj1.counter < numEntriesToWrite) {
            syncObj1.wait();
        }
        assertEquals(BKException.Code.OK, syncObj1.rc);
    }
    // Wait for all entries to be acknowledged for the second ledger
    synchronized (syncObj2) {
        while (syncObj2.counter < numEntriesToWrite) {
            syncObj2.wait();
        }
        assertEquals(BKException.Code.OK, syncObj2.rc);
    }
    // Reading ledger till the last entry
    readEntries(lh, entries1);
    readEntries(lh2, entries2);
    lh.close();
    lh2.close();
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ByteBuffer(java.nio.ByteBuffer) BKLedgerClosedException(org.apache.bookkeeper.client.BKException.BKLedgerClosedException) BookieException(org.apache.bookkeeper.bookie.BookieException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 45 with BookieSocketAddress

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

the class BookieWriteLedgerTest method testLedgerCreateAdvWithAsyncWritesWithBookieFailures.

/**
 * Verify Advanced asynchronous writing with entryIds in reverse order.
 */
@Test
public void testLedgerCreateAdvWithAsyncWritesWithBookieFailures() throws Exception {
    // Create ledgers
    lh = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
    lh2 = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
    LOG.info("Ledger ID-1: " + lh.getId());
    LOG.info("Ledger ID-2: " + lh2.getId());
    SyncObj syncObj1 = new SyncObj();
    SyncObj syncObj2 = new SyncObj();
    for (int i = numEntriesToWrite - 1; i >= 0; i--) {
        ByteBuffer entry = ByteBuffer.allocate(4);
        entry.putInt(rng.nextInt(maxInt));
        entry.position(0);
        try {
            entries1.add(0, entry.array());
            entries2.add(0, entry.array());
        } catch (Exception e) {
            e.printStackTrace();
        }
        lh.asyncAddEntry(i, entry.array(), 0, entry.capacity(), this, syncObj1);
        lh2.asyncAddEntry(i, entry.array(), 0, entry.capacity(), this, syncObj2);
    }
    // Start One more bookie and shutdown one from last ensemble before reading
    startNewBookie();
    ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
    killBookie(ensemble.get(0));
    // Wait for all entries to be acknowledged for the first ledger
    synchronized (syncObj1) {
        while (syncObj1.counter < numEntriesToWrite) {
            syncObj1.wait();
        }
        assertEquals(BKException.Code.OK, syncObj1.rc);
    }
    // Wait for all entries to be acknowledged for the second ledger
    synchronized (syncObj2) {
        while (syncObj2.counter < numEntriesToWrite) {
            syncObj2.wait();
        }
        assertEquals(BKException.Code.OK, syncObj2.rc);
    }
    // Reading ledger till the last entry
    readEntries(lh, entries1);
    readEntries(lh2, entries2);
    lh.close();
    lh2.close();
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ByteBuffer(java.nio.ByteBuffer) BKLedgerClosedException(org.apache.bookkeeper.client.BKException.BKLedgerClosedException) BookieException(org.apache.bookkeeper.bookie.BookieException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) 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