aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/app')
-rw-r--r--shard/lib/app/chat.ex5
-rw-r--r--shard/lib/app/directory.ex4
-rw-r--r--shard/lib/app/file.ex6
-rw-r--r--shard/lib/app/identity.ex4
-rw-r--r--shard/lib/app/pagestore.ex16
5 files changed, 31 insertions, 4 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 2795153..ff0c97d 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -131,6 +131,11 @@ defmodule SApp.Chat do
{:reply, state.manifest, state}
end
+ def handle_call(:delete_shard, _from, state) do
+ GenServer.call(state.store, :delete_store)
+ {:stop, :normal, :ok, state}
+ end
+
def handle_call({:read_history, top_bound, num}, _from, state) do
ret = MST.last(state.mst, top_bound, num)
{:reply, ret, state}
diff --git a/shard/lib/app/directory.ex b/shard/lib/app/directory.ex
index e9482f7..cbea8c3 100644
--- a/shard/lib/app/directory.ex
+++ b/shard/lib/app/directory.ex
@@ -64,6 +64,10 @@ defmodule SApp.Directory do
{:reply, state.manifest, state}
end
+ def handle_call(:delete_shard, _from, state) do
+ {:stop, :normal, :ok, state}
+ end
+
def handle_call(:get_items, _from, state) do
{:reply, SData.SignRev.get(state.items), state}
end
diff --git a/shard/lib/app/file.ex b/shard/lib/app/file.ex
index ce28beb..e2a9798 100644
--- a/shard/lib/app/file.ex
+++ b/shard/lib/app/file.ex
@@ -84,6 +84,12 @@ defmodule SApp.File do
{:reply, state.manifest, state}
end
+ def handle_call(:delete_shard, _from, state) do
+ GenServer.call(state.store, :delete_store)
+ File.rm(state.path)
+ {:stop, :normal, :ok, state}
+ end
+
def handle_call(:get_info, _from, state) do
reply = cond do
state.info != nil and GenServer.call(state.store, {:have_rec, state.info.merkle_root}) ->
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex
index 59a4b90..78abbe7 100644
--- a/shard/lib/app/identity.ex
+++ b/shard/lib/app/identity.ex
@@ -65,6 +65,10 @@ defmodule SApp.Identity do
{:reply, state.manifest, state}
end
+ def handle_call(:delete_shard, _from, state) do
+ {:stop, :normal, :ok, state}
+ end
+
def handle_call(:get_info, _from, state) do
{:reply, SData.SignRev.get(state.state), state}
end
diff --git a/shard/lib/app/pagestore.ex b/shard/lib/app/pagestore.ex
index 5165b84..3cda51d 100644
--- a/shard/lib/app/pagestore.ex
+++ b/shard/lib/app/pagestore.ex
@@ -25,7 +25,7 @@ defmodule SApp.PageStore do
@max_failures 4 # Maximum of peers that reply not_found before we abandon
defmodule State do
- defstruct [:shard_id, :path, :netgroup, :store, :reqs, :retries]
+ defstruct [:shard_id, :path, :netgroup, :store, :reqs, :retries, :store_path]
end
@@ -36,15 +36,21 @@ defmodule SApp.PageStore do
def init([shard_id, path, netgroup]) do
Shard.Manager.dispatch_to(shard_id, path, self())
- store_path = [Application.get_env(:shard, :data_path), "#{shard_id|>Base.encode16}.#{path}"] |> Path.join |> String.to_atom
- {:ok, store} = :dets.open_file store_path, [type: :set]
+ store_path = [Application.get_env(:shard, :data_path), "#{shard_id|>Base.encode16}.#{path}"] |> Path.join
+ {:ok, store} = :dets.open_file(String.to_atom(store_path), [type: :set])
Process.send_after(self(), :clean_cache, 1000)
- {:ok, %State{shard_id: shard_id, path: path, netgroup: netgroup, store: store, reqs: %{}, retries: %{}}}
+ {:ok, %State{shard_id: shard_id, path: path, netgroup: netgroup, store: store, reqs: %{}, retries: %{}, store_path: store_path}}
end
+ def handle_call(:delete_store, _from, state) do
+ :dets.close state.store
+ File.rm state.store_path
+ {:stop, :normal, :ok, state}
+ end
+
def handle_call({:get, key, prefer_ask}, from, state) do
case :dets.lookup state.store, key do
[{_, _, bin}] ->
@@ -84,9 +90,11 @@ defmodule SApp.PageStore do
case :dets.lookup state.store, hash do
[] ->
:dets.insert state.store, {hash, {:cached, System.os_time(:seconds) + @cache_ttl}, bin}
+ :dets.sync state.store
nil
[{_, why}] ->
:dets.insert state.store, {hash, why, bin}
+ :dets.sync state.store
why
[{_, _, _}] ->
nil