<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="154150" data-post-id="154150">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi,</p>
<p>Thank you for the pointers. I only have one CubDB process.<br>
I removed all Logger references, including <code>require Logger</code> calls, and the problem is still there.<br>
What is strange is that there is this error about <code>sys.beam</code>, but why the BEAM would load this file once again, since the module is loaded at the VM boot …</p>
<p>All the calls to CubDB are made by 4 processes, all using <code>get_multi</code> and <code>get_and_update_multi</code> either to load data or to write data.</p>
<p>Reading:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">CubDB.get_multi(cub, keys, :NOT_FOUND)
</code></pre>
<p>When writing we give no key:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">CubDB.get_and_update_multi(cub, [], fn %{} -&gt;
  {events, puts, delete_keys}
end)
</code></pre>
<p><strong>edit</strong></p>
<p>I have found that the error happens because I’ve set <code>auto_compact: true</code>. If I set it to false, everything works well. So maybe it is  an expected behaviour ?</p>
<p>Everything seem to work well, as I changed your code to add <code>IO.puts</code> calls and have the following logs:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    IO.puts("compaction_completed")
    send(caller, {:compaction_completed, btree, compacted_btree})
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defp can_compact?(%State{compactor: compactor}) do
    case compactor do
      nil -&gt;
        IO.puts("compaction will run")
        true

      _ -&gt;
        IO.puts("compaction is pending")
        {false, :pending_compaction}
    end
  end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">compaction is pending
compaction_completed
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction will run
compaction is pending
compaction is pending
compaction is pending
compaction_completed
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
compaction is pending
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154150" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/62">Post #61</a>
	                </div>
	            </div>
              <div id="likers-container-154150" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154150"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #61"></div>
  </section>
</div>
    <div class="postbit" id="154152" data-post-id="154152">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Very interesting find about the <code>auto_compact: true</code>, Thanks <a class="mention" href="/u/lud" rel="nofollow">@lud</a> !</p>
<p>Only one compaction operation can run at any time, so when a compaction is already running, writes do not trigger another one. The pending compaction should only create one single file (and clean up after itself), but it might be that something is going wrong here. This is already a good start for an investigation.</p>
<p>One question: if you <code>ls</code> the data directory, which files do you see? If all is fine, you should see the <code>.cub</code> file and, possibly, a <code>.compact</code> file if the previous compaction did not complete (this file will be cleaned up when the next compaction starts). If you see many <code>.compact</code> files or other strange behavior, let me know.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154152" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/63">Post #62</a>
	                </div>
	            </div>
              <div id="likers-container-154152" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154152"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #62"></div>
  </section>
</div>
    <div class="postbit" id="154153" data-post-id="154153">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I have two <code>.cub</code> files:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">test//db/Elixir.Gem.EventsTest/D27.cub
test//db/Elixir.Gem.EventsTest/D26.cub
</code></pre>
<p>I think it is normal to have two because the app crashes so maybe CubDB cannot remove the old file. I have no <code>.compact</code> files.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154153" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/64">Post #63</a>
	                </div>
	            </div>
              <div id="likers-container-154153" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154153"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #63"></div>
  </section>
</div>
    <div class="postbit" id="154154" data-post-id="154154">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Exactly as you say.</p>
<p>It looks like the compaction completed correctly, caught up with the updates occurring during the compaction, and then the VM crashed before the old file was cleaned up. That’s not a problem in itself, as <code>CubDB</code> is designed to handle this, and will clean up the old file at the next available opportunity.</p>
<p>That said, I still wonder what was causing the <code>emfile</code> or the <code>sys</code> errors. I will go through the code and see if I can find something suspect. I will also try to reproduce this. Let’s see.</p>
<p>If you happen to have a short example that reproduces this problem, please share it with me <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154154" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/65">Post #64</a>
	                </div>
	            </div>
              <div id="likers-container-154154" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154154"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #64"></div>
  </section>
</div>
    <div class="postbit" id="154166" data-post-id="154166">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Good news for you, it seems to be related with my <a href="https://hex.pm/packages/mutex" rel="nofollow">mutex</a> and not with CubDB.</p>
<p>I tried with the following code. If you remove all references to Mutex, it works perfectly, if you keep it as-is it will crash.</p>
<p>I added some tests (locally) to the mutex suite and I can have 4 processes trying to lock the same key concurrently 10K times without seeng the error.</p>
<p>I also tried to remove all <code>Logger</code> references to the mutex but my code using CubDB keeps crashing.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule CubDbCrashTest do
  use ExUnit.Case

  @db_dir "test/db/#{__MODULE__}"
  @db_name Module.concat(__MODULE__, Repo)
  @mutex Module.concat(__MODULE__, Mutex)

  setup_all do
    File.mkdir_p!(@db_dir)

    db_opts = [auto_compact: true, auto_file_sync: false]
    gen_opts = [name: @db_name]

    start_supervised(%{
      id: __MODULE__.DB,
      start: {CubDB, :start_link, [@db_dir, db_opts, gen_opts]}
    })

    start_supervised(%{
      id: @mutex,
      start: {Mutex, :start_link, [[name: @mutex]]}
    })

    :ok
  end

  defmodule Account do
    defstruct id: nil, balance: 0
  end

  defp put_account(%Account{id: id} = account) do
    CubDB.get_and_update_multi(@db_name, [], fn %{} -&gt;
      {account, [{{Account, id}, account}], []}
    end)
  end

  defp get_account(id) do
    [account] = CubDB.get_multi(@db_name, [{Account, id}], :NOT_FOUND)
    {:ok, account}
  end

  defp withdrawal(account_id, amount) do
    Mutex.under(@mutex, {Account, account_id}, fn -&gt;
      {:ok, account} = get_account(account_id)

      if account.balance &lt; amount do
        {:error, :not_enough_money}
      else
        account = Map.update!(account, :balance, &amp;(&amp;1 - amount))
        put_account(account)
        :ok
      end
    end)
  end

  defp deposit(account_id, amount) do
    Mutex.under(@mutex, {Account, account_id}, fn -&gt;
      {:ok, account} = get_account(account_id)
      account = Map.update!(account, :balance, &amp;(&amp;1 + amount))
      put_account(account)
      :ok
    end)
  end

  @account_id 1234

  test "Massive concurrency" do
    account = %Account{id: @account_id, balance: 0}
    put_account(account)

    IO.puts("Launching commands")
    iterations = 10_000
    withdrawal = exec_command_n({:withdrawal, fn -&gt; withdrawal(@account_id, 12) end}, iterations)
    deposit_1 = exec_command_n({:deposit, fn -&gt; deposit(@account_id, 4) end}, iterations)
    deposit_2 = exec_command_n({:deposit, fn -&gt; deposit(@account_id, 4) end}, iterations)
    deposit_3 = exec_command_n({:deposit, fn -&gt; deposit(@account_id, 4) end}, iterations)

    IO.puts("Awaiting commands")
    Task.await(withdrawal, :infinity)
    Task.await(deposit_1, :infinity)
    Task.await(deposit_2, :infinity)
    Task.await(deposit_3, :infinity)

    case get_account(@account_id) do
      {:ok, %Account{balance: balance}} -&gt;
        assert(balance == 0)

      other -&gt;
        raise "Unexpeced result"
    end
  end

  defp exec_command_n(command, iterations) do
    Task.async(fn -&gt;
      # Process.sleep(100)
      exec_retry_n(command, iterations)
    end)
  end

  defp exec_retry_n(command, 0),
    do: :ok

  defp exec_retry_n({name, fun} = command, iterations) when iterations &gt; 0 do
    case fun.() do
      :ok -&gt;
        # IO.puts("Command succeeded: #{name}")

        exec_retry_n(command, iterations - 1)

      {:error, reason} -&gt;
        # IO.puts("error running command #{name}\n  reason: #{inspect(reason)}")
        Process.sleep(50)
        exec_retry_n(command, iterations)
    end
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154166" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/67">Post #66</a>
	                </div>
	            </div>
              <div id="likers-container-154166" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154166"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #66"></div>
  </section>
</div>
    <div class="postbit" id="154167" data-post-id="154167">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh, that’s great news, thanks a lot <a class="mention" href="/u/lud" rel="nofollow">@lud</a> for your investigation and for reporting on the result!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154167" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/68">Post #67</a>
	                </div>
	            </div>
              <div id="likers-container-154167" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154167"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #67"></div>
  </section>
</div>
    <div class="postbit" id="154171" data-post-id="154171">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you for looking into it too.</p>
<p>I will not look further into this because at this level of concurrency, using a Mutex is not a good solution. It was just a dummy speed test.</p>
<p>Would you mind run my project juste once to see if you have the same issue ? If yes I’ll upload it to github this week.</p>
<p><strong>Edit:</strong> problem disapeared when upgrading to CubDB 0.13, even though reading the changes I cannot guess why.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154171" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/69">Post #68</a>
	                </div>
	            </div>
              <div id="likers-container-154171" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154171"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #68"></div>
  </section>
</div>
    <div class="postbit" id="154184" data-post-id="154184">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>One comment: if you want to atomically check the balance and then update it, you can use <code>get_and_update/3</code>. That way, you can avoid using the <code>Mutex</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defp withdrawal(account_id, amount) do
  get_and_update(@db_name, {Account, account_id}, fn
    nil -&gt;
      {{:error, "No account with id: #{account_id}"}, nil}

    %{ balance: balance } when balance &lt; amount -&gt;
      {{:error, :not_enough_money}, account}

    account -&gt;
      {:ok, Map.update!(account, :balance, &amp;(&amp;1 - amount))}
    end
  end)
end
</code></pre>
<p>Similarly, <code>deposit</code> can be implemented like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defp deposit(account_id, amount) do
  get_and_update(@db_name, {Account, account_id}, fn
    nil -&gt;
      {{:error, "No account with id: #{account_id}"}, nil}

    account -&gt;
      {:ok, Map.update!(account, :balance, &amp;(&amp;1 + amount))}
    end)
  end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154184" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/70">Post #69</a>
	                </div>
	            </div>
              <div id="likers-container-154184" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154184"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #69"></div>
  </section>
</div>
    <div class="postbit" id="154187" data-post-id="154187">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yep, I know !</p>
<p>The point was to have many concurrent updates, doing heavy jobs between fetching and saving.</p>
<p>I believe the fun runs inside the CubDB process and I did that in order to avoid serializing multiple updates. Am I wrong ?</p>
<p>Also I may use different repositories (ETS, CubDB, or Ecto) so the mutex is a simple way to queue updates to a common entity.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154187" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/71">Post #70</a>
	                </div>
	            </div>
              <div id="likers-container-154187" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154187"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #70"></div>
  </section>
</div>
    <div class="postbit" id="154190" data-post-id="154190">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I see now, you want to avoid blocking when another update is occurring, but on a different account.</p>
<p>If you end up with some interesting benchmark I’d be curious to see the results <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Also, your mutex solution skips the write when nothing needs to be changed (e.g. when the balance is too low). This gave me me an idea for an improvement to <code>CubDB</code>: currently there is no way to tell <code>get_and_update</code> to “bail out” and avoid updating. Such an option would be useful in this case, and in all cases when one is implementing some sort of “compare and swap” semantics.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="154190" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/72">Post #71</a>
	                </div>
	            </div>
              <div id="likers-container-154190" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="154190"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #71"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/23397/load_more?page=8">Load more posts (54 remaining)</a>
</div></template></turbo-stream>