Skip to content

Commit 7bc38c9

Browse files
jweinkambitwalker
authored andcommitted
Fix build errors, use :gb_trees.next instead of matching on opaque type.
1 parent 99e2ae7 commit 7bc38c9

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

lib/app.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule HashRing.App do
1212
start: {HashRing.Worker, :start_link, [[restart: :transient, name: HashRing.Worker]]}
1313
}
1414

15-
DynamicSupervisor.start_child(HashRing.Supervisor, spec)
15+
_ = DynamicSupervisor.start_child(HashRing.Supervisor, spec)
1616

1717
# Add any preconfigured rings
1818
Enum.each(Application.get_env(:libring, :rings, []), fn

lib/managed_ring.ex

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,36 @@ defmodule HashRing.Managed do
3030
node_type: :all | :hidden | :visible
3131
]
3232

33-
@type child_spec_options :: [
34-
:id => atom() | term(),
35-
:start => {module, function_name :: atom, args :: [term]},
36-
optional(:restart) => restart,
37-
optional(:shutdown) => shutdown,
38-
optional(:type) => type,
39-
optional(:modules) => [module] | :dynamic,
40-
optional(:significant) => boolean,
41-
:nodes => node_list,
42-
:monitor_nodes => boolean,
43-
:node_blacklist => pattern_list,
44-
:node_whitelist => pattern_list
45-
]
33+
@type child_spec_option ::
34+
{:id, atom() | term()}
35+
| {:start, {module, function_name :: atom, args :: [term]}}
36+
| {:restart, :permanent | :transient | :temporary}
37+
| {:shutdown, timeout() | :brutal_kill}
38+
| {:type, :worker | :supervisor}
39+
| {:modules, [module] | :dynamic}
40+
| {:significant, boolean}
41+
| {:nodes, node_list}
42+
| {:monitor_nodes, boolean}
43+
| {:node_blacklist, pattern_list}
44+
| {:node_whitelist, pattern_list}
45+
46+
@type child_spec_options :: [child_spec_option()]
4647

4748
@valid_ring_opts [:name, :nodes, :monitor_nodes, :node_blacklist, :node_whitelist, :node_type]
4849

49-
@spec child_spec(child_spec_options) :: Supervisor.child_spec
50+
@spec child_spec(child_spec_options) :: Supervisor.child_spec()
5051
def child_spec(opts) do
5152
opts = Keyword.put_new(opts, :name, :hash_ring_manager)
5253

53-
Keyword.merge(%{
54-
id: opts[:id] || opts[:name],
55-
type: :worker,
56-
restart: :permanent,
57-
start: {__MODULE__, :run, [opts[:name], Keyword.take(opts, @valid_ring_opts)]}
58-
}, Keyword.drop(opts, @valid_ring_opts))
54+
Map.merge(
55+
%{
56+
id: opts[:id] || opts[:name],
57+
type: :worker,
58+
restart: :permanent,
59+
start: {__MODULE__, :run, [opts[:name], Keyword.take(opts, @valid_ring_opts)]}
60+
},
61+
Map.new(Keyword.drop(opts, @valid_ring_opts))
62+
)
5963
end
6064

6165
@doc """

lib/ring.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ defmodule HashRing do
205205
def key_to_node(%__MODULE__{ring: r}, key) do
206206
hash = :erlang.phash2(key, @hash_range)
207207

208-
case :gb_trees.iterator_from(hash, r) do
209-
[{_key, node, _, _} | _] ->
208+
case :gb_trees.iterator_from(hash, r) |> :gb_trees.next() do
209+
{_key, node, _} ->
210210
node
211211

212212
_ ->
@@ -244,8 +244,8 @@ defmodule HashRing do
244244
hash = :erlang.phash2(key, @hash_range)
245245
count = min(length(nodes), count)
246246

247-
case :gb_trees.iterator_from(hash, r) do
248-
[{_key, node, _, _} | _] = iter ->
247+
case :gb_trees.iterator_from(hash, r) |> :gb_trees.next() do
248+
{_key, node, iter} ->
249249
find_nodes_from_iter(iter, count - 1, [node])
250250

251251
_ ->
@@ -262,7 +262,6 @@ defmodule HashRing do
262262
if node in results do
263263
find_nodes_from_iter(iter, count, results)
264264
else
265-
[node | results]
266265
find_nodes_from_iter(iter, count - 1, [node | results])
267266
end
268267

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule HashRing.Mixfile do
1616
docs: docs(),
1717
deps: deps(),
1818
dialyzer: [
19-
flags: ~w(-Wunmatched_returns -Werror_handling -Wrace_conditions -Wno_opaque -Wunderspecs)
19+
flags: ~w(-Wunmatched_returns -Werror_handling -Wno_opaque -Wunderspecs)
2020
],
2121
preferred_cli_env: [
2222
docs: :docs,

0 commit comments

Comments
 (0)