From c50875d1f59660ec29df03f37c532947b9954abc Mon Sep 17 00:00:00 2001 From: Attila Gulyas Date: Mon, 28 Mar 2016 21:17:15 -0700 Subject: [PATCH 1/3] Remove empty parens (supervisor-and-application) --- .../mix-otp/supervisor-and-application.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/getting-started/mix-otp/supervisor-and-application.markdown b/getting-started/mix-otp/supervisor-and-application.markdown index 57266eda8..8fdf2a9e3 100644 --- a/getting-started/mix-otp/supervisor-and-application.markdown +++ b/getting-started/mix-otp/supervisor-and-application.markdown @@ -220,7 +220,7 @@ We have now successfully defined our supervisor which is automatically started ( Remember however that our `KV.Registry` is both linking and monitoring bucket processes in the `handle_cast/2` callback: ```elixir -{:ok, pid} = KV.Bucket.start_link() +{:ok, pid} = KV.Bucket.start_link ref = Process.monitor(pid) ``` @@ -267,7 +267,7 @@ defmodule KV.Bucket.Supervisor do # A simple module attribute that stores the supervisor name @name KV.Bucket.Supervisor - def start_link() do + def start_link do Supervisor.start_link(__MODULE__, :ok, name: @name) end @@ -296,7 +296,7 @@ Run `iex -S mix` so we can give our new supervisor a try: ```iex iex> {:ok, _} = KV.Bucket.Supervisor.start_link {:ok, #PID<0.70.0>} -iex> {:ok, bucket} = KV.Bucket.Supervisor.start_bucket() +iex> {:ok, bucket} = KV.Bucket.Supervisor.start_bucket {:ok, #PID<0.72.0>} iex> KV.Bucket.put(bucket, "eggs", 3) :ok @@ -311,7 +311,7 @@ Let's change the registry to work with the buckets supervisor by rewriting how b if Map.has_key?(names, name) do {:noreply, {names, refs}} else - {:ok, pid} = KV.Bucket.Supervisor.start_bucket() + {:ok, pid} = KV.Bucket.Supervisor.start_bucket ref = Process.monitor(pid) refs = Map.put(refs, ref, name) names = Map.put(names, name, pid) From d62c30eebb6854cefccb0208da62c7ecbe1a0f89 Mon Sep 17 00:00:00 2001 From: Attila Gulyas Date: Tue, 29 Mar 2016 21:49:05 -0700 Subject: [PATCH 2/3] Fix typo --- getting-started/mix-otp/supervisor-and-application.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting-started/mix-otp/supervisor-and-application.markdown b/getting-started/mix-otp/supervisor-and-application.markdown index 8fdf2a9e3..6954cc0c5 100644 --- a/getting-started/mix-otp/supervisor-and-application.markdown +++ b/getting-started/mix-otp/supervisor-and-application.markdown @@ -343,7 +343,7 @@ This time we have added a supervisor as child, starting it with no arguments. Re Since we have added more children to the supervisor, it is also important to evaluate if the `:one_for_one` strategy is still correct. One flaw that shows up right away is the relationship between registry and buckets supervisor. If the registry dies, the buckets supervisor must die too, because once the registry dies all information linking the bucket name to the bucket process is lost. If the buckets supervisor is kept alive, it would be impossible to reach those buckets. -We should consider moving to another supervision strategy like `:one_for_all` or `:rest_for_one`. The `:one_for_all` strategy kills and restarts all children whenever one of the children die. This would suit our case but may be too harsh as there is no need to crash the registry once the bucket supervisor dies since the registry supervises every bucket and would be able to clean itself up. That's when the `:rest_for_one` strategy is handy: `:rest_for_one` will only restart the crashed process along side the rest of tree. Let's rewrite our supervision tree to use it: +We should consider moving to another supervision strategy like `:one_for_all` or `:rest_for_one`. The `:one_for_all` strategy kills and restarts all children whenever one of the children die. This would suit our case but may be too harsh as there is no need to crash the registry once the bucket supervisor dies since the registry supervises every bucket and would be able to clean itself up. That's when the `:rest_for_one` strategy is handy: `:rest_for_one` will only restart the crashed process along side the rest of the tree. Let's rewrite our supervision tree to use it: ```elixir def init(:ok) do From 8306d5dd369e50ac8573677d4ec406e8c5fd085c Mon Sep 17 00:00:00 2001 From: Attila Gulyas Date: Tue, 29 Mar 2016 22:13:07 -0700 Subject: [PATCH 3/3] Remove empty parens (ets.markdown) --- getting-started/mix-otp/ets.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getting-started/mix-otp/ets.markdown b/getting-started/mix-otp/ets.markdown index 140d2d394..f58d8f0e4 100644 --- a/getting-started/mix-otp/ets.markdown +++ b/getting-started/mix-otp/ets.markdown @@ -101,7 +101,7 @@ defmodule KV.Registry do {:ok, _pid} -> {:noreply, {names, refs}} :error -> - {:ok, pid} = KV.Bucket.Supervisor.start_bucket() + {:ok, pid} = KV.Bucket.Supervisor.start_bucket ref = Process.monitor(pid) refs = Map.put(refs, ref, name) :ets.insert(names, {name, pid}) @@ -192,7 +192,7 @@ To fix the failure we just need to make `KV.Registry.create/2` synchronous by us {:ok, pid} -> {:reply, pid, {names, refs}} :error -> - {:ok, pid} = KV.Bucket.Supervisor.start_bucket() + {:ok, pid} = KV.Bucket.Supervisor.start_bucket ref = Process.monitor(pid) refs = Map.put(refs, ref, name) :ets.insert(names, {name, pid})