Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Error Code: ValidationException, AWS Error Message: Consistent reads are not supported on global secondary indexes

I started using Amazon DynamoDB and have an issue with query.

I have a table Dev_Testgame1_Mail with id as primary hash key and following three global secondary indexes,

  1. fromPlayerId (Hash Key)
  2. toPlayerId (Hash Key) + isRead (Range Key)
  3. toPlayerId (Hash Key) + endDate(Range Key)

I have above code to do the query,

**DynamoDBMail hashKObject = new DynamoDBMail();
            hashKObject.setToPlayerId(playerId);
Condition endDateRangeKeyCondition = new Condition();
            //endDateRangeKeyCondition.withComparisonOperator(ComparisonOperator.NULL).withAttributeValueList(new AttributeValue().withB(Utils.convertDateToByteBuffer(DateUtil.getUtcDateTime())));
            endDateRangeKeyCondition.withComparisonOperator(ComparisonOperator.NULL);

            DynamoDBQueryExpression<DynamoDBMail> queryExpression = new DynamoDBQueryExpression<DynamoDBMail>();
            queryExpression.withHashKeyValues(hashKObject).withRangeKeyCondition("endDate", endDateRangeKeyCondition);
            queryExpression.withIndexName("gsi_tp_enddt").withLimit(pageSize).withScanIndexForward(false);
            return dynamodbMapper.queryPage(DynamoDBMail.class, queryExpression, new DynamoDBMapperConfig(TableNameOverride.withTableNamePrefix(Utils.getDynamoDBTableNamePrefix(gameId, env))));**

And I get the following error,

com.amazonaws.AmazonServiceException: Status Code: 400, AWS Service: AmazonDynamoDBv2, AWS Request ID: GUUBV24K2O40T276R9NNN0EKB7VV4KQNSO5AEMVJF66Q9ASUAAJG, AWS Error Code: ValidationException, AWS Error Message: Consistent reads are not supported on global secondary indexes

Your help is much appreciated on this issue.

Thanks Arun

like image 432
Aj last Avatar asked Feb 06 '14 07:02

Aj last


People also ask

Why strongly consistent reads are not supported on global secondary indexes?

Since Global Secondary Indexes are effectively separate tables, which have writes replicated to them from the main table, it makes sense that they cannot support consistent reads.

Is GSI eventually consistent?

Global secondary indexes support eventually consistent reads, each of which consume one half of a read capacity unit. This means that a single global secondary index query can retrieve up to 2 × 4 KB = 8 KB per read capacity unit.

Does GSI support strongly consistent reads?

Strongly consistent reads are not supported on global secondary indexes. Strongly consistent reads use more throughput capacity than eventually consistent reads. For details, see Read/write capacity mode.

Which consistency models are supported by DynamoDB for data reads?

The eventual consistency option is the default in Amazon DynamoDB and maximizes the read throughput. However, an eventually consistent read might not always reflect the results of a recently completed write. Consistency across all copies of data is usually reached within a second.


1 Answers

Set the consistent read property of the queryExpression to false. Put this line:

queryExpression.withConsistentRead(false);

or

queryExpression.setConsistentRead(false);

before you call

return dynamodbMapper.queryPage(DynamoDBMail.class, queryExpression, new DynamoDBMapperConfig(TableNameOverride.withTableNamePrefix(Utils.getDynamoDBTableNamePrefix(gameId, env))));

As an aside, I don't think your NULL RangeKeyCondition is doing anything for you.

like image 153
rpmartz Avatar answered Oct 20 '22 15:10

rpmartz