本文整理汇总了Java中org.apache.bookkeeper.client.LedgerHandle.getLastAddConfirmed方法的典型用法代码示例。如果您正苦于以下问题:Java LedgerHandle.getLastAddConfirmed方法的具体用法?Java LedgerHandle.getLastAddConfirmed怎么用?Java LedgerHandle.getLastAddConfirmed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bookkeeper.client.LedgerHandle
的用法示例。
在下文中一共展示了LedgerHandle.getLastAddConfirmed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BookKeeperEditLogInputStream
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Construct BookKeeper edit log input stream.
* Starts reading from firstBookKeeperEntry. This allows the stream
* to take a shortcut during recovery, as it doesn't have to read
* every edit log transaction to find out what the last one is.
*/
BookKeeperEditLogInputStream(LedgerHandle lh, EditLogLedgerMetadata metadata,
long firstBookKeeperEntry)
throws IOException {
this.lh = lh;
this.firstTxId = metadata.getFirstTxId();
this.lastTxId = metadata.getLastTxId();
this.logVersion = metadata.getDataLayoutVersion();
this.inProgress = metadata.isInProgress();
if (firstBookKeeperEntry < 0
|| firstBookKeeperEntry > lh.getLastAddConfirmed()) {
throw new IOException("Invalid first bk entry to read: "
+ firstBookKeeperEntry + ", LAC: " + lh.getLastAddConfirmed());
}
BufferedInputStream bin = new BufferedInputStream(
new LedgerInputStream(lh, firstBookKeeperEntry));
tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);
DataInputStream in = new DataInputStream(tracker);
reader = new FSEditLogOp.Reader(in, tracker, logVersion);
}
示例2: BookKeeperEditLogInputStream
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Construct BookKeeper edit log input stream.
* Starts reading from firstBookKeeperEntry. This allows the stream
* to take a shortcut during recovery, as it doesn't have to read
* every edit log transaction to find out what the last one is.
*/
BookKeeperEditLogInputStream(LedgerHandle lh, EditLogLedgerMetadata metadata,
long firstBookKeeperEntry)
throws IOException {
this.lh = lh;
this.firstTxId = metadata.getFirstTxId();
this.lastTxId = metadata.getLastTxId();
this.logVersion = metadata.getDataLayoutVersion();
this.inProgress = metadata.isInProgress();
if (firstBookKeeperEntry < 0
|| firstBookKeeperEntry > lh.getLastAddConfirmed()) {
throw new IOException("Invalid first bk entry to read: "
+ firstBookKeeperEntry + ", LAC: " + lh.getLastAddConfirmed());
}
BufferedInputStream bin = new BufferedInputStream(
new LedgerInputStream(lh, firstBookKeeperEntry));
tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);
DataInputStream in = new DataInputStream(tracker);
reader = FSEditLogOp.Reader.create(in, tracker, logVersion);
}
示例3: LedgerStreamReader
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
public LedgerStreamReader(LedgerHandle lh,
ReadEntryListener readEntryListener,
int concurrency) {
this.lh = lh;
this.lac = lh.getLastAddConfirmed();
this.readEntryListener = readEntryListener;
this.concurrency = concurrency;
for (int i = 0; i < concurrency; i++) {
long entryId = nextReadEntry.getAndIncrement();
if (entryId > lac) {
break;
}
PendingReadRequest request = new PendingReadRequest(entryId);
pendingReads.add(request);
request.read();
}
if (pendingReads.isEmpty()) {
done.countDown();
}
}
示例4: LedgerInputStream
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Construct ledger input stream
* @param lh the ledger handle to read from
* @param firstBookKeeperEntry ledger entry to start reading from
*/
LedgerInputStream(LedgerHandle lh, long firstBookKeeperEntry)
throws IOException {
this.lh = lh;
readEntries = firstBookKeeperEntry;
maxEntry = lh.getLastAddConfirmed();
}
示例5: shouldCloseLedger
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
boolean shouldCloseLedger(LedgerHandle lh) {
long now = System.currentTimeMillis();
if ((lh.getLastAddConfirmed() >= config.getMetadataMaxEntriesPerLedger()
|| lastLedgerSwitchTimestamp < (now - config.getLedgerRolloverTimeout() * 1000))
&& STATE_UPDATER.get(this) != State.Closed) {
// It's safe to modify the timestamp since this method will be only called from a callback, implying that
// calls will be serialized on one single thread
lastLedgerSwitchTimestamp = now;
return true;
} else {
return false;
}
}
示例6: readLastAddConfirmed
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Reliably retrieves the LastAddConfirmed for the Ledger with given LedgerId, by opening the Ledger in fencing mode
* and getting the value. NOTE: this open-fences the Ledger which will effectively stop any writing action on it.
*
* @param ledgerId The Id of the Ledger to query.
* @param bookKeeper A references to the BookKeeper client to use.
* @param config Configuration to use.
* @return The LastAddConfirmed for the given LedgerId.
* @throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it.
*/
static long readLastAddConfirmed(long ledgerId, BookKeeper bookKeeper, BookKeeperConfig config) throws DurableDataLogException {
LedgerHandle h = null;
try {
// Here we open the Ledger WITH recovery, to force BookKeeper to reconcile any appends that may have been
// interrupted and not properly acked. Otherwise there is no guarantee we can get an accurate value for
// LastAddConfirmed.
h = openFence(ledgerId, bookKeeper, config);
return h.getLastAddConfirmed();
} finally {
if (h != null) {
close(h);
}
}
}
示例7: fenceOut
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Fences out a Log made up of the given ledgers.
*
* @param ledgers An ordered list of LedgerMetadata objects representing all the Ledgers in the log.
* @param bookKeeper A reference to the BookKeeper client to use.
* @param config Configuration to use.
* @param traceObjectId Used for logging.
* @return A Map of LedgerId to LastAddConfirmed for those Ledgers that were fenced out and had a different
* LastAddConfirmed than what their LedgerMetadata was indicating.
* @throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it.
*/
static Map<Long, Long> fenceOut(List<LedgerMetadata> ledgers, BookKeeper bookKeeper, BookKeeperConfig config, String traceObjectId) throws DurableDataLogException {
// Fence out the ledgers, in descending order. During the process, we need to determine whether the ledgers we
// fenced out actually have any data in them, and update the LedgerMetadata accordingly.
// We need to fence out at least MIN_FENCE_LEDGER_COUNT ledgers that are not empty to properly ensure we fenced
// the log correctly and identify any empty ledgers (Since this algorithm is executed upon every recovery, any
// empty ledgers should be towards the end of the Log).
int nonEmptyCount = 0;
val result = new HashMap<Long, Long>();
val iterator = ledgers.listIterator(ledgers.size());
while (iterator.hasPrevious() && (nonEmptyCount < MIN_FENCE_LEDGER_COUNT)) {
LedgerMetadata ledgerMetadata = iterator.previous();
LedgerHandle handle = openFence(ledgerMetadata.getLedgerId(), bookKeeper, config);
if (handle.getLastAddConfirmed() != NO_ENTRY_ID) {
// Non-empty.
nonEmptyCount++;
}
if (ledgerMetadata.getStatus() == LedgerMetadata.Status.Unknown) {
// We did not know the status of this Ledger before, but now we do.
result.put(ledgerMetadata.getLedgerId(), handle.getLastAddConfirmed());
}
close(handle);
log.info("{}: Fenced out Ledger {}.", traceObjectId, ledgerMetadata);
}
return result;
}
示例8: repairLogSegment
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
protected void repairLogSegment(BookKeeperAdmin bkAdmin,
MetadataUpdater metadataUpdater,
LogSegmentMetadata segment) throws Exception {
if (segment.isInProgress()) {
System.out.println("Skip inprogress log segment " + segment);
return;
}
LedgerHandle lh = bkAdmin.openLedger(segment.getLedgerId(), true);
long lac = lh.getLastAddConfirmed();
Enumeration<LedgerEntry> entries = lh.readEntries(lac, lac);
if (!entries.hasMoreElements()) {
throw new IOException("Entry " + lac + " isn't found for " + segment);
}
LedgerEntry lastEntry = entries.nextElement();
Entry.Reader reader = Entry.newBuilder()
.setLogSegmentInfo(segment.getLogSegmentSequenceNumber(), segment.getStartSequenceId())
.setEntryId(lastEntry.getEntryId())
.setEnvelopeEntry(LogSegmentMetadata.supportsEnvelopedEntries(segment.getVersion()))
.setInputStream(lastEntry.getEntryInputStream())
.buildReader();
LogRecordWithDLSN record = reader.nextRecord();
LogRecordWithDLSN lastRecord = null;
while (null != record) {
lastRecord = record;
record = reader.nextRecord();
}
if (null == lastRecord) {
throw new IOException("No record found in entry " + lac + " for " + segment);
}
System.out.println("Updating last record for " + segment + " to " + lastRecord);
if (!IOUtils.confirmPrompt("Do you want to make this change (Y/N): ")) {
return;
}
metadataUpdater.updateLastRecord(segment, lastRecord);
}
示例9: recoverLastTxId
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Find the id of the last edit log transaction writen to a edit log
* ledger.
*/
private long recoverLastTxId(EditLogLedgerMetadata l, boolean fence)
throws IOException, SegmentEmptyException {
LedgerHandle lh = null;
try {
if (fence) {
lh = bkc.openLedger(l.getLedgerId(),
BookKeeper.DigestType.MAC,
digestpw.getBytes(Charsets.UTF_8));
} else {
lh = bkc.openLedgerNoRecovery(l.getLedgerId(),
BookKeeper.DigestType.MAC,
digestpw.getBytes(Charsets.UTF_8));
}
} catch (BKException bke) {
throw new IOException("Exception opening ledger for " + l, bke);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted opening ledger for " + l, ie);
}
BookKeeperEditLogInputStream in = null;
try {
long lastAddConfirmed = lh.getLastAddConfirmed();
if (lastAddConfirmed == -1) {
throw new SegmentEmptyException();
}
in = new BookKeeperEditLogInputStream(lh, l, lastAddConfirmed);
long endTxId = HdfsConstants.INVALID_TXID;
FSEditLogOp op = in.readOp();
while (op != null) {
if (endTxId == HdfsConstants.INVALID_TXID
|| op.getTransactionId() == endTxId+1) {
endTxId = op.getTransactionId();
}
op = in.readOp();
}
return endTxId;
} finally {
if (in != null) {
in.close();
}
}
}
示例10: recoverLastTxId
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
* Find the id of the last edit log transaction writen to a edit log
* ledger.
*/
private long recoverLastTxId(EditLogLedgerMetadata l, boolean fence)
throws IOException, SegmentEmptyException {
LedgerHandle lh = null;
try {
if (fence) {
lh = bkc.openLedger(l.getLedgerId(),
BookKeeper.DigestType.MAC,
digestpw.getBytes(Charsets.UTF_8));
} else {
lh = bkc.openLedgerNoRecovery(l.getLedgerId(),
BookKeeper.DigestType.MAC,
digestpw.getBytes(Charsets.UTF_8));
}
} catch (BKException bke) {
throw new IOException("Exception opening ledger for " + l, bke);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted opening ledger for " + l, ie);
}
BookKeeperEditLogInputStream in = null;
try {
long lastAddConfirmed = lh.getLastAddConfirmed();
if (lastAddConfirmed == -1) {
throw new SegmentEmptyException();
}
in = new BookKeeperEditLogInputStream(lh, l, lastAddConfirmed);
long endTxId = HdfsServerConstants.INVALID_TXID;
FSEditLogOp op = in.readOp();
while (op != null) {
if (endTxId == HdfsServerConstants.INVALID_TXID
|| op.getTransactionId() == endTxId+1) {
endTxId = op.getTransactionId();
}
op = in.readOp();
}
return endTxId;
} finally {
if (in != null) {
in.close();
}
}
}
示例11: ledgerClosed
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
synchronized void ledgerClosed(final LedgerHandle lh) {
final State state = STATE_UPDATER.get(this);
if (state == State.ClosingLedger || state == State.LedgerOpened) {
STATE_UPDATER.set(this, State.ClosedLedger);
} else {
// In case we get multiple write errors for different outstanding write request, we should close the ledger
// just once
return;
}
long entriesInLedger = lh.getLastAddConfirmed() + 1;
if (log.isDebugEnabled()) {
log.debug("[{}] Ledger has been closed id={} entries={}", name, lh.getId(), entriesInLedger);
}
if (entriesInLedger > 0) {
LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lh.getId()).setEntries(entriesInLedger)
.setSize(lh.getLength()).setTimestamp(System.currentTimeMillis()).build();
ledgers.put(lh.getId(), info);
} else {
// The last ledger was empty, so we can discard it
ledgers.remove(lh.getId());
mbean.startDataLedgerDeleteOp();
bookKeeper.asyncDeleteLedger(lh.getId(), (rc, ctx) -> {
mbean.endDataLedgerDeleteOp();
log.info("[{}] Delete complete for empty ledger {}. rc={}", name, lh.getId(), rc);
}, null);
}
trimConsumedLedgersInBackground();
if (!pendingAddEntries.isEmpty()) {
// Need to create a new ledger to write pending entries
if (log.isDebugEnabled()) {
log.debug("[{}] Creating a new ledger", name);
}
STATE_UPDATER.set(this, State.CreatingLedger);
this.lastLedgerCreationInitiationTimestamp = System.nanoTime();
mbean.startDataLedgerCreateOp();
bookKeeper.asyncCreateLedger(config.getEnsembleSize(), config.getWriteQuorumSize(),
config.getAckQuorumSize(), config.getDigestType(), config.getPassword(), this, null);
}
}
示例12: internalReadFromLedger
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
private void internalReadFromLedger(LedgerHandle ledger, OpReadEntry opReadEntry) {
// Perform the read
long firstEntry = opReadEntry.readPosition.getEntryId();
long lastEntryInLedger;
final ManagedCursorImpl cursor = opReadEntry.cursor;
PositionImpl lastPosition = lastConfirmedEntry;
if (ledger.getId() == lastPosition.getLedgerId()) {
// For the current ledger, we only give read visibility to the last entry we have received a confirmation in
// the managed ledger layer
lastEntryInLedger = lastPosition.getEntryId();
} else {
// For other ledgers, already closed the BK lastAddConfirmed is appropriate
lastEntryInLedger = ledger.getLastAddConfirmed();
}
if (firstEntry > lastEntryInLedger) {
if (log.isDebugEnabled()) {
log.debug("[{}] No more messages to read from ledger={} lastEntry={} readEntry={}", name,
ledger.getId(), lastEntryInLedger, firstEntry);
}
if (ledger.getId() != currentLedger.getId()) {
// Cursor was placed past the end of one ledger, move it to the
// beginning of the next ledger
Long nextLedgerId = ledgers.ceilingKey(ledger.getId() + 1);
opReadEntry.updateReadPosition(new PositionImpl(nextLedgerId, 0));
}
opReadEntry.checkReadCompletion();
return;
}
long lastEntry = min(firstEntry + opReadEntry.getNumberOfEntriesToRead() - 1, lastEntryInLedger);
if (log.isDebugEnabled()) {
log.debug("[{}] Reading entries from ledger {} - first={} last={}", name, ledger.getId(), firstEntry,
lastEntry);
}
entryCache.asyncReadEntry(ledger, firstEntry, lastEntry, false, opReadEntry, opReadEntry.ctx);
if (updateCursorRateLimit.tryAcquire()) {
if (isCursorActive(cursor)) {
final PositionImpl lastReadPosition = PositionImpl.get(ledger.getId(), lastEntry);
discardEntriesFromCache(cursor, lastReadPosition);
}
}
}
示例13: getCursorLedgerLastEntry
import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
public long getCursorLedgerLastEntry() {
LedgerHandle lh = cursorLedger;
return lh != null ? lh.getLastAddConfirmed() : -1;
}