Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.disk;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.time.Deadline;
import org.apache.flink.configuration.TaskManagerOptions;
import org.apache.flink.core.memory.MemorySegment;
import org.apache.flink.core.memory.MemorySegmentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.concurrent.GuardedBy;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkState;
/**
* A fixed-size {@link MemorySegment} pool used by batch shuffle for shuffle data read (currently
* only used by sort-merge blocking shuffle).
*/
public class BatchShuffleReadBufferPool {
private static final Logger LOG = LoggerFactory.getLogger(BatchShuffleReadBufferPool.class);
/**
* Memory size in bytes can be allocated from this buffer pool for a single request (4M is for
* better sequential read).
*/
public static final int NUM_BYTES_PER_REQUEST = 4 * 1024 * 1024;
/**
* Wait for at most 2 seconds before return if there is no enough available buffers currently.
*/
private static final Duration WAITING_TIME = Duration.ofSeconds(2);
/** Total direct memory size in bytes can can be allocated and used by this buffer pool. */
private final long totalBytes;
/** The number of total buffers in this buffer pool. */
private final int numTotalBuffers;
/** Size of each buffer in bytes in this buffer pool. */
private final int bufferSize;
/** The number of buffers to be returned for a single request. */
private final int numBuffersPerRequest;
/** All requesters which need to request buffers from this pool currently. */
private final Set