From: Christopher Date: Sun, 8 Mar 2020 21:28:06 +0000 (-0500) Subject: more logging in DB, don't overwrite current batch with new X-Git-Url: http://git.entropealabs.com/?a=commitdiff_plain;h=9cea6c95281c90e27d83dc1b3da3c75a2d53d4eb;p=cluster_kv.git more logging in DB, don't overwrite current batch with new --- diff --git a/lib/cluster_kv/db.ex b/lib/cluster_kv/db.ex index c9a966b..e0d096b 100644 --- a/lib/cluster_kv/db.ex +++ b/lib/cluster_kv/db.ex @@ -31,7 +31,7 @@ defmodule ClusterKV.DB do GenServer.cast(name, {:upsert, key, value, fun}) end - def batch(name, batch, chunk \\ 100, fun \\ &{elem(&1, 0), &2}) do + def batch(name, batch, chunk \\ 10, fun \\ &{elem(&1, 0), &2}) do GenServer.cast(name, {:batch, batch, chunk, fun}) end @@ -54,22 +54,27 @@ defmodule ClusterKV.DB do end def handle_call({:get, key}, _from, %DB{db: db} = state) do + Logger.debug("DB handling GET #{key}") {:reply, do_get(db, key), state} end def handle_cast({:put, key, value}, %DB{db: db} = state) do + Logger.debug("DB handling PUT #{key}") :ets.insert(db, {key, [value]}) {:noreply, state} end def handle_cast({:upsert, key, value, fun}, %DB{db: db} = state) do + Logger.debug("DB handling UPSERT #{key}") do_upsert(db, key, value, fun) {:noreply, state} end - def handle_cast({:batch, batch, chunk, fun}, %DB{db: db, last_batch: lb} = state) do - {batch, lb} = handle_next_batch_chunk(db, batch, chunk, lb, fun) - {:noreply, %DB{state | batch: batch, batch_chunk: chunk, batch_fun: fun, last_batch: lb}} + def handle_cast({:batch, batch, chunk, fun}, %DB{batch: b} = state) do + Logger.debug("DB handling BATCH") + batch = b ++ batch + Process.send_after(self(), :process_batch, 0) + {:noreply, %DB{state | batch: batch, batch_chunk: chunk, batch_fun: fun}} end def handle_info( @@ -81,6 +86,8 @@ defmodule ClusterKV.DB do end defp handle_next_batch_chunk(db, batch, chunk, last_batch, fun) do + Logger.debug("processing batch of #{length(batch)} from #{last_batch} with chunk of #{chunk}") + batch |> Enum.slice(last_batch, chunk) |> Enum.each(fn {k, v} -> @@ -93,6 +100,7 @@ defmodule ClusterKV.DB do lb -> Process.send_after(self(), :process_batch, 0) + Logger.debug("Batch Processed") {batch, lb} end end