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 Optimistic Locking #286

Closed
jcoyne opened this Issue Oct 26, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@jcoyne
Contributor

jcoyne commented Oct 26, 2017

In Hyrax/ActiveFedora, we can use the Etag to do optimistic locking. Does Valkyrie have a mechanism for doing this?

See:
https://github.com/samvera/hyrax/blob/master/app/actors/hyrax/actors/optimistic_lock_validator.rb

@tpendragon

This comment has been minimized.

Collaborator

tpendragon commented Oct 26, 2017

No. I've been thinking about this lately and trying to decide what the correct mechanism for this would be. Something like AR where there's a special lock_key property which when defined will do optimistic locking?

@tpendragon tpendragon added the Groomed label Jan 24, 2018

@tpendragon tpendragon changed the title from Optimistic locking? to Add Optimistic Locking Mar 14, 2018

@tpendragon

This comment has been minimized.

Collaborator

tpendragon commented Mar 14, 2018

Proposed Success Criteria:

class Resource < Valkyrie::Resource
  attribute :title
  attribute :lock_key # Reserved attribute for when you want to enable optimistic locking
end

resource_1 = persister.save(resource: Resource.new)
resource_1.lock_key # => "unique1" # Set by the persister.
resource_1.title = ["test"]
resource_2 = persister.save(resource: resource_1)
resource_2.lock_key # => "unique2" # Set by the persister.
resource_1.title = ["test2"]
persister.save(resource: resource_1) # => Valkyrie::Persistence::StaleObjectError # Raised because resource_1.lock_key does not match the lock_key in the database (resource_2.lock_key)
@tpendragon

This comment has been minimized.

Collaborator

tpendragon commented Jul 18, 2018

Alternative API:

class Resource < Valkyrie::Resource
  optimistic_locking
  attribute :title
end

@tpendragon tpendragon added ready and removed Groomed labels Jul 18, 2018

hackmastera added a commit that referenced this issue Jul 30, 2018

Add optimistic_lock_token to valkyrie resources on query
connected to #286
connected to #453

Co-authored-by: Adam Wead <amsterdamos@gmail.com>
Co-authored-by: Michael Tribone <mtribone@psu.edu>

hackmastera added a commit that referenced this issue Jul 30, 2018

Add optimistic_lock_token to valkyrie resources on query
connected to #286
connected to #453

Co-authored-by: Adam Wead <amsterdamos@gmail.com>
Co-authored-by: Michael Tribone <mtribone@psu.edu>

@hackmastera hackmastera self-assigned this Jul 30, 2018

@hackmastera hackmastera added in progress and removed ready labels Jul 30, 2018

hackmastera added a commit that referenced this issue Jul 30, 2018

Add optimistic_lock_token to valkyrie resources on query
connected to #286
connected to #453

Co-authored-by: Adam Wead <amsterdamos@gmail.com>
Co-authored-by: Michael Tribone <mtribone@psu.edu>

hackmastera added a commit that referenced this issue Jul 30, 2018

Add optimistic_lock_token to valkyrie resources on query
connected to #286
connected to #453

Co-authored-by: Adam Wead <amsterdamos@gmail.com>
Co-authored-by: Michael Tribone <mtribone@psu.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment