Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

13486 fix zone shuffle 1.3.x #22

Merged
merged 1 commit into from

2 participants

@rnewson
Owner

BugzID: 13486

@kocolosk
Owner

I'm wondering if it's better to submit this PR against master instead? The bug is not an issue for us in production at the moment. Code looks good, though.

@kocolosk
Owner

Oh, you already did that in #21. Cool.

@kocolosk kocolosk merged commit fa58367 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 24, 2012
  1. Use rand_uniform to fix deterministic zone placement

    Robert Newson authored
    BugzID: 13486
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 13 deletions.
  1. +4 −13 src/mem3.erl
View
17 src/mem3.erl
@@ -201,19 +201,10 @@ nodes_in_zone(Nodes, Zone) ->
[Node || Node <- Nodes, Zone == mem3:node_info(Node, <<"zone">>)].
shuffle(List) ->
- %% Determine the log n portion then randomize the list.
- randomize(round(math:log(length(List)) + 0.5), List).
-
-randomize(1, List) ->
- randomize(List);
-randomize(T, List) ->
- lists:foldl(fun(_E, Acc) -> randomize(Acc) end,
- randomize(List), lists:seq(1, (T - 1))).
-
-randomize(List) ->
- D = lists:map(fun(A) -> {random:uniform(), A} end, List),
- {_, D1} = lists:unzip(lists:keysort(1, D)),
- D1.
+ List1 = [{crypto:rand_uniform(1, 1000), Item} || Item <- List],
+ List2 = lists:sort(List1),
+ {_, Result} = lists:unzip(List2),
+ Result.
apportion(Shares, Ways) ->
apportion(Shares, lists:duplicate(Ways, 0), Shares).
Something went wrong with that request. Please try again.