zhijiangW commented on a change in pull request #8654: [FLINK-12647][network] Add feature flag to disable release of consumed blocking partitions URL: https://github.com/apache/flink/pull/8654#discussion_r293656023
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ReleaseOnConsumptionResultPartition.java ########## @@ -0,0 +1,102 @@ +/* + * 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.io.network.partition; + +import org.apache.flink.runtime.io.network.buffer.BufferPool; +import org.apache.flink.runtime.io.network.buffer.BufferPoolOwner; +import org.apache.flink.util.function.FunctionWithException; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.apache.flink.util.Preconditions.checkState; + +/** + * ResultPartition that releases itself once all subpartitions have been consumed. + */ +public class ReleaseOnConsumptionResultPartition extends ResultPartition { + + /** + * The total number of references to subpartitions of this result. The result partition can be + * safely released, iff the reference count is zero. A reference count of -1 denotes that the + * result partition has been released. + */ + private final AtomicInteger pendingReferences = new AtomicInteger(); + + ReleaseOnConsumptionResultPartition( + String owningTaskName, + ResultPartitionID partitionId, + ResultPartitionType partitionType, + ResultSubpartition[] subpartitions, + int numTargetKeyGroups, + ResultPartitionManager partitionManager, + FunctionWithException<BufferPoolOwner, BufferPool, IOException> bufferPoolFactory) { + super(owningTaskName, partitionId, partitionType, subpartitions, numTargetKeyGroups, partitionManager, bufferPoolFactory); + } + + @Override + void pin() { + while (true) { Review comment: I created [FLINK-12842](https://issues.apache.org/jira/browse/FLINK-12842) and [FLINK-12843](https://issues.apache.org/jira/browse/FLINK-12843) for the ref-counter issues which could be solved separately after this PR merged, because these issues already exist before and are not in the scope of this PR. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services