@Override public long getEpoch() { ensurePreconditions(); return getLogMetadata().getEpoch(); }
@Override public CloseableIterator<ReadItem, DurableDataLogException> getReader() throws DurableDataLogException { ensurePreconditions(); return new LogReader(getLogMetadata(), this.bookKeeper, this.config); }
/** * Creates a special DurableDataLog wrapping the BookKeeperLog that does only supports reading from the log. It does * not support initialization or otherwise modifications to the log. Accessing this log will not interfere with other * active writes to this log (i.e., it will not fence anyone out or close Ledgers that shouldn't be closed). * * @return A new DurableDataLog instance. * @throws DataLogInitializationException If an exception occurred fetching metadata from ZooKeeper. */ public DurableDataLog asReadOnly() throws DataLogInitializationException { return new ReadOnlyBooKeeperLog(this.log.loadMetadata()); }
private void writeLedger00(RevisionDataOutput output, LedgerMetadata m) throws IOException { output.writeCompactLong(m.getLedgerId()); output.writeCompactInt(m.getSequence()); output.writeByte(m.getStatus().getValue()); }
/** * Creates a new instance of the LedgerAddress class. * * @param metadata The LedgerMetadata for the ledger. * @param entryId The Entry Id inside the Ledger that this Address corresponds to. */ LedgerAddress(LedgerMetadata metadata, long entryId) { this(calculateAppendSequence(metadata.getSequence(), entryId), metadata.getLedgerId()); }
private void reportMetrics() { this.metrics.ledgerCount(getLogMetadata().getLedgers().size()); this.metrics.queueStats(this.writes.getStatistics()); }
private void write00(LogMetadata m, RevisionDataOutput output) throws IOException { output.writeBoolean(m.isEnabled()); output.writeCompactLong(m.getEpoch()); output.writeCompactLong(m.truncationAddress.getSequence()); output.writeCompactLong(m.truncationAddress.getLedgerId()); output.writeCollection(m.ledgers, this::writeLedger00); }
private void startLocalZK() throws Exception { zkService = new ZooKeeperServiceRunner(zkPort, secureZK, jksKeyFile, keyPasswordFile, jksTrustFile); zkService.initialize(); zkService.start(); }
/** * Opens a ledger for reading purposes (does not fence it). * * @param ledgerMetadata LedgerMetadata for the ledger to open. * @return A BookKeeper LedgerHandle representing the ledger. * @throws DurableDataLogException If an exception occurred. */ public LedgerHandle openLedgerNoFencing(LedgerMetadata ledgerMetadata) throws DurableDataLogException { return Ledgers.openRead(ledgerMetadata.getLedgerId(), this.bkClient, this.config); }
private LedgerMetadata readLedger00(RevisionDataInput input) throws IOException { long ledgerId = input.readCompactLong(); int seq = input.readCompactInt(); LedgerMetadata.Status empty = LedgerMetadata.Status.valueOf(input.readByte()); return new LedgerMetadata(ledgerId, seq, empty); } }
/** * Gets a value representing the BookKeeper-assigned Entry id of this address. This entry id is unique per ledger, but * is likely duplicated across ledgers (since it grows sequentially from 0 in each ledger). * * @return The result. */ long getEntryId() { return getSequence() & INT_MASK; }
/** * Open-Fences the BookKeeperLog (initializes it), then updates the Metadata for it in ZooKeeper by setting its * Enabled flag to false. * @throws DurableDataLogException If an exception occurred. */ public void disable() throws DurableDataLogException { initialize(); this.log.disable(); }
/** * Loads a fresh copy BookKeeperLog Metadata from ZooKeeper, without doing any sort of fencing or otherwise modifying * it. * * @return A new instance of the LogMetadata class, or null if no such metadata exists (most likely due to this being * the first time accessing this log). * @throws DataLogInitializationException If an Exception occurred. */ public ReadOnlyLogMetadata fetchMetadata() throws DataLogInitializationException { return this.log.loadMetadata(); }
@Override public boolean equals(Object obj) { if (obj instanceof LedgerAddress) { return this.compareTo((LedgerAddress) obj) == 0; } return false; }
@Override public QueueStats getQueueStatistics() { return this.writes.getStatistics(); }
/** * Updates the Metadata for this BookKeeperLog in ZooKeeper by setting its Enabled flag to true. * @throws DurableDataLogException If an exception occurred. */ public void enable() throws DurableDataLogException { this.log.enable(); }
/** * Creates a new instance of the LedgerAddress class. * * @param ledgerSequence The sequence of the Ledger (This is different from the Entry Sequence). * @param ledgerId The Id of the Ledger that this Address corresponds to. * @param entryId The Entry Id inside the Ledger that this Address corresponds to. */ LedgerAddress(int ledgerSequence, long ledgerId, long entryId) { this(calculateAppendSequence(ledgerSequence, entryId), ledgerId); }
@Override protected LogMetadataBuilder newBuilder() { return LogMetadata.builder(); }
@Override protected DurableDataLog createDurableDataLog(Object sharedContext) { return createDurableDataLog(); // Nothing different for shared context. }
/** * Gets a Sequence number identifying the Ledger inside the log. This is different from getSequence (which identifies * a particular write inside the entire log. It is also different from LedgerId, which is a BookKeeper assigned id. * * @return The result. */ int getLedgerSequence() { return (int) (getSequence() >>> 32); }