while (numRetries > 0) { try { LedgerHandle lh = bkc.get().openLedger(lid, BookKeeper.DigestType.CRC32, passwd); lh.close(); System.out.println("Fenced ledger " + lid + ", " + numPendings.decrementAndGet() + " left.");
handle = bookKeeper.openLedger(ledgerId, BookKeeper.DigestType.CRC32C, sharedSecret.getBytes(StandardCharsets.UTF_8)); } else { handle = bookKeeper.openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32C, sharedSecret.getBytes(StandardCharsets.UTF_8));
LedgerHandle lh = bkc.get().openLedger(ledgerId, BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); LedgerHandle readLh = bkc.get().openLedger(ledgerId, BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); LedgerReader lr = new LedgerReader(bkc.get());
private LedgerHandle openLedger(LedgerHandle lh) throws Exception { return bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8)); }
private void fenceLedger(LedgerHandle lh) throws Exception { bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8)); }
public static void fenceStream(DistributedLogConfiguration conf, URI uri, String name) throws Exception { BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(name, conf, uri); try { BKLogReadHandler readHandler = dlm.createReadHandler(); List<LogSegmentMetadata> ledgerList = readHandler.getFullLedgerList(true, true); LogSegmentMetadata lastSegment = ledgerList.get(ledgerList.size() - 1); BookKeeperClient bkc = dlm.getWriterBKC(); LedgerHandle lh = bkc.get().openLedger(lastSegment.getLedgerId(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8)); lh.close(); } finally { dlm.close(); } }
@Test(timeout = 60000) public void testCloseAllocatorDuringObtaining() throws Exception { String allocationPath = "/allocation2"; SimpleLedgerAllocator allocator = createAllocator(allocationPath); allocator.allocate(); ZKTransaction txn = newTxn(); // close during obtaining ledger. LedgerHandle lh = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER)); Utils.close(allocator); byte[] data = zkc.get().getData(allocationPath, false, null); assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8))); // the ledger is not deleted bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8)); }
@Test(timeout = 60000) public void testCloseAllocatorAfterAbort() throws Exception { String allocationPath = "/allocation3"; SimpleLedgerAllocator allocator = createAllocator(allocationPath); allocator.allocate(); ZKTransaction txn = newTxn(); // close during obtaining ledger. LedgerHandle lh = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER)); txn.addOp(DefaultZKOp.of(Op.setData("/unexistedpath", "data".getBytes(UTF_8), -1))); try { FutureUtils.result(txn.execute()); fail("Should fail the transaction when setting unexisted path"); } catch (ZKException ke) { // expected } Utils.close(allocator); byte[] data = zkc.get().getData(allocationPath, false, null); assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8))); // the ledger is not deleted. bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8)); }
/** * {@link https://issues.apache.org/jira/browse/DL-26} */ @DistributedLogAnnotations.FlakyTest @Ignore @Test(timeout = 60000) public void testCloseAllocatorAfterConfirm() throws Exception { String allocationPath = "/allocation2"; SimpleLedgerAllocator allocator = createAllocator(allocationPath); allocator.allocate(); ZKTransaction txn = newTxn(); // close during obtaining ledger. LedgerHandle lh = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER)); FutureUtils.result(txn.execute()); Utils.close(allocator); byte[] data = zkc.get().getData(allocationPath, false, null); assertEquals(0, data.length); // the ledger is not deleted. bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8)); }
LedgerHandle readLh = bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes()); Enumeration<LedgerEntry> entries = readLh.readEntries(eid, eid); int i = 0;
bkc.get().openLedger(lh1.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes()); fail("LedgerHandle allocated by allocator1 should be deleted."); } catch (BKException.BKNoSuchLedgerExistsException nslee) { LedgerHandle readLh = bkc.get().openLedger(lh2.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes()); Enumeration<LedgerEntry> entries = readLh.readEntries(eid, eid); int i = 0;
dlm.getWriterBKC().get().openLedger(logWriter.getLogSegmentId(), BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
dlm.getWriterBKC().get().openLedger(logWriter.getLogSegmentId(), BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
/** * 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); } }
LedgerHandle lh = bkc.get().openLedger(ledgerId, BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); LedgerHandle readLh = bkc.get().openLedger(ledgerId, BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); LedgerReader lr = new LedgerReader(bkc.get());
lh = bk.openLedger(lh.getId(), DigestType.MAC, new byte[0]); if (lh.getLastAddConfirmed() != (numberOfEntries - 1)) { throw new Exception("Invalid last entry found on ledger. expecting: " + (numberOfEntries - 1)