
org.apache.hadoop.dynamodb.preader.AbstractReadManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of emr-dynamodb-hadoop Show documentation
Show all versions of emr-dynamodb-hadoop Show documentation
EMR DynamoDB Hadoop Connector
/**
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE.TXT" file accompanying this file. This file 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.hadoop.dynamodb.preader;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.dynamodb.DynamoDBConstants;
import org.apache.hadoop.dynamodb.util.AbstractTimeSource;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The ReadManager is responsible for deciding the required number of ReadWorkers to achieve the
* target throughput rate. It will keep track of RCUs achieved and increase or decrease the worker
* count as necessary.
*/
public abstract class AbstractReadManager {
protected static final Log log = LogFactory.getLog(AbstractReadManager.class);
// This defines the lower bound of what we try to stay within. Not the same
// as RateController.MIN_RCU_PER_REQ which defines the absolute smallest
// request we are willing to make.
private static final int MIN_RCU_PER_REQ = 2;
private static final int MIN_WORKER_COUNT = 1;
private static final int MAX_WORKER_COUNT = 30;
private static final int INITIAL_WORKER_COUNT = MIN_WORKER_COUNT;
private static final int EVALUATION_FREQ_MS = DynamoDBConstants.RATE_CONTROLLER_WINDOW_SIZE_SEC
* 1000;
protected final DynamoDBRecordReaderContext context;
protected final RateController rateController;
protected final AbstractTimeSource time;
// In the query case, there is only one read quest.
protected final Deque readRequestQueue = new ConcurrentLinkedDeque<>();
protected final AtomicInteger segmentsRemaining = new AtomicInteger(0);
protected final Queue workers = new ArrayBlockingQueue<>(MAX_WORKER_COUNT);
private final List reportedStats = new ArrayList<>();
private final Object reportStatsLock = new Object();
private final PageResultMultiplexer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy