/** * Opens a ledger. This operation also fences out the ledger in case anyone else was writing to it. * * @param ledgerId The Id of the Ledger to open. * @param bookKeeper A references to the BookKeeper client to use. * @param config Configuration to use. * @return A LedgerHandle for the newly opened ledger. * @throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it. */ static LedgerHandle openFence(long ledgerId, BookKeeper bookKeeper, BookKeeperConfig config) throws DurableDataLogException { try { return Exceptions.handleInterruptedCall( () -> bookKeeper.openLedger(ledgerId, LEDGER_DIGEST_TYPE, config.getBKPassword())); } catch (BKException bkEx) { throw new DurableDataLogException(String.format("Unable to open-fence ledger %d.", ledgerId), bkEx); } }
/** * Opens a ledger for reading. This operation does not fence out the ledger. * * @param ledgerId The Id of the Ledger to open. * @param bookKeeper A references to the BookKeeper client to use. * @param config Configuration to use. * @return A LedgerHandle for the newly opened ledger. * @throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it. */ static LedgerHandle openRead(long ledgerId, BookKeeper bookKeeper, BookKeeperConfig config) throws DurableDataLogException { try { return Exceptions.handleInterruptedCall( () -> bookKeeper.openLedgerNoRecovery(ledgerId, LEDGER_DIGEST_TYPE, config.getBKPassword())); } catch (BKException bkEx) { throw new DurableDataLogException(String.format("Unable to open-read ledger %d.", ledgerId), bkEx); } }
/** * Creates a new Ledger in BookKeeper. * * @return A LedgerHandle for the new ledger. * @throws DataLogNotAvailableException If BookKeeper is unavailable or the ledger could not be created because an * insufficient number of Bookies are available. The causing exception is wrapped * inside it. * @throws DurableDataLogException If another exception occurred. The causing exception is wrapped inside it. */ static LedgerHandle create(BookKeeper bookKeeper, BookKeeperConfig config) throws DurableDataLogException { try { return Exceptions.handleInterruptedCall(() -> bookKeeper.createLedger( config.getBkEnsembleSize(), config.getBkWriteQuorumSize(), config.getBkAckQuorumSize(), LEDGER_DIGEST_TYPE, config.getBKPassword())); } catch (BKException.BKNotEnoughBookiesException bkEx) { throw new DataLogNotAvailableException("Unable to create new BookKeeper Ledger.", bkEx); } catch (BKException bkEx) { throw new DurableDataLogException("Unable to create new BookKeeper Ledger.", bkEx); } }
@Test public void testDefaultValues() { BookKeeperConfig cfg = BookKeeperConfig.builder() .build(); Assert.assertEquals("localhost:2181", cfg.getZkAddress()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkSessionTimeout()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkConnectionTimeout()); Assert.assertEquals("/segmentstore/containers", cfg.getZkMetadataPath()); Assert.assertEquals(2, cfg.getZkHierarchyDepth()); Assert.assertEquals(5, cfg.getMaxWriteAttempts()); Assert.assertEquals(3, cfg.getBkEnsembleSize()); Assert.assertEquals(2, cfg.getBkAckQuorumSize()); Assert.assertEquals(3, cfg.getBkWriteQuorumSize()); Assert.assertEquals(5000, cfg.getBkWriteTimeoutMillis()); Assert.assertEquals(5000, cfg.getBkReadTimeoutMillis()); Assert.assertEquals(1024 * 1024 * 1024, cfg.getBkLedgerMaxSize()); Assert.assertEquals(0, cfg.getBKPassword().length); Assert.assertEquals("", cfg.getBkLedgerPath()); Assert.assertEquals(false, cfg.isTLSEnabled()); Assert.assertEquals("config/client.truststore.jks", cfg.getTlsTrustStore()); Assert.assertEquals("", cfg.getTlsTrustStorePasswordPath()); }