|
| 1 | +use std::time::{Duration, Instant}; |
| 2 | + |
| 3 | +use timely::dataflow::operators::{Input, Probe}; |
| 4 | +use timely::dataflow::{InputHandle, ProbeHandle}; |
| 5 | +use timely::Config; |
| 6 | + |
| 7 | +use differential_dataflow::columnar::collection; |
| 8 | +use differential_dataflow::columnar::trace::{Batcher, Builder, Chunker, Spine}; |
| 9 | +use differential_dataflow::operators::arrange::arrangement::arrange_core; |
| 10 | + |
| 11 | +type Upd = (u64, (), u64, i64); |
| 12 | + |
| 13 | +/// Feed the dataflow with a single (key, val) at the provided `diffs` the |
| 14 | +/// advance the frontier to 1. |
| 15 | +/// |
| 16 | +/// Returns false if the dataflow hangs for longer than 5s. |
| 17 | +fn arrange_reaches_one(config: Config, diffs: &'static [i64]) -> bool { |
| 18 | + let guards = timely::execute(config, move |worker| { |
| 19 | + let index = worker.index(); |
| 20 | + let mut probe = ProbeHandle::new(); |
| 21 | + let mut input = <InputHandle<u64, collection::Builder<Upd>>>::new_with_builder(); |
| 22 | + |
| 23 | + worker.dataflow::<u64, _, _>(|scope| { |
| 24 | + let stream = scope.input_from(&mut input); |
| 25 | + let pact = collection::Pact { |
| 26 | + hashfunc: |k: columnar::Ref<'_, u64>| *k, |
| 27 | + }; |
| 28 | + |
| 29 | + arrange_core::< |
| 30 | + _, |
| 31 | + _, |
| 32 | + Chunker<Upd>, |
| 33 | + Batcher<u64, (), u64, i64>, |
| 34 | + Builder<u64, (), u64, i64>, |
| 35 | + Spine<u64, (), u64, i64>, |
| 36 | + >(stream, pact, "Arrange") |
| 37 | + .stream |
| 38 | + .probe_with(&mut probe); |
| 39 | + }); |
| 40 | + |
| 41 | + for &diff in diffs { |
| 42 | + input.send((index as u64, (), 0, diff)); |
| 43 | + } |
| 44 | + input.advance_to(1); |
| 45 | + input.flush(); |
| 46 | + |
| 47 | + let start = Instant::now(); |
| 48 | + while probe.less_than(&1) { |
| 49 | + worker.step(); |
| 50 | + if start.elapsed() > Duration::from_secs(5) { |
| 51 | + for id in worker.installed_dataflows() { |
| 52 | + worker.drop_dataflow(id); |
| 53 | + } |
| 54 | + return false; |
| 55 | + } |
| 56 | + } |
| 57 | + true |
| 58 | + }) |
| 59 | + .expect("timely execute"); |
| 60 | + |
| 61 | + guards.join().into_iter().all(|r| r.unwrap_or(false)) |
| 62 | +} |
| 63 | + |
| 64 | +#[test] |
| 65 | +fn columnar_exchange_net_empty_container() { |
| 66 | + // [+1, -1] diffs should consolidate to nothing, but the exchange must |
| 67 | + // still deliver a message with `records = 2`. |
| 68 | + // |
| 69 | + // Previously the exchange did not emit a message and the dataflow froze. |
| 70 | + assert!( |
| 71 | + arrange_reaches_one(Config::process(2), &[1, -1]), |
| 72 | + "frontier stalled: record count lost for an all-cancelled container" |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +#[test] |
| 77 | +fn columnar_exchange_consolidated_container() { |
| 78 | + assert!(arrange_reaches_one(Config::process(2), &[1, 1, 1])); |
| 79 | + assert!(arrange_reaches_one(Config::process(3), &[2, -1, 1])); |
| 80 | +} |
0 commit comments