diff options
author | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
commit | 1a13285971ef728109011a93e676e26248b30242 (patch) | |
tree | f03467bc07ff84961f8c3eb88497adaf36b5f009 /shard/lib/app | |
parent | 7d0009d83c9b5c747d4adb535817924762429f30 (diff) | |
download | shard-1a13285971ef728109011a93e676e26248b30242.tar.gz shard-1a13285971ef728109011a93e676e26248b30242.zip |
Fixes
Diffstat (limited to 'shard/lib/app')
-rw-r--r-- | shard/lib/app/chat.ex | 10 | ||||
-rw-r--r-- | shard/lib/app/pagestore.ex | 14 |
2 files changed, 23 insertions, 1 deletions
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 [_|_] -> |