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

Add GetCurrentLock #4

Merged
merged 1 commit into from
May 18, 2021
Merged

Add GetCurrentLock #4

merged 1 commit into from
May 18, 2021

Conversation

stevenjackson
Copy link
Contributor

Overview

GetCurrentLock will return the current lock for a key. This is meant to
help troubleshoot lock starvation. If there is no lock, nil will be
returned for both lock and error. This should not be used to "pre-check"
for a lock as AcquireLock may still fail.

Testing

2 new integration tests

@stevenjackson stevenjackson requested a review from a team as a code owner May 18, 2021 21:02
result, err := l.dynamoDBAPI.GetItemWithContext(ctx, &getInput)

if err != nil {
l.logger.ErrorD("unexpected-dynamo-error", logger.M{
Copy link

Choose a reason for hiding this comment

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

nit: do we still want to log here since we're returning the error? If we do then maybe we also want to log for the unmarshal error below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I was following the pattern that was established for other dynamo access - I'm not attached to this though.

https://github.com/Clever/dynamodb-lock-go/blob/b4feaddeb8ae4d0de9e7d57972b29f899dad6130/lock/lock.go#LL217-L225

and

item, err := dynamodbattribute.MarshalMap(lock)
if err != nil {
return fmt.Errorf("failed to DynamoDB marshal Record, %v", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think when I made this library, my intention was to log somewhat verbosely and the user can control things by the logger argument to https://github.com/Clever/dynamodb-lock-go/blob/master/lock/interface.go#L75. The way things are done in this PR is consistent with that pattern, but I'm not super attached to the pattern.

lock/lock.go Outdated
if unmarshalErr := dynamodbattribute.UnmarshalMap(result.Item, &lock); unmarshalErr != nil {
return nil, fmt.Errorf("failed to DynamoDB unmarshal Record, %v", unmarshalErr)
}
if len(result.Item) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason to prefer doing this after attempting to unmarshal? Seems like it might be a teensy bit better to do it first?

GetCurrentLock will return the current lock for a key.  This is meant to
help troubleshoot lock starvation.  If there is no lock, nil will be
returned for both lock and error. This should not be used to "pre-check"
for a lock as AcquireLock may still fail.
@stevenjackson stevenjackson merged commit ae1fda2 into master May 18, 2021
@stevenjackson stevenjackson deleted the getCurrentLock branch May 18, 2021 21:32
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.

None yet

3 participants