]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm/schedule: make placement shuffle deterministic
authorSage Weil <sage@newdream.net>
Thu, 22 Apr 2021 22:42:00 +0000 (18:42 -0400)
committerSage Weil <sage@newdream.net>
Thu, 3 Jun 2021 12:36:45 +0000 (07:36 -0500)
hash(str) is non-deterministic, probably because it is using the internal
object ID or something and not the string content?

In any case, explicitly hash the string content and use that instead.

Also, sort the input pre-shuffle to ensure that variations in the original
host list ordering don't screw with the result.

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit adceaa9b28278601c56a7db1c3f42eaa592ec4d1)

src/pybind/mgr/cephadm/schedule.py

index c583bfaa5268032b7e419107579845cc9e197d9c..de7f8a61e90391285795f41153d78b4c22f65660 100644 (file)
@@ -1,3 +1,4 @@
+import hashlib
 import logging
 import random
 from typing import List, Optional, Callable, TypeVar, Tuple, NamedTuple, Dict
@@ -308,7 +309,10 @@ class HostAssignment(object):
 
         # shuffle for pseudo random selection
         # gen seed off of self.spec to make shuffling deterministic
-        seed = hash(self.spec.service_name())
-        random.Random(seed).shuffle(ls)
-
+        seed = int(
+            hashlib.sha1(self.spec.service_name().encode('utf-8')).hexdigest(),
+            16
+        ) % (2 ** 32)
+        final = sorted(ls)
+        random.Random(seed).shuffle(final)
         return ls