dawidwys commented on a change in pull request #13357: URL: https://github.com/apache/flink/pull/13357#discussion_r490907492
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/operators/sort/SorterInputGateway.java ########## @@ -0,0 +1,132 @@ +/* + * 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.operators.sort; + +import org.apache.flink.runtime.operators.sort.StageRunner.SortStage; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * A gateway for writing records into the sort/merge process. + */ +final class SorterInputGateway<E> { + /** Logging. */ + private static final Logger LOG = LoggerFactory.getLogger(SorterInputGateway.class); + private final LargeRecordHandler<E> largeRecords; + /** The object into which the thread reads the data from the input. */ + private final StageRunner.StageMessageDispatcher<E> dispatcher; + private long bytesUntilSpilling; + private CircularElement<E> currentBuffer; + + /** + * Creates a new gateway for pushing records into the sorter. + * + * @param dispatcher The queues used to pass buffers between the threads. + */ + SorterInputGateway( + StageRunner.StageMessageDispatcher<E> dispatcher, + LargeRecordHandler<E> largeRecordsHandler, + long startSpillingBytes) { + + // members + this.bytesUntilSpilling = startSpillingBytes; + this.largeRecords = largeRecordsHandler; + this.dispatcher = dispatcher; + + if (bytesUntilSpilling < 1) { + this.dispatcher.send(SortStage.SORT, CircularElement.spillingMarker()); + } + } + + /** + * Writes the given record for sorting. + */ + public void writeRecord(E record) throws IOException { + + if (currentBuffer == null) { + this.currentBuffer = this.dispatcher.take(SortStage.READ); Review comment: Good catch! Now that it is not run in a separate thread it has to be done accounted for. ---------------------------------------------------------------- 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