Skip to content

Commit 743b8af

Browse files
committed
Fix cross-worker indeterminsm in GraphQl v2
1 parent 89de567 commit 743b8af

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/domain/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ where
124124
InputSemantics::CardinalityMany => pairs.as_collection().distinct(),
125125
};
126126

127+
// @TODO should only create this if used later
127128
let tuples_reverse = tuples.map(|(e, v)| (v, e));
128129

129130
// Propose traces are used in general, whereas the other

src/plan/graphql_v2.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,26 @@ impl GraphQl {
279279

280280
let dummy = VariableMap::new();
281281

282-
let mut paths = self
283-
.paths
284-
.iter()
285-
.flat_map(|path| {
286-
let (streams, shutdown) = path.implement(nested, &dummy, context);
287-
std::mem::forget(shutdown);
288-
streams
289-
})
290-
.collect::<HashMap<PathId, _>>();
291-
292-
let streams = paths.drain().map(|(path_id, stream)| {
282+
let mut paths = {
283+
let mut paths_map = self
284+
.paths
285+
.iter()
286+
.flat_map(|path| {
287+
let (streams, shutdown) = path.implement(nested, &dummy, context);
288+
std::mem::forget(shutdown);
289+
streams
290+
})
291+
.collect::<HashMap<PathId, _>>();
292+
293+
let mut paths = paths_map.drain().collect::<Vec<(PathId, _)>>();
294+
295+
// Important for cross-worker determinism.
296+
paths.sort_by_key(|(path_id, _)| path_id.clone());
297+
298+
paths
299+
};
300+
301+
let streams = paths.drain(..).map(|(path_id, stream)| {
293302
let states = states.clone();
294303
let mut buffer = HashMap::new();
295304
let mut vector = Vec::new();
@@ -464,7 +473,7 @@ fn pointer_mut<'a>(v: &'a mut JValue, tokens: &[String]) -> &'a mut JValue {
464473
// JValue::Array(ref mut list) => {
465474
// parse_index(&token).and_then(move |x| list.get_mut(x))
466475
// }
467-
_ => panic!("!!!"),
476+
_ => panic!("failed to acquire pointer to {:?}", tokens),
468477
};
469478
}
470479

0 commit comments

Comments
 (0)