Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination: unknown error, exception or failure #2171

Closed
arivera-tiempodev opened this issue Aug 1, 2018 · 3 comments
Closed

Pagination: unknown error, exception or failure #2171

arivera-tiempodev opened this issue Aug 1, 2018 · 3 comments
Labels
service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@arivera-tiempodev
Copy link

I have a DynamoDB table that is generated with the following code:

const params = {
  TableName,
  AttributeDefinitions: [{
    AttributeName: 'post_id',
    AttributeType: 'S'
  }, {
    AttributeName: 'parent_post_id',
    AttributeType: 'S'
  }, {
    AttributeName: 'created_at',
    AttributeType: 'S'
  }, {
    AttributeName: 'average_rating',
    AttributeType: 'N'
  }],
  KeySchema: [{
    AttributeName: 'post_id',
    KeyType: 'HASH'
  }, {
    AttributeName: 'created_at',
    KeyType: 'RANGE'
  }],
  GlobalSecondaryIndexes: [{
    IndexName: 'parent_post_id-created_at-index',
    ProvisionedThroughput: {
      ReadCapacityUnits: 5,
      WriteCapacityUnits: 5
    },
    KeySchema: [{
      AttributeName: 'parent_post_id',
      KeyType: 'HASH'
    }, {
      AttributeName: 'created_at',
      KeyType: 'SORT'
    }],
    Projection: {
      ProjectionType: 'ALL'
    }
  }, {
    IndexName: 'parent_post_id-averge_rating-index',
    ProvisionedThroughput: {
      ReadCapacityUnits: 5,
      WriteCapacityUnits: 5
    },
    KeySchema: [{
      AttributeName: 'parent_post_id',
      KeyType: 'HASH'
    }, {
      AttributeName: 'average_rating',
      KeyType: 'SORT'
    }],
    Projection: {
      ProjectionType: 'ALL'
    }
  }],
  ProvisionedThroughput: {
    ReadCapacityUnits: 1,
    WriteCapacityUnits: 1
  }
};

Then I make queries like this:

const paramsPosts = {
  TableName: this.table,
  IndexName: 'parent_post_id-created_at-index',
  KeyConditionExpression: '#parent_post_id = :parent_post_id',
  FilterExpression: '#resource_id = :resource_id',
  ExpressionAttributeNames: {
    '#parent_post_id': 'parent_post_id',
    '#resource_id': 'resource_id',
  },
  ExpressionAttributeValues: {
    ':parent_post_id': '-',
    ':resource_id': resource_id,
  },
  Limit: limit,
  ScanIndexForward: true,
  ExclusiveStartKey: lastEvaluatedKey
};

When I send null or undefined as LastEvaluatedKey I get expected results:

{
  "resource_id": "VALID_RESOURCE_ID",
  "limit": 5
}

RESULT:

{
  "posts": {
    "items": [
      {
        "comment": "This comment 1.",
        "created_at": "2018-07-31T19:40:21.899Z"
      },
      {
        "comment": "This comment 2.",
        "created_at": "2018-07-31T19:40:26.460Z"
      },
      {
        "comment": "This comment 3.",
        "created_at": "2018-07-31T19:40:30.810Z"
      },
      {
        "comment": "This comment 4.",
        "created_at": "2018-07-31T19:40:35.057Z"
      },
      {
        "comment": "This comment 5.",
        "created_at": "2018-07-31T19:40:39.341Z"
      }
    ],
      "summary": {
      "total_count": 13
    },
    "paging": {
      "next": {
        "post_id": "660b4878-e883-41ce-af4e-c393a20aac08",
        "created_at": "2018-07-31T19:40:39.341Z",
        "parent_post_id": "-"
      },
      "prev": null
    }
  }
}

I got that object because I formatting like this:

const response = {
  items: [],
  paging: {},
  summary: {}
};

return this.query(paramsPosts)
  .then(postsData => {
    response.paging.next = postsData.LastEvaluatedKey;
    response.items = postsData.Items;
    return this.query(paramsCount);
  }).then(countData => {
    response.paging.prev = lastEvaluatedKey;
    response.summary.total_count = countData.Count;
    return response;
  });

Then, if I use posts.paging.next as ExclusiveStartKey I got the following error:

{
  "data": {
    "posts": null
  },
  "errors": [
    {
      "message": "The request processing has failed because of an unknown error, exception or failure.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "posts"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "The request processing has failed because of an unknown error, exception or failure.",
          "code": "InternalFailure",
          "time": "2018-07-31T21:16:56.008Z",
          "requestId": "10dc5a07-a18e-407b-bba3-ad57506d5fd2",
          "statusCode": 500,
          "retryable": true,
          "stacktrace": [
            "InternalFailure: The request processing has failed because of an unknown error, exception or failure.",
            "    at Request.extractError (/home/node/node_modules/aws-sdk/lib/protocol/json.js:48:27)",
            "    at Request.callListeners (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:105:20)",
            "    at Request.emit (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:77:10)",
            "    at Request.emit (/home/node/node_modules/aws-sdk/lib/request.js:683:14)",
            "    at Request.transition (/home/node/node_modules/aws-sdk/lib/request.js:22:10)",
            "    at AcceptorStateMachine.runTo (/home/node/node_modules/aws-sdk/lib/state_machine.js:14:12)",
            "    at /home/node/node_modules/aws-sdk/lib/state_machine.js:26:10",
            "    at Request.<anonymous> (/home/node/node_modules/aws-sdk/lib/request.js:38:9)",
            "    at Request.<anonymous> (/home/node/node_modules/aws-sdk/lib/request.js:685:12)",
            "    at Request.callListeners (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:115:18)"
          ]
        }
      }
    }
  ]
}

I have DynamoDB running in local inside of a Docker container with the InMemory flag set to true.

I thought that I only have to send GSI Key, that is composed by parent_post_id (partition key) and created_at (sort key) but reading in some places I found that I also have to send Table Key. If I remove post_id that is only part of Table Key I got the following error:

{
  "data": {
    "posts": null
  },
  "errors": [
    {
      "message": "Exclusive Start Key must have same size as table's key schema",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "posts"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "Exclusive Start Key must have same size as table's key schema",
          "code": "ValidationException",
          "time": "2018-07-31T21:20:11.286Z",
          "requestId": "f8961dcd-325c-4cda-8fa8-855539cae715",
          "statusCode": 400,
          "retryable": false,
          "stacktrace": [
            "ValidationException: Exclusive Start Key must have same size as table's key schema",
            "    at Request.extractError (/home/node/node_modules/aws-sdk/lib/protocol/json.js:48:27)",
            "    at Request.callListeners (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:105:20)",
            "    at Request.emit (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:77:10)",
            "    at Request.emit (/home/node/node_modules/aws-sdk/lib/request.js:683:14)",
            "    at Request.transition (/home/node/node_modules/aws-sdk/lib/request.js:22:10)",
            "    at AcceptorStateMachine.runTo (/home/node/node_modules/aws-sdk/lib/state_machine.js:14:12)",
            "    at /home/node/node_modules/aws-sdk/lib/state_machine.js:26:10",
            "    at Request.<anonymous> (/home/node/node_modules/aws-sdk/lib/request.js:38:9)",
            "    at Request.<anonymous> (/home/node/node_modules/aws-sdk/lib/request.js:685:12)",
            "    at Request.callListeners (/home/node/node_modules/aws-sdk/lib/sequential_executor.js:115:18)"
          ]
        }
      }
    }
  ]
}

And DynamoDB print this on console:

dynamo-forum | Jul 31, 2018 9:32:31 PM com.almworks.sqlite4java.Internal log
dynamo-forum | WARNING: [sqlite] SQLiteDBAccess$20@268969a1: job exception
dynamo-forum | java.lang.NullPointerException
dynamo-forum |  at com.amazonaws.services.dynamodbv2.local.shared.access.sqlite.SQLiteDBAccessUtils.translateKeyAttributeValue(SQLiteDBAccessUtils.java:194)
dynamo-forum |  at com.amazonaws.services.dynamodbv2.local.shared.access.sqlite.SQLiteDBAccess$20.doWork(SQLiteDBAccess.java:2012)
dynamo-forum |  at com.amazonaws.services.dynamodbv2.local.shared.access.sqlite.SQLiteDBAccess$20.doWork(SQLiteDBAccess.java:1787)
dynamo-forum |  at com.amazonaws.services.dynamodbv2.local.shared.access.sqlite.AmazonDynamoDBOfflineSQLiteJob.job(AmazonDynamoDBOfflineSQLiteJob.java:97)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteJob.execute(SQLiteJob.java:372)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteQueue.executeJob(SQLiteQueue.java:534)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteQueue.queueFunction(SQLiteQueue.java:667)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteQueue.runQueue(SQLiteQueue.java:623)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteQueue.access$000(SQLiteQueue.java:77)
dynamo-forum |  at com.almworks.sqlite4java.SQLiteQueue$1.run(SQLiteQueue.java:205)
dynamo-forum |  at java.lang.Thread.run(Thread.java:748)
dynamo-forum |

And this is by AWS-SDK NPM package:

service-forum | [AWS dynamodb 500 0.025s 0 retries] query({ TableName: 'forum-post',
service-forum |   IndexName: 'parent_post_id-created_at-index',
service-forum |   KeyConditionExpression: '#parent_post_id = :parent_post_id',
service-forum |   FilterExpression: '#resource_id = :resource_id',
service-forum |   ExpressionAttributeNames:
service-forum |    { '#parent_post_id': 'parent_post_id',
service-forum |      '#resource_id': 'resource_id' },
service-forum |   ExpressionAttributeValues:
service-forum |    { ':parent_post_id': { S: '-' },
service-forum |      ':resource_id': { S: 'VALID_RESOURCE_ID' } },
service-forum |   Limit: 5,
service-forum |   ScanIndexForward: true,
service-forum |   ExclusiveStartKey:
service-forum |    { post_id: { S: '660b4878-e883-41ce-af4e-c393a20aac08' },
service-forum |      created_at: { S: '2018-07-31T19:40:39.341Z' },
service-forum |      parent_post_id: { S: '-' } } 
@AllanZhengYP
Copy link
Contributor

Hi @arivera-tiempodev Thank you for reporting this issue. I can reproduce it and it seems that this issue only happens in local DynamoDB and it works fine remotely. I'm not sure if this is a known issue, I will contact the service team to verify. You can also call out at the DynamoDB forum. One thing is sure that this is not an SDK issue.

I will comment here if hear back from the service team.

@AllanZhengYP AllanZhengYP added service-api This issue is due to a problem in a service API, not the SDK implementation. investigating Issue has been looked at and needs deep dive work by OSDS. and removed investigating Issue has been looked at and needs deep dive work by OSDS. labels Aug 3, 2018
mwarger added a commit to mwarger/amplify-cli that referenced this issue Sep 16, 2019
Latest version, still running into aws/aws-sdk-js#2171
@ajredniwja
Copy link
Member

Closing the issue now since the fix is being tracked by service team in this PR.

Please reach out if you have any questions.

@lock
Copy link

lock bot commented Nov 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

3 participants