use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo in project pulsar by yahoo.
the class MetaStoreImplZookeeperTest method readMalformedML.
@Test(timeOut = 20000)
void readMalformedML() throws Exception {
MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
zkc.create("/managed-ledgers/my_test", "non-valid".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final CountDownLatch latch = new CountDownLatch(1);
store.getManagedLedgerInfo("my_test", new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() {
public void operationFailed(MetaStoreException e) {
// Ok
latch.countDown();
}
public void operationComplete(ManagedLedgerInfo result, Stat version) {
fail("Operation should have failed");
}
});
latch.await();
}
use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo in project pulsar by yahoo.
the class MetaStoreImplZookeeperTest method failInCreatingMLnode.
@Test(timeOut = 20000)
void failInCreatingMLnode() throws Exception {
MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
final CountDownLatch latch = new CountDownLatch(1);
zkc.failAfter(1, Code.CONNECTIONLOSS);
store.getManagedLedgerInfo("my_test", new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() {
public void operationFailed(MetaStoreException e) {
// Ok
latch.countDown();
}
public void operationComplete(ManagedLedgerInfo result, Stat version) {
fail("Operation should have failed");
}
});
latch.await();
}
use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo in project pulsar by yahoo.
the class ManagedLedgerTest method testBackwardCompatiblityForMeta.
@Test
public void testBackwardCompatiblityForMeta() throws Exception {
final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3];
final Stat[] versions = new Stat[1];
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
conf.setRetentionSizeInMB(10);
conf.setRetentionTime(1, TimeUnit.HOURS);
ManagedLedger ml = factory.open("backward_test_ledger", conf);
ml.openCursor("c1");
ml.addEntry("msg1".getBytes());
ml.addEntry("msg2".getBytes());
ml.close();
MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
CountDownLatch l1 = new CountDownLatch(1);
// obtain the ledger info
store.getManagedLedgerInfo("backward_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {
@Override
public void operationComplete(ManagedLedgerInfo result, Stat version) {
storedMLInfo[0] = result;
versions[0] = version;
l1.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
fail("on get ManagedLedgerInfo backward_test_ledger");
}
});
l1.await();
ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder();
// simulate test for old ledger with no timestampl
for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) {
LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp().build();
assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp");
builder1.addLedgerInfo(noTimestamp);
}
storedMLInfo[1] = builder1.build();
// test timestamp on new ledger
CountDownLatch l2 = new CountDownLatch(1);
store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0], new MetaStoreCallback<Void>() {
@Override
public void operationComplete(Void result, Stat version) {
l2.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
fail("on asyncUpdateLedgerIds");
}
});
// verify that after update ledgers have timestamp
ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf);
List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList();
assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() {
@Override
public boolean test(LedgerInfo ledgerInfo) {
return ledgerInfo.hasTimestamp();
}
}));
}
use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo in project pulsar by yahoo.
the class ManagedLedgerImpl method updateLedgersListAfterRollover.
private void updateLedgersListAfterRollover(MetaStoreCallback<Void> callback) {
if (!ledgersListMutex.tryLock()) {
// Defer update for later
scheduledExecutor.schedule(() -> updateLedgersListAfterRollover(callback), 100, TimeUnit.MILLISECONDS);
return;
}
ManagedLedgerInfo mlInfo = ManagedLedgerInfo.newBuilder().addAllLedgerInfo(ledgers.values()).build();
if (log.isDebugEnabled()) {
log.debug("[{}] Updating ledgers ids with new ledger. version={}", name, ledgersStat);
}
store.asyncUpdateLedgerIds(name, mlInfo, ledgersStat, callback);
}
use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo in project pulsar by yahoo.
the class ManagedLedgerTest method cursorReadsWithDiscardedEmptyLedgersStillListed.
@Test
public void cursorReadsWithDiscardedEmptyLedgersStillListed() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("entry-1".getBytes());
ledger.close();
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
ledger.addEntry("entry-2".getBytes());
final LedgerInfo l1info = ledger.getLedgersInfoAsList().get(0);
final LedgerInfo l2info = ledger.getLedgersInfoAsList().get(1);
ledger.close();
// Add the deleted ledger back in the meta-data to simulate an empty ledger that was deleted but not removed
// from the list of ledgers
final CountDownLatch counter = new CountDownLatch(1);
final MetaStore store = factory.getMetaStore();
store.getManagedLedgerInfo("my_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {
@Override
public void operationComplete(ManagedLedgerInfo result, Stat version) {
// Update the list
ManagedLedgerInfo.Builder info = ManagedLedgerInfo.newBuilder(result);
info.clearLedgerInfo();
info.addLedgerInfo(LedgerInfo.newBuilder().setLedgerId(l1info.getLedgerId()).build());
info.addLedgerInfo(l2info);
store.asyncUpdateLedgerIds("my_test_ledger", info.build(), version, new MetaStoreCallback<Void>() {
@Override
public void operationComplete(Void result, Stat version) {
counter.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
counter.countDown();
}
});
}
@Override
public void operationFailed(MetaStoreException e) {
counter.countDown();
}
});
// Wait for the change to be effective
counter.await();
// Delete the ledger and mantain it in the ledgers list
bkc.deleteLedger(l1info.getLedgerId());
// re-open
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
assertEquals(c1.getNumberOfEntries(), 1);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(ledger.getLedgersInfoAsList().size(), 2);
List<Entry> entries = c1.readEntries(10);
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
assertEquals(c1.hasMoreEntries(), false);
entries = c1.readEntries(1);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
}
Aggregations