]> Entropealabs - cluster_kv.git/commitdiff
handle upsert edge-case
authorChristopher <chris@entropealabs.com>
Sun, 8 Mar 2020 04:41:58 +0000 (22:41 -0600)
committerChristopher <chris@entropealabs.com>
Sun, 8 Mar 2020 04:41:58 +0000 (22:41 -0600)
lib/cluster_kv/db.ex
lib/cluster_kv/ring.ex

index 4b963008e129fff76f8084609a6f1cb5b6008dc5..f7ff6560866c4f232cd08e7446701250fe753c77 100644 (file)
@@ -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
 
index 4feea0022d043b45a876c0d8af26d0a99a380665..92f7bc3fa17d0bdef3618e743b62847289396e18 100644 (file)
@@ -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})