element() | :not_found
def get(name, key, timeout \\ :infinity) do
:poolboy.transaction(name, fn w ->
- Logger.info("GET: #{inspect(key)}")
GenServer.call(w, {:get, key}, timeout)
end)
end
end
def handle_call({:get, key}, _from, %DB{db: db} = state) do
- Logger.info("DB handling GET #{key}")
+ Logger.debug("DB handling GET #{key}")
{:reply, do_get(db, key), state}
end
last_batch :: integer(),
fun :: fun()
) :: {[element()], integer(), reference()}
- defp handle_next_batch_chunk(db, batch, chunk, last_batch, _fun) do
+ 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} = v ->
- Logger.info("Batch processing: #{inspect(v)}")
- :ets.insert_new(db, v)
- # do_upsert(db, k, v, fun)
+ |> Enum.each(fn {k, v} ->
+ do_upsert(db, k, v, fun)
end)
case last_batch + chunk do
new = fun.(old, value)
:ets.insert(db, new)
- [{_, v}] ->
- Logger.info("Exising value is not a list: #{inspect(v)} writing #{inspect(value)}")
+ [_] ->
:ets.insert(db, {key, [value]})
end
@spec do_get(db :: module(), key :: String.t()) :: element() | :not_found
defp do_get(db, key) do
- Logger.info("Lookup: #{inspect(key)}")
-
case :ets.lookup(db, key) do
[] -> :not_found
[other] -> other
@ready,
sl
) do
- Logger.info("Ready")
-
{:ok, sl, []}
end
end
def handle_info({:get_key, key, ref, node}, _, %SL{data: %Ring{name: n, db: db, node: me}} = sl) do
- Logger.info("Getting value for #{inspect(key)} with ref #{inspect(ref)}")
send({n, node}, {:reply, get_key(db, key), ref, me})
{:ok, sl, []}
end
end
def handle_info({:reply, val, ref, from}, _, %SL{data: %Ring{requests: reqs} = data} = sl) do
- Logger.info("Got #{inspect(val)} with ref #{inspect(ref)}")
{requests, actions} = maybe_reply(ref, reqs, val, from)
{:ok, %SL{sl | data: %Ring{data | requests: requests}}, actions}
end
end
def handle_info({:handle_batch, batch}, _, %SL{data: %Ring{db: db}} = sl) do
- Logger.info("Handling Batch")
DB.batch(db, batch)
{:ok, sl, []}
end
def handle_info(e, s, sl) do
- Logger.info("Unknown Info Event: #{inspect(e)} in state #{s} with data #{inspect(sl)}")
+ Logger.warn("Unknown Info Event: #{inspect(e)} in state #{s} with data #{inspect(sl)}")
{:ok, sl, []}
end