aces / cbrain

CBRAIN is a flexible Ruby on Rails framework for accessing and processing of large data on high-performance computing infrastructures.
GNU General Public License v3.0
70 stars 43 forks source link

Fixes race conditions when tracking file syncing #1326

Closed prioux closed 1 year ago

prioux commented 1 year ago

Adds logic to try twice if a sync object gets newly created and picked up by multiple clients on the same server. Twice is enough because the second time the code will receive a completion status from whatever other process did permorm the operation.

This commit should get rid forever of all exceptions that appeared as:

CbrainTransitionException: Sync status was changed before lock was acquired.

prioux commented 1 year ago

Note for reviewers: the main difference is that in 4 methods, I wrapped a bit of code inside a 2.times block, then added a check after the block:

2.times do
  (original old code indented by two more spaces)
end

if status check not expected
   raise exception
end

The code in the 2.times block is pretty much unchanged except at the end, instead of a status_transition!(blah) we have a break if status_transition(blah) (note the absence of the ! in the method name).

prioux commented 1 year ago

Consider reviewing this with spacing not significant.