aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/pagestore.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/app/pagestore.ex')
-rw-r--r--shard/lib/app/pagestore.ex52
1 files changed, 46 insertions, 6 deletions
diff --git a/shard/lib/app/pagestore.ex b/shard/lib/app/pagestore.ex
index 3cda51d..0cbb10a 100644
--- a/shard/lib/app/pagestore.ex
+++ b/shard/lib/app/pagestore.ex
@@ -7,12 +7,29 @@ defmodule SApp.PageStore do
Uses an ETS table of:
- { page_id, why_have_it } -- waiting for data
- { page_id, why_have_it, data } -- once we have the data
+ { page_id, why_have_it } # waiting for data
+ { page_id, why_have_it, data } # once we have the data
- why_have_it := :root
- | {:req_by, some_other_page_id}
- | {:cached, expiry_date}
+ why_have_it := :root
+ | {:req_by, some_other_page_id}
+ | {:cached, expiry_date}
+
+ TODO: at the moment we are trying to pull all missing pages at once from our peers.
+ This can work for metadata that isn't too big but won't work with bigger objects.
+ Have a smart strategy where we limit the number of requests currently in-flight but
+ still make sure everything gets pulled in. This will also pave the way to selectively
+ pulling in pages, for instance if we have a function to give them a priority score and
+ a maximum stored page count.
+
+ A `SApp.PageStore` can be used as a `SData.PageStore` in the following way:
+
+ %SApp.PageStore{pid: store_pid}
+
+ or:
+
+ %SApp.PageStore{pid: store_pid, prefer_ask: [connection_pid, ...]}
+
+ In the second case, missing pages will be requested first to the specified peers.
"""
use GenServer
@@ -25,6 +42,9 @@ defmodule SApp.PageStore do
@max_failures 4 # Maximum of peers that reply not_found before we abandon
defmodule State do
+ @moduledoc"""
+ Internal state struct of pagestore process.
+ """
defstruct [:shard_id, :path, :netgroup, :store, :reqs, :retries, :store_path]
end
@@ -258,7 +278,7 @@ defmodule SApp.PageStore do
{:noreply, state}
end
- def ask_random_peers(state, key) do
+ defp ask_random_peers(state, key) do
SNet.Group.broadcast(state.netgroup, {state.shard_id, state.path, {:get, key}}, nmax: 3)
end
@@ -289,4 +309,24 @@ defmodule SApp.PageStore do
store ## DO SOMETHING???
end
end
+
+ # ====================
+ # PAGE STORE INTERFACE
+ # ====================
+
+ @doc"""
+ Returns `true` if the page store currently stores the specified root page
+ and all its dependencies, recursively.
+ """
+ def have_rec?(pid, root) do
+ GenServer.call(pid, {:have_rec, root})
+ end
+
+ @doc"""
+ Define the set of root pages we are interested in. This will start pulling in
+ the defined pages and all their dependencies recursively if we don't have them.
+ """
+ def set_roots(pid, roots) do
+ GenServer.cast(pid, {:set_roots, roots})
+ end
end