-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
result, err := l.dynamoDBAPI.GetItemWithContext(ctx, &getInput) | ||
|
||
if err != nil { | ||
l.logger.ErrorD("unexpected-dynamo-error", logger.M{ |
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.
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
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.
I think I was following the pattern that was established for other dynamo access - I'm not attached to this though.
and
Lines 186 to 189 in b4feadd
item, err := dynamodbattribute.MarshalMap(lock) | |
if err != nil { | |
return fmt.Errorf("failed to DynamoDB marshal Record, %v", err) | |
} |
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.
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 { |
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.
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.
b4feadd
to
7cfe9db
Compare
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