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

Update reduceCapacity to support new data shape #157

Merged
merged 4 commits into from
Oct 25, 2022

Conversation

AlexanderBelokon
Copy link
Contributor

When using batch operations the stats are not returned correctly.

For example, this request:

batchWriteAll({
  RequestItems: { ... },
  ReturnConsumedCapacity: 'INDEXES',
  ReturnItemCollectionMetrics: 'SIZE'
})

causes AWS to return the following data structure:

{
  ConsumedCapacity: [{
    TableName: 'table',
    CapacityUnits: 8,
    Table: { CapacityUnits: 4 },
    GlobalSecondaryIndexes: { index: { CapacityUnits: 4 } }
  }]
}

which is then transformed by reduceCapacity inside sendAll to this:

{
  ConsumedCapacity: {
    TableName: undefined
  }
}

This PR fixes that problem.

@AlexanderBelokon
Copy link
Contributor Author

AlexanderBelokon commented Sep 8, 2022

Noticed that there were a few more fields missing from the current doc:

Items: Array<Map<Map>>
    Count: Integer
    ScannedCount: Integer
    LastEvaluatedKey: Map<Map>
    ConsumedCapacity: Map
        TableName: String
        CapacityUnits: Float
        ReadCapacityUnits: Float
        WriteCapacityUnits: Float
        Table: map
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float
        LocalSecondaryIndexes: Map<Map>
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float
        GlobalSecondaryIndexes: Map<Map>
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float

lib/util.js Show resolved Hide resolved
{ CapacityUnits: existing.LocalSecondaryIndexes.CapacityUnits + incoming.LocalSecondaryIndexes.CapacityUnits } :
{ CapacityUnits: incoming.LocalSecondaryIndexes.CapacityUnits };
function mergeCapacityParents(dst, src, k) {
if (!src[k]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check if src or dst is null in case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src can't be null here because we're not calling this function if it is (on L55) (TypeScript would be helpful in enforcing that, but we don't have it here), and we init dst on L46-47.

There's a test case already that checks this code path: [reduceCapacity] parses new data format correctly, there dst is built up from nothing.

But you're right that this is not obvious at all without compiler's help and someone in the future might break that accidentally. The tests would show it, though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, I would like to add null/undefined checking before accessing its properties to avoid unexpected exception thrown, especially this is an utils function, try to make it more common and robust.

lib/util.js Show resolved Hide resolved
Copy link

@davidweimapbox davidweimapbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@AlexanderBelokon AlexanderBelokon self-assigned this Oct 7, 2022
@AlexanderBelokon AlexanderBelokon merged commit bf58dd5 into master Oct 25, 2022
@AlexanderBelokon AlexanderBelokon deleted the fix-batch-stats branch October 25, 2022 21:11
@AlexanderBelokon AlexanderBelokon mentioned this pull request Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants