hyrax icon indicating copy to clipboard operation
hyrax copied to clipboard

Turn on optimistic locking for file sets

Open hackartisan opened this issue 3 years ago • 1 comments

Descriptive summary

Enable optimistic locking on file sets

Rationale

A lot of things tend to happen with file sets in background jobs, for example, characterization / derivatives, updates that have been moved to jobs because they may effect large numbers of file sets at once. Turning on optimistic locking helps guard against race conditions because if the object is fetched by one process, then saved by another process, then saved by the first process, the first process will fail. With file sets this failure often occurs in a background job, which is simply re-run and then succeeds with a new fetch of the object.

Related work

Optimistic locking for all resources was explored here: https://github.com/samvera/hyrax/pull/4326 Optimistic locking was enabled in figgy here: https://github.com/pulibrary/figgy/pull/2879/files

hackartisan avatar Mar 18 '22 17:03 hackartisan

Without transactions this might be a nightmare (I just did a bunch of stuff that succeeded and then FileSet didn't, now what). You might have to pick a battle here.

Proposed Success Criteria

Enable optimistic locking for FileSets via enable_optimistic_locking: https://github.com/samvera/valkyrie/wiki/Optimistic-Locking#optimistic-locking-on-valkyrie-resources

Ensure the tests pass and maybe add a small test to make sure the FileSet's locking works (you can save one resource twice without using the output of the first save e.g

output = persister.save(resource: file_set)
persister.save(resource: output)
persister.save(resource: output) # should error

)

tpendragon avatar Aug 23 '23 22:08 tpendragon