com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TracingRequestHandlerTest.java    From zipkin-aws with Apache License 2.0 6 votes vote down vote up
@Test
public void handlesAmazonServiceExceptions() {
  brave.Span braveSpan = tracing.tracer().nextSpan();
  AmazonServiceException exception = new ProvisionedThroughputExceededException("test");
  exception.setRequestId("abcd");

  DefaultRequest request = new DefaultRequest("test");
  request.addHandlerContext(new HandlerContextKey<>(brave.Span.class.getCanonicalName()), braveSpan);
  HandlerAfterAttemptContext context = HandlerAfterAttemptContext.builder()
      .withRequest(request)
      .withException(exception)
      .build();

  handler.afterAttempt(context);
  assertThat(spans).hasSize(1);
  MutableSpan reportedSpan = spans.get(0);
  assertThat(reportedSpan.traceId()).isEqualToIgnoringCase(braveSpan.context().traceIdString());
  assertThat(reportedSpan.error()).isEqualTo(exception);
  assertThat(reportedSpan.tags().get("aws.request_id")).isEqualToIgnoringCase("abcd");
}
 
Example #2
Source File: FaultInjectionRequestHandler.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeRequest(Request<?> request) {

    /* Things to do just before a request is executed */
    if (request.getOriginalRequest() instanceof PutItemRequest) {

        /* Throw throughput exceeded exception for 50% of put requests */
        if (rnd.nextInt(2) == 0) {

            logger.info("Injecting ProvisionedThroughputExceededException");
            throw new ProvisionedThroughputExceededException("Injected Error");
        }
    }

    /* Add latency to some Get requests */
    if (request.getOriginalRequest() instanceof GetItemRequest) {

        /* Delay 50% of GetItem requests by 500 ms */
        if (rnd.nextInt(2) == 0) {
            /*
             * Delay on average 50% of the requests from client perspective
             */
            try {

                logger.info("Injecting 500 ms delay");
                Thread.sleep(500);
            }
            catch (InterruptedException ie) {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}
 
Example #3
Source File: DynamoDBService.java    From Doradus with Apache License 2.0 5 votes vote down vote up
void deleteRow(String storeName, Map<String, AttributeValue> key) {
    String tableName = storeToTableName(storeName);
    m_logger.debug("Deleting row from table {}, key={}", tableName, DynamoDBService.getDDBKey(key));
    
    Timer timer = new Timer();
    boolean bSuccess = false;
    for (int attempts = 1; !bSuccess; attempts++) {
        try {
            m_ddbClient.deleteItem(tableName, key);
            if (attempts > 1) {
                m_logger.info("deleteRow() succeeded on attempt #{}", attempts);
            }
            bSuccess = true;
            m_logger.debug("Time to delete table {}, key={}: {}",
                           new Object[]{tableName, DynamoDBService.getDDBKey(key), timer.toString()});
        } catch (ProvisionedThroughputExceededException e) {
            if (attempts >= m_max_commit_attempts) {
                String errMsg = "All retries exceeded; abandoning deleteRow() for table: " + tableName;
                m_logger.error(errMsg, e);
                throw new RuntimeException(errMsg, e);
            }
            m_logger.warn("deleteRow() attempt #{} failed: {}", attempts, e);
            try {
                Thread.sleep(attempts * m_retry_wait_millis);
            } catch (InterruptedException ex2) {
                // ignore
            }
        }
    }
}
 
Example #4
Source File: DynamoDBService.java    From Doradus with Apache License 2.0 5 votes vote down vote up
void updateRow(String storeName,
               Map<String, AttributeValue> key,
               Map<String, AttributeValueUpdate> attributeUpdates) {
    String tableName = storeToTableName(storeName);
    m_logger.debug("Updating row in table {}, key={}", tableName, DynamoDBService.getDDBKey(key));
    
    Timer timer = new Timer();
    boolean bSuccess = false;
    for (int attempts = 1; !bSuccess; attempts++) {
        try {
            m_ddbClient.updateItem(tableName, key, attributeUpdates);
            if (attempts > 1) {
                m_logger.info("updateRow() succeeded on attempt #{}", attempts);
            }
            bSuccess = true;
            m_logger.debug("Time to update table {}, key={}: {}",
                           new Object[]{tableName, DynamoDBService.getDDBKey(key), timer.toString()});
        } catch (ProvisionedThroughputExceededException e) {
            if (attempts >= m_max_commit_attempts) {
                String errMsg = "All retries exceeded; abandoning updateRow() for table: " + tableName;
                m_logger.error(errMsg, e);
                throw new RuntimeException(errMsg, e);
            }
            m_logger.warn("updateRow() attempt #{} failed: {}", attempts, e);
            try {
                Thread.sleep(attempts * m_retry_wait_millis);
            } catch (InterruptedException ex2) {
                // ignore
            }
        }
    }
}
 
Example #5
Source File: DynamoDBService.java    From Doradus with Apache License 2.0 5 votes vote down vote up
private ScanResult scan(ScanRequest scanRequest) {
    m_logger.debug("Performing scan() request on table {}", scanRequest.getTableName());
    
    Timer timer = new Timer();
    boolean bSuccess = false;
    ScanResult scanResult = null;
    for (int attempts = 1; !bSuccess; attempts++) {
        try {
            scanResult = m_ddbClient.scan(scanRequest);
            if (attempts > 1) {
                m_logger.info("scan() succeeded on attempt #{}", attempts);
            }
            bSuccess = true;
            m_logger.debug("Time to scan table {}: {}", scanRequest.getTableName(), timer.toString());
        } catch (ProvisionedThroughputExceededException e) {
            if (attempts >= m_max_read_attempts) {
                String errMsg = "All retries exceeded; abandoning scan() for table: " + scanRequest.getTableName();
                m_logger.error(errMsg, e);
                throw new RuntimeException(errMsg, e);
            }
            m_logger.warn("scan() attempt #{} failed: {}", attempts, e);
            try {
                Thread.sleep(attempts * m_retry_wait_millis);
            } catch (InterruptedException ex2) {
                // ignore
            }
        }
    }
    return scanResult;
}
 
Example #6
Source File: FaultInjectionRequestHandler.java    From aws-dynamodb-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeRequest(Request<?> request)
{

    /* Things to do just before a request is executed */
    if (request.getOriginalRequest() instanceof PutItemRequest)
    {

        /* Throw throuhgput exceeded exception for 50% of put requests */
        if (rnd.nextInt(2) == 0)
        {

            logger.info("Injecting ProvisionedThroughputExceededException");
            throw new ProvisionedThroughputExceededException("Injected Error");
        }
    }

    /* Add latency to some Get requests */
    if (request.getOriginalRequest() instanceof GetItemRequest)
    {

        /* Delay 50% of GetItem requests by 500 ms */
        if (rnd.nextInt(2) == 0)
        {
            /* Delay on average 50% of the requests from client perspective */
            try
            {

                logger.info("Injecting 500 ms delay");
                Thread.sleep(500);
            }
            catch (InterruptedException ie)
            {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}
 
Example #7
Source File: DynamoDBExceptionFilter.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isMatch(Exception ex)
{
    return ex instanceof LimitExceededException
            || ex instanceof ProvisionedThroughputExceededException;
}