jiangxin369 commented on code in PR #248: URL: https://github.com/apache/flink-ml/pull/248#discussion_r1295375489
########## flink-ml-iteration/flink-ml-iteration-common/src/main/java/org/apache/flink/iteration/operator/feedback/MpscQueue.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.iteration.operator.feedback; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.runtime.io.disk.iomanager.IOManager; +import org.apache.flink.runtime.memory.MemoryAllocationException; +import org.apache.flink.runtime.memory.MemoryManager; +import org.apache.flink.runtime.util.EmptyMutableObjectIterator; +import org.apache.flink.statefun.flink.core.queue.Lock; +import org.apache.flink.statefun.flink.core.queue.Locks; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.util.MutableObjectIterator; +import org.apache.flink.util.Preconditions; + +import java.io.Closeable; +import java.io.IOException; + +/** + * Multi producers single consumer fifo queue. + * + * @param <T> The element type. + */ +@Internal +public final class MpscQueue<T> implements Closeable { + private final Lock lock = Locks.spinLock(); + + private SpillableFeedbackQueue<T> activeQueue; + private SpillableFeedbackQueue<T> standByQueue; + + private volatile boolean isClosed; Review Comment: There are some tests like `HeadOperatorTest#testSnapshotAndRestoreBeforeRoundZeroFinish` that are closing the operator without processing any events. So the `ConsumerTask` may be scheduled after the operator is closed and still allocates managed memory, which would cause errors. But in an actual Flink program, the above case would not happen. So yes, the `volatile isClosed` can be removed, and just need to make the current tests process all events before closing. -- 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]
