Optimistic Locking


#1

Hi :wave:

I am wondering how one would implement optimistic locking with rom. This is provided as an extension to Sequel::Model (https://raw.githubusercontent.com/jeremyevans/sequel/master/lib/sequel/plugins/optimistic_locking.rb), as well as ActiveRecord (https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html)

Thanks :slight_smile:


#2

Additional features can be implemented as plugins in rom-sql. We’d have to look into what Sequel provides to help with the implementation. We don’t use the model part of Sequel though, so its plugin can’t be used.


#3

Do you guys have optimistic locking on your roadmap? It’s something I would consider a requirement for any situation where I may be doing concurrent writes to the same work, the performance cost is negligible and it significantly mitigates race conditions around stale data.

If no, do you have any examples of writing that sort of plugin I could look at?

Thanks :slight_smile:


#4

Do you guys have optimistic locking on your roadmap?

Yes, it’s definitely something we want to have, but it’s hard to say when somebody will get to implementing it, so help here is highly appreciated.

If no, do you have any examples of writing that sort of plugin I could look at?

A PR with a working plugin would be accepted, really. Here’s some useful info:

  • Pagination plugin - this is a pretty extensive plugin so it shows a lot of extension points (both at class and instance level)
  • Here is an example how plugins are registered, so that you can do use :your_plugin in your relation classes

I would recommend looking into Sequel API to see which Dataset methods could be useful here (if any), then implementing it in your code to see what works well, and eventually it could be extracted into a rom-sql plugin.

Let me know if you have any more questions, and sorry for being so slow with replies. Busy dry-rb times for me :wink: