Skip to content

Commit 452226b

Browse files
authored
Define loggers in terms of container builders (#615)
* Define loggers in terms of container builders The logging infrastructure had some old assumptions built in, such as the container type and the size of buffers. With this change, we defer to the container builder pattern to re-use the existing infrastructure. This also allows us to switch the container type to something else if we'd like to do so. Signed-off-by: Moritz Hoffmann <antiguru@gmail.com> * Make the communication log event builder public Signed-off-by: Moritz Hoffmann <antiguru@gmail.com> * Back out some changes, introduce typed logger Signed-off-by: Moritz Hoffmann <antiguru@gmail.com> * Cleanup Signed-off-by: Moritz Hoffmann <antiguru@gmail.com> --------- Signed-off-by: Moritz Hoffmann <antiguru@gmail.com>
1 parent 486c988 commit 452226b

File tree

13 files changed

+230
-123
lines changed

13 files changed

+230
-123
lines changed

communication/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ getopts = { version = "0.2.21", optional = true }
2222
byteorder = "1.5"
2323
serde = { version = "1.0", features = ["derive"] }
2424
timely_bytes = { path = "../bytes", version = "0.12" }
25+
timely_container = { path = "../container", version = "0.13.0" }
2526
timely_logging = { path = "../logging", version = "0.13" }
2627
crossbeam-channel = "0.5"

communication/src/allocator/zero_copy/initialize.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Network initialization.
22
33
use std::sync::Arc;
4-
// use crate::allocator::Process;
4+
use timely_logging::Logger;
55
use crate::allocator::process::ProcessBuilder;
6+
use crate::logging::CommunicationEventBuilder;
67
use crate::networking::create_sockets;
78
use super::tcp::{send_loop, recv_loop};
89
use super::allocator::{TcpBuilder, new_vector};
@@ -30,16 +31,15 @@ impl Drop for CommsGuard {
3031
}
3132
}
3233

33-
use crate::logging::{CommunicationSetup, CommunicationEvent};
34-
use timely_logging::Logger;
34+
use crate::logging::CommunicationSetup;
3535

3636
/// Initializes network connections
3737
pub fn initialize_networking(
3838
addresses: Vec<String>,
3939
my_index: usize,
4040
threads: usize,
4141
noisy: bool,
42-
log_sender: Arc<dyn Fn(CommunicationSetup)->Option<Logger<CommunicationEvent>>+Send+Sync>,
42+
log_sender: Arc<dyn Fn(CommunicationSetup)->Option<Logger<CommunicationEventBuilder>>+Send+Sync>,
4343
)
4444
-> ::std::io::Result<(Vec<TcpBuilder<ProcessBuilder>>, CommsGuard)>
4545
{
@@ -58,7 +58,7 @@ pub fn initialize_networking_from_sockets<S: Stream + 'static>(
5858
mut sockets: Vec<Option<S>>,
5959
my_index: usize,
6060
threads: usize,
61-
log_sender: Arc<dyn Fn(CommunicationSetup)->Option<Logger<CommunicationEvent>>+Send+Sync>,
61+
log_sender: Arc<dyn Fn(CommunicationSetup)->Option<Logger<CommunicationEventBuilder>>+Send+Sync>,
6262
)
6363
-> ::std::io::Result<(Vec<TcpBuilder<ProcessBuilder>>, CommsGuard)>
6464
{

communication/src/allocator/zero_copy/tcp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::stream::Stream;
1111

1212
use timely_logging::Logger;
1313

14-
use crate::logging::{CommunicationEvent, MessageEvent, StateEvent};
14+
use crate::logging::{CommunicationEvent, CommunicationEventBuilder, MessageEvent, StateEvent};
1515

1616
fn tcp_panic(context: &'static str, cause: io::Error) -> ! {
1717
// NOTE: some downstream crates sniff out "timely communication error:" from
@@ -35,10 +35,11 @@ pub fn recv_loop<S>(
3535
worker_offset: usize,
3636
process: usize,
3737
remote: usize,
38-
mut logger: Option<Logger<CommunicationEvent>>)
38+
logger: Option<Logger<CommunicationEventBuilder>>)
3939
where
4040
S: Stream,
4141
{
42+
let mut logger = logger.map(|logger| logger.into_typed::<CommunicationEvent>());
4243
// Log the receive thread's start.
4344
logger.as_mut().map(|l| l.log(StateEvent { send: false, process, remote, start: true }));
4445

@@ -134,9 +135,9 @@ pub fn send_loop<S: Stream>(
134135
sources: Vec<Sender<MergeQueue>>,
135136
process: usize,
136137
remote: usize,
137-
mut logger: Option<Logger<CommunicationEvent>>)
138+
logger: Option<Logger<CommunicationEventBuilder>>)
138139
{
139-
140+
let mut logger = logger.map(|logger| logger.into_typed::<CommunicationEvent>());
140141
// Log the send thread's start.
141142
logger.as_mut().map(|l| l.log(StateEvent { send: true, process, remote, start: true, }));
142143

communication/src/initialize.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
use std::thread;
44
#[cfg(feature = "getopts")]
55
use std::io::BufRead;
6-
#[cfg(feature = "getopts")]
7-
use getopts;
86
use std::sync::Arc;
9-
7+
use std::fmt::{Debug, Formatter};
108
use std::any::Any;
119

10+
#[cfg(feature = "getopts")]
11+
use getopts;
12+
use timely_logging::Logger;
13+
1214
use crate::allocator::thread::ThreadBuilder;
1315
use crate::allocator::{AllocateBuilder, Process, Generic, GenericBuilder};
1416
use crate::allocator::zero_copy::allocator_process::ProcessBuilder;
1517
use crate::allocator::zero_copy::initialize::initialize_networking;
16-
17-
use crate::logging::{CommunicationSetup, CommunicationEvent};
18-
use timely_logging::Logger;
19-
use std::fmt::{Debug, Formatter};
20-
18+
use crate::logging::{CommunicationEventBuilder, CommunicationSetup};
2119

2220
/// Possible configurations for the communication infrastructure.
2321
#[derive(Clone)]
@@ -39,7 +37,7 @@ pub enum Config {
3937
/// Verbosely report connection process
4038
report: bool,
4139
/// Closure to create a new logger for a communication thread
42-
log_fn: Arc<dyn Fn(CommunicationSetup) -> Option<Logger<CommunicationEvent>> + Send + Sync>,
40+
log_fn: Arc<dyn Fn(CommunicationSetup) -> Option<Logger<CommunicationEventBuilder>> + Send + Sync>,
4341
}
4442
}
4543

communication/src/logging.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use columnar::Columnar;
44
use serde::{Serialize, Deserialize};
5+
use timely_container::CapacityContainerBuilder;
56

67
/// Configuration information about a communication thread.
78
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize, Columnar)]
@@ -53,3 +54,6 @@ impl From<MessageEvent> for CommunicationEvent {
5354
impl From<StateEvent> for CommunicationEvent {
5455
fn from(v: StateEvent) -> CommunicationEvent { CommunicationEvent::State(v) }
5556
}
57+
58+
/// Builder for communication log events.
59+
pub type CommunicationEventBuilder = CapacityContainerBuilder<Vec<(std::time::Duration, CommunicationEvent)>>;

logging/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ homepage = "https://github.com/TimelyDataflow/timely-dataflow"
1010
repository = "https://github.com/TimelyDataflow/timely-dataflow.git"
1111
keywords = ["timely", "dataflow", "logging"]
1212
license = "MIT"
13+
14+
[dependencies]
15+
timely_container = { version = "0.13.0", path = "../container" }

0 commit comments

Comments
 (0)