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

DynamoDB: Check for children more efficiently #2722

Merged
merged 2 commits into from
May 15, 2017

Conversation

seiffert
Copy link
Contributor

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. 🎉

Copy link
Contributor

@briankassouf briankassouf left a 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!

@@ -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.
Copy link
Contributor

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?

},
},
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing as above.

@jefferai
Copy link
Member

Same comment as brian -- looks good after the comment nitpicking :-)

@jefferai jefferai added this to the 0.7.3 milestone May 12, 2017
@seiffert
Copy link
Contributor Author

Sure, no problem! Done 😉

Copy link
Contributor

@briankassouf briankassouf left a 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!

@briankassouf briankassouf merged commit 199f2e3 into hashicorp:master May 15, 2017
@Bonko Bonko deleted the check_children_efficiently branch May 29, 2017 12:01
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.

4 participants