Java Code Examples for org.apache.bookkeeper.client.BKException#BKNoSuchLedgerExistsException
The following examples show how to use
org.apache.bookkeeper.client.BKException#BKNoSuchLedgerExistsException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBKDistributedLogManager.java From distributedlog with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testDeleteLog() throws Exception { String name = "delete-log-should-delete-ledgers"; DistributedLogManager dlm = createNewDLM(conf, name); long txid = 1; // Create the log and write some records BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned(); for (long j = 1; j <= DEFAULT_SEGMENT_SIZE; j++) { writer.write(DLMTestUtil.getLogRecordInstance(txid++)); } BKLogSegmentWriter perStreamLogWriter = writer.getCachedLogWriter(); writer.closeAndComplete(); BKLogWriteHandler blplm = ((BKDistributedLogManager) (dlm)).createWriteHandler(true); assertNotNull(zkc.exists(blplm.completedLedgerZNode(txid, txid - 1, perStreamLogWriter.getLogSegmentSequenceNumber()), false)); Utils.ioResult(blplm.asyncClose()); // Should be able to open the underline ledger using BK client long ledgerId = perStreamLogWriter.getLogSegmentId(); BKNamespaceDriver driver = (BKNamespaceDriver) dlm.getNamespaceDriver(); driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8)); // Delete the log and we shouldn't be able the open the ledger dlm.delete(); try { driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8)); fail("Should fail to open ledger after we delete the log"); } catch (BKException.BKNoSuchLedgerExistsException e) { // ignore } // delete again should not throw any exception try { dlm.delete(); } catch (IOException ioe) { fail("Delete log twice should not throw any exception"); } }
Example 2
Source File: TestBaseOffload.java From pulsar with Apache License 2.0 | 5 votes |
public boolean ledgerExistsInBookKeeper(long ledgerId) throws Exception { ClientConfiguration bkConf = new ClientConfiguration(); bkConf.setZkServers(pulsarCluster.getZKConnString()); try (BookKeeperAdmin bk = new BookKeeperAdmin(bkConf)) { try { bk.openLedger(ledgerId).close(); return true; } catch (BKException.BKNoSuchLedgerExistsException | BKException.BKNoSuchLedgerExistsOnMetadataServerException e) { return false; } } }
Example 3
Source File: CompactedTopicTest.java From pulsar with Apache License 2.0 | 4 votes |
@Test public void testCleanupOldCompactedTopicLedger() throws Exception { BookKeeper bk = pulsar.getBookKeeperClientFactory().create( this.conf, null, Optional.empty(), null); LedgerHandle oldCompactedLedger = bk.createLedger(1, 1, Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD); oldCompactedLedger.close(); LedgerHandle newCompactedLedger = bk.createLedger(1, 1, Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD); newCompactedLedger.close(); // set the compacted topic ledger CompactedTopicImpl compactedTopic = new CompactedTopicImpl(bk); compactedTopic.newCompactedLedger(new PositionImpl(1,2), oldCompactedLedger.getId()).get(); // ensure both ledgers still exist, can be opened bk.openLedger(oldCompactedLedger.getId(), Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD).close(); bk.openLedger(newCompactedLedger.getId(), Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD).close(); // update the compacted topic ledger compactedTopic.newCompactedLedger(new PositionImpl(1,2), newCompactedLedger.getId()).get(); // old ledger should be deleted, new still there try { bk.openLedger(oldCompactedLedger.getId(), Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD).close(); Assert.fail("Should have failed to open old ledger"); } catch (BKException.BKNoSuchLedgerExistsException | BKException.BKNoSuchLedgerExistsOnMetadataServerException e) { // correct, expected behaviour } bk.openLedger(newCompactedLedger.getId(), Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD).close(); }