Java Code Examples for org.apache.bookkeeper.client.LedgerHandle#asyncAddEntry()
The following examples show how to use
org.apache.bookkeeper.client.LedgerHandle#asyncAddEntry() .
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: TwoPhaseCompactor.java From pulsar with Apache License 2.0 | 5 votes |
private CompletableFuture<Void> addToCompactedLedger(LedgerHandle lh, RawMessage m) { CompletableFuture<Void> bkf = new CompletableFuture<>(); ByteBuf serialized = m.serialize(); lh.asyncAddEntry(serialized, (rc, ledger, eid, ctx) -> { if (rc != BKException.Code.OK) { bkf.completeExceptionally(BKException.create(rc)); } else { bkf.complete(null); } }, null); return bkf; }
Example 2
Source File: BookkeeperSchemaStorage.java From pulsar with Apache License 2.0 | 5 votes |
@NotNull private CompletableFuture<Long> addEntry(LedgerHandle ledgerHandle, SchemaStorageFormat.SchemaEntry entry) { final CompletableFuture<Long> future = new CompletableFuture<>(); ledgerHandle.asyncAddEntry(entry.toByteArray(), (rc, handle, entryId, ctx) -> { if (rc != BKException.Code.OK) { future.completeExceptionally(bkException("Failed to add entry", rc, ledgerHandle.getId(), -1)); } else { future.complete(entryId); } }, null ); return future; }
Example 3
Source File: ManagedCursorImpl.java From pulsar with Apache License 2.0 | 4 votes |
void persistPositionToLedger(final LedgerHandle lh, MarkDeleteEntry mdEntry, final VoidCallback callback) { PositionImpl position = mdEntry.newPosition; PositionInfo pi = PositionInfo.newBuilder().setLedgerId(position.getLedgerId()) .setEntryId(position.getEntryId()) .addAllIndividualDeletedMessages(buildIndividualDeletedMessageRanges()) .addAllBatchedEntryDeletionIndexInfo(buildBatchEntryDeletionIndexInfoList()) .addAllProperties(buildPropertiesMap(mdEntry.properties)).build(); if (log.isDebugEnabled()) { log.debug("[{}] Cursor {} Appending to ledger={} position={}", ledger.getName(), name, lh.getId(), position); } checkNotNull(lh); lh.asyncAddEntry(pi.toByteArray(), (rc, lh1, entryId, ctx) -> { if (rc == BKException.Code.OK) { if (log.isDebugEnabled()) { log.debug("[{}] Updated cursor {} position {} in meta-ledger {}", ledger.getName(), name, position, lh1.getId()); } if (shouldCloseLedger(lh1)) { if (log.isDebugEnabled()) { log.debug("[{}] Need to create new metadata ledger for consumer {}", ledger.getName(), name); } startCreatingNewMetadataLedger(); } callback.operationComplete(); } else { log.warn("[{}] Error updating cursor {} position {} in meta-ledger {}: {}", ledger.getName(), name, position, lh1.getId(), BKException.getMessage(rc)); // If we've had a write error, the ledger will be automatically closed, we need to create a new one, // in the meantime the mark-delete will be queued. STATE_UPDATER.compareAndSet(ManagedCursorImpl.this, State.Open, State.NoLedger); // Before giving up, try to persist the position in the metadata store persistPositionMetaStore(-1, position, mdEntry.properties, new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat stat) { if (log.isDebugEnabled()) { log.debug( "[{}][{}] Updated cursor in meta store after previous failure in ledger at position {}", ledger.getName(), name, position); } callback.operationComplete(); } @Override public void operationFailed(MetaStoreException e) { log.warn("[{}][{}] Failed to update cursor in meta store after previous failure in ledger: {}", ledger.getName(), name, e.getMessage()); callback.operationFailed(createManagedLedgerException(rc)); } }, true); } }, null); }