-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
DynamoDB: Check for children more efficiently #2722
DynamoDB: Check for children more efficiently #2722
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two very small things, aside from that it looks great! Thanks for the contribution!
physical/dynamodb.go
Outdated
@@ -378,6 +378,39 @@ func (d *DynamoDBBackend) List(prefix string) ([]string, error) { | |||
return keys, nil | |||
} | |||
|
|||
// hasChildren returns true if there exist items below a certain path prefix. | |||
// To do so, the method fetches such items from DynamoDB. If there are more than one item (which is the "directory" | |||
// item), there are children. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick, but could you wrap comments to a width of 80?
physical/dynamodb.go
Outdated
}, | ||
}, | ||
// Avoid fetching too many items from DynamoDB for performance reasons. | ||
// We need at least two because one is the directory item, all others are children. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as above.
Same comment as brian -- looks good after the comment nitpicking :-) |
Sure, no problem! Done 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for the contribution!
When deleting items from Vault, the DynamoDB backend checks whether there are any more items in the same path and cleans it up if not. This works pretty well for nodes with only a few children. In our infrastructure however, we experience issues with the revocation of leases that reside in
auth/github/login/
.Below this node, there are so many items, that listing them consumes a lot DynamoDB read capacity units. Because leases are revoked all the time in our setup, we run into throttled DynamoDB requests (in spikes) a lot.
To work around this, we figured that there must be an easier way to count items. Sadly this is pretty hard in DynamoDB. However what we can do is only fetch 2 items (which only consumes 1 or 2 "read capacity units" in DynamoDB). If there are no children, only one item is returned for this query - the "directory" node itself. If there are two items, we know that there are children.
We tested this in our production cluster where we previously (with v0.7.2) had the throttling issues. Everything works well and we don't see any throttled requests anymore. 🎉