Skip to content

Commit f6bf91f

Browse files
authored
Merge pull request #19 from zhongwencool/random-shuffle
random mode shuffle hosts
2 parents fca0fe2 + 17aa296 commit f6bf91f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/eetcd_conn.erl

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ init({Name, Hosts, Options, Transport, TransportOpts}) ->
103103
connect_all(Hosts, Name, GunOpts, Data);
104104
random ->
105105
Length = erlang:length(Hosts),
106-
Data1 = Data#{endpoints => Hosts, mode => random},
106+
Data1 = Data#{endpoints => shuffle(Hosts), mode => random},
107107
Index = rand:uniform(Length),
108108
connect_one(Index, 2 * Length, Data1, Length)
109109
end.
@@ -455,3 +455,8 @@ put_in_authenticate(Data, Options) ->
455455
Auth = #{name => UserName, password => Password},
456456
Data#{authenticate => Auth}
457457
end.
458+
459+
shuffle(List) ->
460+
Disorders = [begin {rand:uniform(), K} end||K <-List],
461+
[begin K end||{_, K} <- lists:keysort(1, Disorders)].
462+

0 commit comments

Comments
 (0)