From 219bd7978483c327526f4b7bd550c054e954e61f Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 7 Mar 2020 22:41:58 -0600 Subject: [PATCH] handle upsert edge-case --- lib/cluster_kv/db.ex | 7 +++++-- lib/cluster_kv/ring.ex | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cluster_kv/db.ex b/lib/cluster_kv/db.ex index 4b96300..f7ff656 100644 --- a/lib/cluster_kv/db.ex +++ b/lib/cluster_kv/db.ex @@ -4,7 +4,7 @@ defmodule ClusterKV.DB do alias __MODULE__ - @db_options [:set, :public] + @db_options [:set] defstruct [:db, :batch, :batch_chunk, :batch_fun, last_batch: 0] @@ -103,7 +103,7 @@ defmodule ClusterKV.DB do v = case value do val when is_list(val) -> val - val -> [val] + v -> [v] end :ets.insert(db, {key, v}) @@ -111,6 +111,9 @@ defmodule ClusterKV.DB do [{_, val} = old] when is_list(val) -> new = fun.(old, value) 1 = :ets.select_replace(db, [{old, [], [{:const, new}]}]) + + [_] -> + :ets.insert(db, {key, [value]}) end end diff --git a/lib/cluster_kv/ring.ex b/lib/cluster_kv/ring.ex index 4feea00..92f7bc3 100644 --- a/lib/cluster_kv/ring.ex +++ b/lib/cluster_kv/ring.ex @@ -314,7 +314,7 @@ defmodule ClusterKV.Ring do end def send_batch(name, batches) do - Logger.info("Sending batches: #{inspect(batches)}") + Logger.debug("Sending batches: #{inspect(batches)}") Enum.each(batches, fn {node, batch} -> send({name, node}, {:handle_batch, batch}) -- 2.45.3