aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-09-21 11:21:35 +0200
committerAlex Auvolat <alex@adnab.me>2023-09-21 11:21:35 +0200
commit3ecc17f8c5c822ac5785e8a9fef34caf1a3312a2 (patch)
tree0dcab8bb1bdf117d190f3186b74a0a1512c970c6
parent013b026d566689a20f47ced69300ebc117a77171 (diff)
downloadgarage-3ecc17f8c5c822ac5785e8a9fef34caf1a3312a2.tar.gz
garage-3ecc17f8c5c822ac5785e8a9fef34caf1a3312a2.zip
new layout: use deterministic randomness for reproducible results
-rw-r--r--src/rpc/graph_algo.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/rpc/graph_algo.rs b/src/rpc/graph_algo.rs
index 0e88efc4..d8c6c9b9 100644
--- a/src/rpc/graph_algo.rs
+++ b/src/rpc/graph_algo.rs
@@ -1,7 +1,7 @@
//! This module deals with graph algorithms.
//! It is used in layout.rs to build the partition to node assignment.
-use rand::prelude::SliceRandom;
+use rand::prelude::{SeedableRng, SliceRandom};
use std::cmp::{max, min};
use std::collections::HashMap;
use std::collections::VecDeque;
@@ -143,7 +143,11 @@ impl Graph<FlowEdge> {
/// This function shuffles the order of the edge lists. It keeps the ids of the
/// reversed edges consistent.
fn shuffle_edges(&mut self) {
- let mut rng = rand::thread_rng();
+ // We use deterministic randomness so that the layout calculation algorihtm
+ // will output the same thing every time it is run. This way, the results
+ // pre-calculated in `garage layout show` will match exactly those used
+ // in practice with `garage layout apply`
+ let mut rng = rand::rngs::StdRng::from_seed([0x12u8; 32]);
for i in 0..self.graph.len() {
self.graph[i].shuffle(&mut rng);
// We need to update the ids of the reverse edges.