use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method testBookieFailure.
@Test
public void testBookieFailure() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedger ledger = factory.open("my-ledger", config);
ManagedCursor cursor = ledger.openCursor("my-cursor");
ledger.addEntry("entry-0".getBytes());
killBookie(1);
// Now we want to simulate that:
// 1. The write operation fails because we only have 1 bookie available
// 2. The bk client cannot properly close the ledger (finalizing the number of entries) because ZK is also
// not available
// 3. When we re-establish the service one, the ledger recovery will be triggered and the half-committed entry
// is restored
// Force to close the ZK client object so that BK will fail to close the ledger
bkc.getZkHandle().close();
try {
ledger.addEntry("entry-1".getBytes());
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
bkc = new BookKeeperTestClient(baseClientConf);
startNewBookie();
// Reconnect a new bk client
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ledger = factory.open("my-ledger", config);
cursor = ledger.openCursor("my-cursor");
// Next add should succeed
ledger.addEntry("entry-2".getBytes());
assertEquals(3, cursor.getNumberOfEntriesInBacklog());
List<Entry> entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-0", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
// entry-1 which was half-committed will get fully committed during the recovery phase
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-1", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-2", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method testResetCursorAfterRecovery.
@Test(timeOut = 20000)
void testResetCursorAfterRecovery() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig conf = new ManagedLedgerConfig().setMaxEntriesPerLedger(10).setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataWriteQuorumSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("my_test_move_cursor_ledger", conf);
ManagedCursor cursor = ledger.openCursor("trc1");
Position p1 = ledger.addEntry("dummy-entry-1".getBytes());
Position p2 = ledger.addEntry("dummy-entry-2".getBytes());
Position p3 = ledger.addEntry("dummy-entry-3".getBytes());
Position p4 = ledger.addEntry("dummy-entry-4".getBytes());
cursor.markDelete(p3);
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, zkc);
ledger = factory2.open("my_test_move_cursor_ledger", conf);
cursor = ledger.openCursor("trc1");
assertEquals(cursor.getMarkDeletedPosition(), p3);
assertEquals(cursor.getReadPosition(), p4);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
cursor.resetCursor(p2);
assertEquals(cursor.getMarkDeletedPosition(), p1);
assertEquals(cursor.getReadPosition(), p2);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 3);
factory2.shutdown();
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method testSimple.
@Test
public void testSimple() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig mlConfig = new ManagedLedgerConfig();
mlConfig.setEnsembleSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1);
// set the data ledger size
mlConfig.setMaxEntriesPerLedger(100);
// set the metadata ledger size to 1 to kick off many ledger switching cases
mlConfig.setMetadataMaxEntriesPerLedger(2);
ManagedLedger ledger = factory.open("ml-simple-ledger", mlConfig);
ledger.addEntry("test".getBytes());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method closingManagedLedger.
@Test
public void closingManagedLedger() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("c1");
ledger.addEntry("entry".getBytes());
bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
try {
ledger.close();
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
// ML should be closed even if it failed before
try {
ledger.addEntry("entry".getBytes());
fail("managed ledger was closed");
} catch (ManagedLedgerException e) {
// ok
}
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method errorInRecovering6.
@Test
public void errorInRecovering6() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("c1");
ledger.addEntry("entry".getBytes());
ledger.close();
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
zkc.failAfter(3, Code.CONNECTIONLOSS);
try {
ledger = factory.open("my_test_ledger");
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
// It should be fine now
ledger = factory.open("my_test_ledger");
}
Aggregations