【问题标题】:AWS Error Code: ValidationException, AWS Error Message: Consistent reads are not supported on global secondary indexesAWS 错误代码:ValidationException,AWS 错误消息:全局二级索引不支持一致读取
【发布时间】:2014-02-06 07:44:25
【问题描述】:

我开始使用 Amazon DynamoDB,但遇到了查询问题。

我有一个表 Dev_Testgame1_Mail 以 id 作为主哈希键并遵循三个全局二级索引,

  1. fromPlayerId(哈希键)
  2. toPlayerId(哈希键)+ isRead(范围键)
  3. toPlayerId (Hash Key) + endDate(Range Key)

我有上面的代码来做查询,

**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))));**

我收到以下错误,

com.amazonaws.AmazonServiceException:状态代码:400,AWS 服务:AmazonDynamoDBv2,AWS 请求 ID:GUUBV24K2O40T276R9NNN0EKB7VV4KQNSO5AEMVJF66Q9ASUAAJG,AWS 错误代码:ValidationException,AWS 错误消息:全局二级索引不支持一致读取

非常感谢您在此问题上的帮助。

谢谢 阿伦

【问题讨论】:

    标签: amazon-dynamodb


    【解决方案1】:

    queryExpression 的一致读取属性设置为false。把这一行:

    queryExpression.withConsistentRead(false);
    

    queryExpression.setConsistentRead(false);
    

    打电话之前

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

    顺便说一句,我认为您的 NULL RangeKeyCondition 并没有为您做任何事情。

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2012-02-16
      • 2016-02-27
      • 2020-06-24
      • 2023-01-09
      • 2018-11-01
      相关资源
      最近更新 更多