Search in sources :

Example 36 with LedgerEntry

use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.

the class CompactionTest method verifyLedger.

private void verifyLedger(long lid, long startEntryId, long endEntryId) throws Exception {
    LedgerHandle lh = bkc.openLedger(lid, digestType, "".getBytes());
    Enumeration<LedgerEntry> entries = lh.readEntries(startEntryId, endEntryId);
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        assertEquals(msg, new String(entry.getEntry()));
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry)

Example 37 with LedgerEntry

use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.

the class BookieMultipleJournalsTest method testMultipleWritesAndBookieRestart.

@Test
public void testMultipleWritesAndBookieRestart() throws Exception {
    // Creates few ledgers so that writes are spread across all journals
    final int numLedgers = 16;
    final int numEntriesPerLedger = 30;
    List<LedgerHandle> writeHandles = new ArrayList<>();
    for (int i = 0; i < numLedgers; i++) {
        writeHandles.add(bkc.createLedger(1, 1, DigestType.CRC32, new byte[0]));
    }
    for (int i = 0; i < numEntriesPerLedger; i++) {
        for (int j = 0; j < numLedgers; j++) {
            writeHandles.get(j).addEntry(("entry-" + i).getBytes());
        }
    }
    restartBookies();
    // Write another set of entries
    for (int i = numEntriesPerLedger; i < 2 * numEntriesPerLedger; i++) {
        for (int j = 0; j < numLedgers; j++) {
            writeHandles.get(j).addEntry(("entry-" + i).getBytes());
        }
    }
    restartBookies();
    List<LedgerHandle> readHandles = new ArrayList<>();
    for (int i = 0; i < numLedgers; i++) {
        readHandles.add(bkc.openLedger(writeHandles.get(i).getId(), DigestType.CRC32, new byte[0]));
    }
    for (int i = 0; i < numLedgers; i++) {
        Enumeration<LedgerEntry> entries = readHandles.get(i).readEntries(0, numEntriesPerLedger - 1);
        for (int j = 0; j < numEntriesPerLedger; j++) {
            LedgerEntry entry = entries.nextElement();
            assertEquals("entry-" + j, new String(entry.getEntry()));
        }
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ArrayList(java.util.ArrayList) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Test(org.junit.Test)

Example 38 with LedgerEntry

use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.

the class IndexCorruptionTest method testNoSuchLedger.

@Test
public void testNoSuchLedger() throws Exception {
    LOG.debug("Testing NoSuchLedger");
    SyncThread syncThread = bs.get(0).getBookie().syncThread;
    syncThread.suspendSync();
    // Create a ledger
    LedgerHandle lh = bkc.createLedger(1, 1, digestType, "".getBytes());
    // Close the ledger which cause a readEntry(0) call
    LedgerHandle newLh = bkc.openLedger(lh.getId(), digestType, "".getBytes());
    // Create a new ledger to write entries
    String dummyMsg = "NoSuchLedger";
    int numMsgs = 3;
    LedgerHandle wlh = bkc.createLedger(1, 1, digestType, "".getBytes());
    for (int i = 0; i < numMsgs; i++) {
        wlh.addEntry(dummyMsg.getBytes());
    }
    syncThread.resumeSync();
    // trigger sync
    Thread.sleep(2 * baseConf.getFlushInterval());
    // restart bookies
    restartBookies();
    Enumeration<LedgerEntry> seq = wlh.readEntries(0, numMsgs - 1);
    assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements());
    int entryId = 0;
    while (seq.hasMoreElements()) {
        LedgerEntry e = seq.nextElement();
        assertEquals(entryId, e.getEntryId());
        assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
        ++entryId;
    }
    assertEquals(entryId, numMsgs);
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Test(org.junit.Test)

Example 39 with LedgerEntry

use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.

the class IndexCorruptionTest method testEmptyIndexPage.

@Test
public void testEmptyIndexPage() throws Exception {
    LOG.debug("Testing EmptyIndexPage");
    SyncThread syncThread = bs.get(0).getBookie().syncThread;
    assertNotNull("Not found SyncThread.", syncThread);
    syncThread.suspendSync();
    // Create a ledger
    LedgerHandle lh1 = bkc.createLedger(1, 1, digestType, "".getBytes());
    String dummyMsg = "NoSuchLedger";
    // write two page entries to ledger 2
    int numMsgs = 2 * pageSize / 8;
    LedgerHandle lh2 = bkc.createLedger(1, 1, digestType, "".getBytes());
    for (int i = 0; i < numMsgs; i++) {
        lh2.addEntry(dummyMsg.getBytes());
    }
    syncThread.resumeSync();
    // trigger sync
    Thread.sleep(2 * baseConf.getFlushInterval());
    syncThread.suspendSync();
    // Close ledger 1 which cause a readEntry(0) call
    LedgerHandle newLh1 = bkc.openLedger(lh1.getId(), digestType, "".getBytes());
    // write another 3 entries to ledger 2
    for (int i = 0; i < 3; i++) {
        lh2.addEntry(dummyMsg.getBytes());
    }
    syncThread.resumeSync();
    // wait for sync again
    Thread.sleep(2 * baseConf.getFlushInterval());
    // restart bookies
    restartBookies();
    numMsgs += 3;
    Enumeration<LedgerEntry> seq = lh2.readEntries(0, numMsgs - 1);
    assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements());
    int entryId = 0;
    while (seq.hasMoreElements()) {
        LedgerEntry e = seq.nextElement();
        assertEquals(entryId, e.getEntryId());
        assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
        ++entryId;
    }
    assertEquals(entryId, numMsgs);
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Test(org.junit.Test)

Example 40 with LedgerEntry

use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.

the class GSSAPIBookKeeperTest method entryCount.

/**
 * check if the entry exists. Restart the bookie to allow access
 */
private int entryCount(long ledgerId, ClientConfiguration clientConf) throws Exception {
    LOG.info("Counting entries in {}", ledgerId);
    for (ServerConfiguration conf : bsConfs) {
        conf.setUseHostNameAsBookieID(true);
        conf.setBookieAuthProviderFactoryClass(SASLBookieAuthProviderFactory.class.getName());
    }
    clientConf.setClientAuthProviderFactoryClass(SASLClientProviderFactory.class.getName());
    restartBookies();
    try (BookKeeper bkc = new BookKeeper(clientConf, zkc);
        LedgerHandle lh = bkc.openLedger(ledgerId, DigestType.CRC32, PASSWD)) {
        if (lh.getLastAddConfirmed() < 0) {
            return 0;
        }
        Enumeration<LedgerEntry> e = lh.readEntries(0, lh.getLastAddConfirmed());
        int count = 0;
        while (e.hasMoreElements()) {
            count++;
            assertTrue("Should match what we wrote", Arrays.equals(e.nextElement().getEntry(), ENTRY));
        }
        return count;
    }
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) BookKeeper(org.apache.bookkeeper.client.BookKeeper)

Aggregations

LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)54 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)38 BKException (org.apache.bookkeeper.client.BKException)21 Test (org.junit.Test)20 BookKeeper (org.apache.bookkeeper.client.BookKeeper)10 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)9 IOException (java.io.IOException)8 ByteBuffer (java.nio.ByteBuffer)7 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Bookie (org.apache.bookkeeper.bookie.Bookie)4 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)4 MLDataFormats (org.apache.bookkeeper.mledger.proto.MLDataFormats)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)3 ManagedLedgerImpl.createManagedLedgerException (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.createManagedLedgerException)3 Versioned (org.apache.bookkeeper.versioning.Versioned)3