hangc0276 commented on code in PR #3197: URL: https://github.com/apache/bookkeeper/pull/3197#discussion_r859362730
########## bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/CompactionEntryLog.java: ########## @@ -0,0 +1,91 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.bookkeeper.bookie.storage; + +import io.netty.buffer.ByteBuf; +import java.io.IOException; + +/** + * An entrylog to received compacted entries. + * <p/> + * The expected lifecycle for a compaction entry log is: + * 1. Creation + * 2. Mark compacted + * 3. Make available + * 4. Cleanup + * <p/> + * Abort can happen at during any step. + */ +public interface CompactionEntryLog { + /** + * Add an entry to the log. + * @param ledgerId the ledger the entry belong to + * @param entry the payload of the entry Review Comment: It was called by `entryLogger.scanEntryLog`. ```java entryLogger.scanEntryLog(metadata.getEntryLogId(), new EntryLogScanner() { @Override public boolean accept(long ledgerId) { return metadata.containsLedger(ledgerId); } @Override public void process(long ledgerId, long offset, ByteBuf entry) throws IOException { throttler.acquire(entry.readableBytes()); synchronized (TransactionalEntryLogCompactor.this) { long lid = entry.getLong(entry.readerIndex()); long entryId = entry.getLong(entry.readerIndex() + 8); if (lid != ledgerId || entryId < -1) { LOG.warn("Scanning expected ledgerId {}, but found invalid entry " + "with ledgerId {} entryId {} at offset {}", ledgerId, lid, entryId, offset); throw new IOException("Invalid entry found @ offset " + offset); } long newOffset = compactionLog.addEntry(ledgerId, entry); offsets.add(new EntryLocation(ledgerId, entryId, newOffset)); if (LOG.isDebugEnabled()) { LOG.debug("Compact add entry : lid = {}, eid = {}, offset = {}", ledgerId, entryId, newOffset); } } } ``` It will read entries from entryLogFile, and process it. For addEntry interface implementation, it only write the entry ByteBuf into `compactionLogChannel` and won't change the refcount. The entry ByteBuf's refcount only be changed by `entryLogger.scanEntryLog`. Just the same with https://github.com/apache/bookkeeper/blob/db0acf803a87ad067806489251990df992d6a2a3/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java#L637-L654 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
