Skip to content

Commit 2fa4862

Browse files
committed
issue #75: improve cache replicas selection logic
1 node -> 1 replica 2, 3, 4 nodes -> 2 replicas 5 nodes -> 3 replicas 6, 7 nodes -> 4 replicas ... Signed-off-by: Matteo Cafasso <[email protected]>
1 parent 18251f9 commit 2fa4862

File tree

1 file changed

+7
-2
lines changed
  • lib/rabbitmq_message_deduplication

1 file changed

+7
-2
lines changed

lib/rabbitmq_message_deduplication/cache.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,15 @@ defmodule RabbitMQMessageDeduplication.Cache do
219219
end
220220

221221
# List the nodes on which to create the cache replicas.
222-
# Distributed caches are replicated on two-third of the cluster nodes.
222+
# Distributed caches are replicated on two-thirds of the cluster nodes.
223223
defp cache_replicas(_distributed = true) do
224224
nodes = [Node.self() | Node.list()]
225-
nodes |> Enum.split(round((length(nodes) * 2) / 3)) |> elem(0)
225+
226+
if length(nodes) > 2 do
227+
nodes |> Enum.split(floor((length(nodes) * 2) / 3)) |> elem(0)
228+
else
229+
nodes
230+
end
226231
end
227232

228233
# List the nodes on which to create the cache replicas.

0 commit comments

Comments
 (0)