knav_negi

knav_negi

In our application we have a code like below in Elixir:

      Multi.new()
  |> Multi.update(
    :some_operation_name,
    Entity
    |> Repo.preload(:some_entity)
    |> Ecto.Changeset.optimistic_lock(:lock_version)
    |> Ecto.Changeset.change(some_id: some_uuid)
  )
   |> Repo.transaction()

We are using MYSql database, I find this code a little bit strange because it is using optimistic_locking inside a transation,I am wondering if we might run into issues because of using optimistic_locking inside a transction (pessimistic locking).

Showing Posts 1 to 1

kip

kip

ex_cldr Core Team

A transaction essentially means “everything succeeds or nothing succeeds”, and although locking plays a part in determine the success or otherwise many other issues come into play: access control, timeouts, constraints and so on.

So here the optimistic lock may or may not succeed whether a lock of some kind is acquired or not. But if the optimistic lock fails, you want all of the multi steps to rollback, which is what the transaction will accomplish.

MySQL uses REPEATABLE_READ as the default isolation level so another transaction may have updated the optmistic lock column while the current transaction is in process. Therefore the optimistic lock will fail and the transaction would roll back.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
SyntaxSorcerer
This is the start of my Elixir learning journal/journey. I plan to share my journey in this thread and am open to all feedback, construct...
New
bartblast
This is where the projects in the Hologram Showcase get posted: apps built with Hologram and libraries made for it. New ones go up usuall...
New
karolina.curiosum
Hi everyone! This is our fourth edition. Last year, 1,000+ developers took part. The more of you who answer, the more useful the results...
New
mandar1045
I’ve been fixing race condition / crash bugs in an open source org, for a few months now and almost all of them had the same problem. The...
New
budgie
Never used it. I know it’s well-liked by some and the authors have put a lot of work into it. Aside from that, is there a community cons...
New
fredwu
Over the years I’ve tried dozens of time tracking and invoicing apps, and Harvest was the only one I liked. Primarily due to its relative...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
PJUllrich
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews