Skip to content

Commit dc678fa

Browse files
dcadenasjosevalim
authored andcommitted
Change KV.Bucket to KV.Registry (elixir-lang#1044)
1 parent 0689d42 commit dc678fa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

getting-started/mix-otp/dynamic-supervisor.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ One flaw that shows up right away is the ordering issue. Since `KV.Registry` inv
154154

155155
The second flaw is related to the supervision strategy. If `KV.Registry` dies, all information linking `KV.Bucket` names to bucket processes is lost. Therefore the `KV.BucketSupervisor` and all children must terminate too - otherwise we will have orphan processes.
156156

157-
In light of this observation, we should consider moving to another supervision strategy. The two other candidates are `:one_for_all` and `:rest_for_one`. A supervisor using the `:rest_for_one` will kill and restart child processes which were started *after* the crashed child. In this case, we would want `KV.BucketSupervisor` to terminate if `KV.Bucket` terminates. This would require the bucket supervisor to be placed after the registry. Which violates the ordering constraints we have established two paragraphs above.
157+
In light of this observation, we should consider moving to another supervision strategy. The two other candidates are `:one_for_all` and `:rest_for_one`. A supervisor using the `:rest_for_one` will kill and restart child processes which were started *after* the crashed child. In this case, we would want `KV.BucketSupervisor` to terminate if `KV.Registry` terminates. This would require the bucket supervisor to be placed after the registry. Which violates the ordering constraints we have established two paragraphs above.
158158

159159
So our last option is to go all in and pick the `:one_for_all` strategy: the supervisor will kill and restart all of its children processes whenever any one of them dies. This is a completely reasonable approach for our application, since the registry can't work without the bucket supervisor, and the bucket supervisor should terminate without the registry. Let's reimplement `init/1` in `KV.Supervisor` to encode those properties:
160160

0 commit comments

Comments
 (0)