1996fanrui commented on code in PR #28107: URL: https://github.com/apache/flink/pull/28107#discussion_r3197767376
########## flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/RecoveredBufferStoreCoordinator.java: ########## @@ -0,0 +1,66 @@ +/* + * 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.flink.runtime.checkpoint.channel; + +import org.apache.flink.annotation.Internal; + +/** + * Cross-channel coordinator notified by per-channel {@link + * org.apache.flink.runtime.io.network.partition.consumer.RecoveredBufferStore} instances on + * lifecycle events. Centralises bookkeeping that spans multiple channels (checkpoint wait-sets, + * shared on-disk spill state). + * + * <p>The {@code onChannel*} callbacks fire from the Task thread <em>outside</em> the calling + * store's lock, so implementations may freely acquire their own synchronisation. {@link + * #getCurrentDrainHead()} fires <em>inside</em> the calling store's lock so the store can capture a + * consistent (readyBuffers, drainHead) pair atomically — implementations must therefore avoid + * blocking and must not acquire any lock participating in the store-lock cycle (a plain {@code + * volatile} read is the intended implementation). + */ +@Internal +public interface RecoveredBufferStoreCoordinator { + + /** + * Position of the next entry the drain bundle will pop from the global FIFO. Returns {@link + * EntryPosition#END} when no disk entries are pending. Must be cheap and lock-free. + */ + EntryPosition getCurrentDrainHead(); + + /** + * Invoked from {@code RecoveredBufferStore#checkpoint} after the store has snapshotted its + * ready buffers. {@code startPos} is the drain-head captured atomically with that snapshot; + * phase-2 uses it as the per-channel cutoff to split spill entries between this channel's Step + * 1 snapshot and the global checkpoint drain. + */ + void onChannelCheckpointStarted( + long checkpointId, InputChannelInfo channelInfo, EntryPosition startPos); Review Comment: Two reasons it has to be passed in rather than re-derived inside the coordinator: 1. **Atomicity.** `startPos` is the `drainHead` value captured *under the store lock, atomically with this channel's Step 1 readyBuffers snapshot*. By the time this callback fires the store lock is released and `drainHead` has typically advanced — if the coordinator just re-read it here, entries drained between Step 1 and the callback would fall past the cutoff, get skipped by phase-2, yet were never in Step 1 either → data loss. 2. **Per-channel.** Each channel snapshots at a different moment, so each `(readyBuffers, drainHead)` pair lands at a different drain position. Phase-2 splits spill entries using `startPos[channel]`; a single shared cutoff would either double-write (entries already in a later channel's Step 1) or drop (entries not yet in an earlier channel's Step 1). -- 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]
