use of org.apache.bookkeeper.mledger.Position 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.Position in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method errorInUpdatingLedgersList.
@Test(timeOut = 20000, invocationCount = 1, skipFailedInvocations = true, enabled = false)
public void errorInUpdatingLedgersList() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
final CountDownLatch latch = new CountDownLatch(1);
zkc.failAfter(0, Code.CONNECTIONLOSS);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
// not-ok
}
public void addComplete(Position position, Object ctx) {
// ok
}
}, null);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void addComplete(Position position, Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method recoverLongTimeAfterMultipleWriteErrors.
@Test
public void recoverLongTimeAfterMultipleWriteErrors() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("recoverLongTimeAfterMultipleWriteErrors");
ManagedCursor cursor = ledger.openCursor("c1");
bkc.failNow(BKException.Code.BookieHandleNotAvailableException, BKException.Code.BookieHandleNotAvailableException);
CountDownLatch counter = new CountDownLatch(2);
AtomicReference<ManagedLedgerException> ex = new AtomicReference<>();
// Write 2 entries, both should fail the first time and get re-tried internally in a new ledger
AddEntryCallback cb = new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
counter.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
log.warn("Error in write", exception);
ex.set(exception);
counter.countDown();
}
};
ledger.asyncAddEntry("entry-1".getBytes(), cb, null);
ledger.asyncAddEntry("entry-2".getBytes(), cb, null);
counter.await();
assertNull(ex.get());
assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
// Ensure that we are only creating one new ledger
// even when there are multiple (here, 2) add entry failed ops
assertEquals(ledger.getLedgersInfoAsList().size(), 1);
ledger.addEntry("entry-3".getBytes());
List<Entry> entries = cursor.readEntries(10);
assertEquals(entries.size(), 3);
assertEquals(new String(entries.get(0).getData()), "entry-1");
assertEquals(new String(entries.get(1).getData()), "entry-2");
assertEquals(new String(entries.get(2).getData()), "entry-3");
entries.forEach(e -> e.release());
}
use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method handleCursorRecoveryFailure.
@Test
public void handleCursorRecoveryFailure() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("my-cursor");
Position p0 = cursor.getMarkDeletedPosition();
Position p1 = ledger.addEntry("entry-1".getBytes());
cursor.markDelete(p1);
// Re-open from a different factory
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, zkc);
bkc.failAfter(3, BKException.Code.LedgerRecoveryException);
ledger = factory2.open("my_test_ledger");
cursor = ledger.openCursor("my-cursor");
// Since the cursor was rewind, it will be back to p0
assertEquals(cursor.getMarkDeletedPosition(), p0);
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
the class ManagedLedgerMBeanTest method simple.
@Test
public void simple() throws Exception {
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
config.setMaxCacheSize(0);
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(bkc, zkc, config);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("c1");
ManagedLedgerMBeanImpl mbean = ledger.mbean;
assertEquals(mbean.getName(), "my_test_ledger");
assertEquals(mbean.getStoredMessagesSize(), 0);
assertEquals(mbean.getNumberOfMessagesInBacklog(), 0);
waitForRefresh(mbean);
mbean.addAddEntryLatencySample(1, TimeUnit.MILLISECONDS);
mbean.addAddEntryLatencySample(10, TimeUnit.MILLISECONDS);
mbean.addAddEntryLatencySample(1, TimeUnit.SECONDS);
mbean.addLedgerSwitchLatencySample(1, TimeUnit.MILLISECONDS);
mbean.addLedgerSwitchLatencySample(10, TimeUnit.MILLISECONDS);
mbean.addLedgerSwitchLatencySample(1, TimeUnit.SECONDS);
// Simulate stats getting update from different thread
factory.executor.submit(() -> {
mbean.refreshStats(1, TimeUnit.SECONDS);
}).get();
assertEquals(mbean.getAddEntryBytesRate(), 0.0);
assertEquals(mbean.getAddEntryMessagesRate(), 0.0);
assertEquals(mbean.getAddEntrySucceed(), 0);
assertEquals(mbean.getAddEntryErrors(), 0);
assertEquals(mbean.getReadEntriesBytesRate(), 0.0);
assertEquals(mbean.getReadEntriesRate(), 0.0);
assertEquals(mbean.getReadEntriesSucceeded(), 0);
assertEquals(mbean.getReadEntriesErrors(), 0);
assertEquals(mbean.getMarkDeleteRate(), 0.0);
assertEquals(mbean.getAddEntryLatencyBuckets(), new long[] { 0, 1, 0, 1, 0, 0, 0, 0, 1, 0 });
assertEquals(mbean.getAddEntryLatencyAverageUsec(), 337_000.0);
assertEquals(mbean.getEntrySizeBuckets(), new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 });
assertEquals(mbean.getLedgerSwitchLatencyBuckets(), new long[] { 0, 1, 0, 1, 0, 0, 0, 0, 1, 0 });
assertEquals(mbean.getLedgerSwitchLatencyAverageUsec(), 337_000.0);
Position p1 = ledger.addEntry(new byte[200]);
ledger.addEntry(new byte[600]);
cursor.markDelete(p1);
factory.executor.submit(() -> {
mbean.refreshStats(1, TimeUnit.SECONDS);
}).get();
assertEquals(mbean.getAddEntryBytesRate(), 800.0);
assertEquals(mbean.getAddEntryMessagesRate(), 2.0);
assertEquals(mbean.getAddEntrySucceed(), 2);
assertEquals(mbean.getAddEntryErrors(), 0);
assertEquals(mbean.getReadEntriesBytesRate(), 0.0);
assertEquals(mbean.getReadEntriesRate(), 0.0);
assertEquals(mbean.getReadEntriesSucceeded(), 0);
assertEquals(mbean.getReadEntriesErrors(), 0);
assertTrue(mbean.getMarkDeleteRate() > 0.0);
assertEquals(mbean.getEntrySizeBuckets(), new long[] { 0, 1, 1, 0, 0, 0, 0, 0, 0 });
mbean.recordAddEntryError();
mbean.recordReadEntriesError();
factory.executor.submit(() -> {
mbean.refreshStats(1, TimeUnit.SECONDS);
}).get();
assertEquals(mbean.getAddEntryErrors(), 1);
assertEquals(mbean.getReadEntriesErrors(), 1);
List<Entry> entries = cursor.readEntries(100);
assertEquals(entries.size(), 1);
factory.executor.submit(() -> {
mbean.refreshStats(1, TimeUnit.SECONDS);
}).get();
assertEquals(mbean.getReadEntriesBytesRate(), 600.0);
assertEquals(mbean.getReadEntriesRate(), 1.0);
assertEquals(mbean.getReadEntriesSucceeded(), 1);
assertEquals(mbean.getReadEntriesErrors(), 0);
assertEquals(mbean.getNumberOfMessagesInBacklog(), 1);
assertEquals(mbean.getMarkDeleteRate(), 0.0);
factory.shutdown();
}
Aggregations