@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()); } }
@Override public void disable() throws DurableDataLogException { // Get the current metadata, disable it, and then persist it back. synchronized (this.lock) { ensurePreconditions(); LogMetadata metadata = getLogMetadata(); Preconditions.checkState(metadata.isEnabled(), "BookKeeperLog is already disabled."); metadata = this.logMetadata.asDisabled(); persistMetadata(metadata, false); this.logMetadata = metadata; log.info("{}: Disabled (Epoch = {}, UpdateVersion = {}).", this.traceObjectId, metadata.getEpoch(), metadata.getUpdateVersion()); } // Close this instance of the BookKeeperLog. This ensures the proper cancellation of any ongoing writes. close(); }
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); }
if (!oldMetadata.isEnabled()) { throw new DataLogDisabledException("BookKeeperLog is disabled. Cannot initialize.");