/** * 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(); }
/** * 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()); }
@Override public void enable() throws DurableDataLogException { Exceptions.checkNotClosed(this.closed.get(), this); synchronized (this.lock) { Preconditions.checkState(this.writeLedger == null, "BookKeeperLog is already initialized; cannot re-enable."); assert this.logMetadata == null : "writeLedger == null but logMetadata != null"; // Load existing metadata. Inexistent metadata means the BookKeeperLog has never been accessed, and therefore // enabled by default. LogMetadata metadata = loadMetadata(); Preconditions.checkState(metadata != null && !metadata.isEnabled(), "BookKeeperLog is already enabled."); metadata = metadata.asEnabled(); persistMetadata(metadata, false); log.info("{}: Enabled (Epoch = {}, UpdateVersion = {}).", this.traceObjectId, metadata.getEpoch(), metadata.getUpdateVersion()); } }
LogMetadata oldMetadata = loadMetadata();
val currentMetadata = log.loadMetadata(); val lastLedger = currentMetadata.getLedgers().get(currentMetadata.getLedgers().size() - 1); allLedgers.add(new AbstractMap.SimpleImmutableEntry<>(lastLedger.getLedgerId(),