From 1a13285971ef728109011a93e676e26248b30242 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 26 Sep 2018 15:59:22 +0200 Subject: Fixes --- shard/lib/app/chat.ex | 10 +++++++++- shard/lib/app/pagestore.ex | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'shard/lib/app') diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex index c7df62e..52ad920 100644 --- a/shard/lib/app/chat.ex +++ b/shard/lib/app/chat.ex @@ -51,9 +51,17 @@ defmodule SApp.Chat do :ok -> Shard.Manager.dispatch_to(id, nil, self()) {:ok, page_store} = SApp.PageStore.start_link(id, :page_store) + root = Shard.Manager.load_state id + root = cond do + root == nil -> nil + GenServer.call(page_store, {:have_rec, root}) -> root + true -> + Logger.warn "Not all pages for saved root were saved, restarting from an empty state!" + nil + end mst = %MST{store: %SApp.PageStore{pid: page_store}, cmp: &msg_cmp/2, - root: Shard.Manager.load_state(id)} + root: root} GenServer.cast(self(), :init_pull) {:ok, %{channel: channel, diff --git a/shard/lib/app/pagestore.ex b/shard/lib/app/pagestore.ex index 7962084..f093ed4 100644 --- a/shard/lib/app/pagestore.ex +++ b/shard/lib/app/pagestore.ex @@ -66,6 +66,10 @@ defmodule SApp.PageStore do {:reply, hash, state} end + def handle_call({:have_rec, root}, _from, state) do + {:reply, have_rec(state, root), state} + end + defp add_request(state, key, from) do reqs_key = case state.reqs[key] do nil -> @@ -89,6 +93,16 @@ defmodule SApp.PageStore do end end + defp have_rec(state, root) do + case :dets.lookup state.store, root do + [{_, _, bin}] -> + pg = SData.term_unbin bin + pg |> SData.Page.refs |> Enum.map(&(have_rec(state, &1))) |> Enum.all? + _ -> + false + end + end + defp init_rec_pull(state, key, why, prefer_ask) do case prefer_ask do [_|_] -> -- cgit v1.2.3