-
Notifications
You must be signed in to change notification settings - Fork 2
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 concurrency headers #79
Conversation
…n, DeleteObject and DeleteRelation.
Pull Request Test Coverage Report for Build 7625492122
💛 - Coveralls |
pkg/directory/v3/writer.go
Outdated
@@ -46,6 +48,12 @@ func (s *Writer) SetObject(ctx context.Context, req *dsw3.SetObjectRequest) (*ds | |||
return err | |||
} | |||
|
|||
ifMatchHeader := metautils.ExtractIncoming(ctx).Get(headers.IfMatch) | |||
// if the updReq.Etag == "" this means the this is an insert | |||
if ifMatchHeader != "" && updReq.Etag != "" && ifMatchHeader != updReq.Etag { |
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.
The condition detects inserts because otherwise those would always be rejected with a HashMissmatch error.
pkg/directory/v3/writer.go
Outdated
obj := &dsc3.Object{Type: req.ObjectType, Id: req.ObjectId} | ||
updReq, err := bdb.UpdateMetadata(ctx, tx, bdb.ObjectsPath, ds.Object(obj).Key(), obj) |
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.
We do a DB call only if If-Match
header is specified.
Add
IfMatch
header check to SetObject, SetRelation, DeleteObject, DeleteRelation, and DeleteManifest.Add
IfNotmatch
header check to GetObject and GetRelatioThe headers are used for optimist concurrency.
In the case of
IfMatch
HTTP 412 - Precondition Failed is returned if the IfMatch header value does not match the etagIn the case of
IfNotMatch
HTTP 304-Not Modified is returned if the IfNotMatch header values do match the etagresolves https://github.com/aserto-dev/workspace/issues/527