Example usage for com.amazonaws.services.dynamodbv2.model ScanResult getConsumedCapacity

List of usage examples for com.amazonaws.services.dynamodbv2.model ScanResult getConsumedCapacity

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ScanResult getConsumedCapacity.

Prototype


public ConsumedCapacity getConsumedCapacity() 

Source Link

Document

The capacity units consumed by the Scan operation.

Usage

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java

License:Open Source License

public ScanResult scan(final ScanRequest request, final int permitsToConsume) throws BackendException {
    setUserAgent(request);//ww  w. j  a  v  a  2  s . c o  m
    ScanResult result;
    timedReadThrottle(SCAN, request.getTableName(), permitsToConsume);

    final Timer.Context apiTimerContext = getTimerContext(SCAN, request.getTableName());
    try {
        result = client.scan(request);
    } catch (Exception e) {
        throw processDynamoDbApiException(e, SCAN, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    meterConsumedCapacity(SCAN, result.getConsumedCapacity());
    measureItemCount(SCAN, request.getTableName(), result.getCount());
    return result;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.iterator.ScanSegmentWorker.java

License:Open Source License

@SuppressFBWarnings(value = "IT_NO_SUCH_ELEMENT", justification = "https://github.com/awslabs/dynamodb-janusgraph-storage-backend/issues/222")
@Override/*from w ww .j  a v a 2s . co m*/
public ScanResult next() {
    final Scan backoff = new Scan(request, delegate, lastConsumedCapacity);
    ScanResult result = null;
    try {
        result = backoff.runWithBackoff(); //this will be non-null or runWithBackoff throws
    } catch (BackendException e) {
        throw new BackendRuntimeException(e);
    }

    if (result.getConsumedCapacity() != null) {
        lastConsumedCapacity = result.getConsumedCapacity().getCapacityUnits().intValue();
    }

    if (result.getLastEvaluatedKey() != null && !result.getLastEvaluatedKey().isEmpty()) {
        hasNext = true;
        request.setExclusiveStartKey(result.getLastEvaluatedKey());
    } else {
        hasNext = false;
    }

    return result;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.iterator.SequentialScanner.java

License:Open Source License

@SuppressFBWarnings(value = "IT_NO_SUCH_ELEMENT", justification = "https://github.com/awslabs/dynamodb-janusgraph-storage-backend/issues/222")
@Override//from w ww .j  a  v  a2 s. c  o m
public ScanContext next() {
    ScanResult result = null;
    final boolean interrupted = false;
    try {
        result = currentFuture.get();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ExecutionException e) {
        throw new BackendRuntimeException(dynamoDbDelegate.unwrapExecutionException(e, DynamoDbDelegate.SCAN));
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }

    // Copy the request used to get this ScanResult to create the proper ScanContext later
    final ScanRequest requestForResult = DynamoDbDelegate.copyScanRequest(this.request);

    if (result.getConsumedCapacity() != null) {
        lastConsumedCapacity = result.getConsumedCapacity().getCapacityUnits().intValue();
    }

    if (result.getLastEvaluatedKey() != null && !result.getLastEvaluatedKey().isEmpty()) {
        hasNext = true;
        request.setExclusiveStartKey(result.getLastEvaluatedKey());
        currentFuture = dynamoDbDelegate.scanAsync(request, lastConsumedCapacity);
    } else {
        hasNext = false;
    }
    return new ScanContext(requestForResult, result);
}

From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java

License:Open Source License

public ScanResult scan(ScanRequest request, int permitsToConsume) throws BackendException {
    setUserAgent(request);/* w ww.j  av a 2s .co m*/
    ScanResult result;
    timedReadThrottle(SCAN, request.getTableName(), permitsToConsume);

    final Timer.Context apiTimerContext = getTimerContext(SCAN, request.getTableName());
    try {
        result = client.scan(request);
    } catch (Exception e) {
        throw processDynamoDBAPIException(e, SCAN, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    meterConsumedCapacity(SCAN, result.getConsumedCapacity());
    measureItemCount(SCAN, request.getTableName(), result.getCount());
    return result;
}

From source file:com.rapid7.diskstorage.dynamodb.iterator.ScanSegmentWorker.java

License:Open Source License

@Override
public ScanResult next() {
    ExponentialBackoff.Scan backoff = new ExponentialBackoff.Scan(request, delegate, lastConsumedCapacity);
    ScanResult result = null;
    try {//w  w w .j a  v a2  s.com
        result = backoff.runWithBackoff(); //this will be non-null or runWithBackoff throws
    } catch (BackendException e) {
        throw new BackendRuntimeException(e);
    }

    if (result.getConsumedCapacity() != null) {
        lastConsumedCapacity = result.getConsumedCapacity().getCapacityUnits().intValue();
    }

    if (result.getLastEvaluatedKey() != null && !result.getLastEvaluatedKey().isEmpty()) {
        hasNext = true;
        request.setExclusiveStartKey(result.getLastEvaluatedKey());
    } else {
        hasNext = false;
    }

    return result;
}

From source file:com.rapid7.diskstorage.dynamodb.iterator.SequentialScanner.java

License:Open Source License

@Override
public ScanContext next() {
    ScanResult result = null;
    boolean interrupted = false;
    try {/*from www.  jav a2 s .c  om*/
        result = currentFuture.get();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ExecutionException e) {
        throw new BackendRuntimeException(dynamoDBDelegate.unwrapExecutionException(e, DynamoDBDelegate.SCAN));
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }

    // Copy the request used to get this ScanResult to create the proper ScanContext later
    final ScanRequest requestForResult = DynamoDBDelegate.copyScanRequest(this.request);

    if (result.getConsumedCapacity() != null) {
        lastConsumedCapacity = result.getConsumedCapacity().getCapacityUnits().intValue();
    }

    if (result.getLastEvaluatedKey() != null && !result.getLastEvaluatedKey().isEmpty()) {
        hasNext = true;
        request.setExclusiveStartKey(result.getLastEvaluatedKey());
        currentFuture = dynamoDBDelegate.scanAsync(request, lastConsumedCapacity);
    } else {
        hasNext = false;
    }
    return new ScanContext(requestForResult, result);
}

From source file:org.apache.hadoop.dynamodb.preader.ScanRecordReadRequest.java

License:Open Source License

@Override
protected PageResults<Map<String, AttributeValue>> fetchPage(RequestLimit lim) {
    // Read from DynamoDB
    RetryResult<ScanResult> retryResult = context.getClient().scanTable(tableName, null, segment,
            context.getSplit().getTotalSegments(), lastEvaluatedKey, lim.items, context.getReporter());

    ScanResult result = retryResult.result;
    int retries = retryResult.retries;

    double consumedCapacityUnits = 0.0;
    if (result.getConsumedCapacity() != null) {
        consumedCapacityUnits = result.getConsumedCapacity().getCapacityUnits();
    }/* www.ja  v a  2 s .c  o  m*/
    return new PageResults<>(result.getItems(), result.getLastEvaluatedKey(), consumedCapacityUnits, retries);
}

From source file:org.iternine.jeppetto.dao.dynamodb.iterable.ScanIterable.java

License:Apache License

@Override
protected Iterator<Map<String, AttributeValue>> fetchItems() {
    ScanResult currentScanResult = getDynamoDB().scan(scanRequest);
    Iterator<Map<String, AttributeValue>> iterator = currentScanResult.getItems().iterator();

    scanRequest.setExclusiveStartKey(currentScanResult.getLastEvaluatedKey()); // Prepare for next query

    if (logger.isDebugEnabled()) {
        logger.debug(/*from  w  w w  . j a  v a2 s  . c om*/
                "Scanned {} using {}.  Took {} read capacity units, retrieved {} items, more items {} available.",
                getEnhancer().getBaseClass().getSimpleName(), scanRequest,
                currentScanResult.getConsumedCapacity(), currentScanResult.getCount(),
                currentScanResult.getLastEvaluatedKey() == null ? "are not" : "are");
    }

    return iterator;
}