1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use crate::log_specification::LogSpecification;
use crate::primary_writer::PrimaryWriter;
use std::borrow::Borrow;
use std::sync::Arc;
use std::sync::RwLock;
pub struct ReconfigurationHandle {
spec: Arc<RwLock<LogSpecification>>,
spec_stack: Vec<LogSpecification>,
primary_writer: Arc<PrimaryWriter>,
}
impl ReconfigurationHandle {
pub fn set_new_spec(&mut self, new_spec: LogSpecification) {
let mut guard = self.spec.write().unwrap();
guard.reconfigure(new_spec);
}
pub fn parse_new_spec(&mut self, spec: &str) {
let mut guard = self.spec.write().unwrap();
guard.reconfigure(LogSpecification::parse(spec).unwrap_or_else(|e| {
eprintln!("ReconfigurationHandle::parse_new_spec(): failed with {}", e);
LogSpecification::off()
}));
}
pub fn push_temp_spec(&mut self, new_spec: LogSpecification) {
let mut guard = self.spec.write().unwrap();
self.spec_stack.push(guard.clone());
guard.reconfigure(new_spec);
}
pub fn parse_and_push_temp_spec(&mut self, new_spec: &str) {
let mut guard = self.spec.write().unwrap();
let new_spec = LogSpecification::parse(new_spec).unwrap_or_else(|e| {
eprintln!(
"ReconfigurationHandle::parse_new_spec(): failed with {}, \
falling back to empty log spec",
e
);
LogSpecification::off()
});
self.spec_stack.push(guard.clone());
guard.reconfigure(new_spec);
}
pub fn pop_temp_spec(&mut self) {
let mut guard = self.spec.write().unwrap();
if let Some(new_spec) = self.spec_stack.pop() {
guard.reconfigure(new_spec);
}
}
#[doc(hidden)]
pub fn validate_logs(&self, expected: &[(&'static str, &'static str, &'static str)]) -> bool {
Borrow::<PrimaryWriter>::borrow(&self.primary_writer).validate_logs(expected)
}
}
pub(crate) fn reconfiguration_handle(
spec: Arc<RwLock<LogSpecification>>,
primary_writer: Arc<PrimaryWriter>,
) -> ReconfigurationHandle {
ReconfigurationHandle {
spec,
spec_stack: Default::default(),
primary_writer,
}
}