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,
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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With