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
pub use self::imp::wait_for_signal;
#[cfg(unix)]
mod imp {
use engine_rocks::RocksEngine;
use engine_traits::{Engines, MiscExt, RaftEngine};
use libc::c_int;
use nix::sys::signal::{SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2};
use signal::trap::Trap;
use tikv_util::metrics;
#[allow(dead_code)]
pub fn wait_for_signal<ER: RaftEngine>(engines: Option<Engines<RocksEngine, ER>>) {
let trap = Trap::trap(&[SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2]);
for sig in trap {
match sig {
SIGTERM | SIGINT | SIGHUP => {
info!("receive signal {}, stopping server...", sig as c_int);
break;
}
SIGUSR1 => {
info!("{}", metrics::dump());
if let Some(ref engines) = engines {
info!("{:?}", MiscExt::dump_stats(&engines.kv));
info!("{:?}", RaftEngine::dump_stats(&engines.raft));
}
}
_ => unreachable!(),
}
}
}
}
#[cfg(not(unix))]
mod imp {
use engine_rocks::RocksEngine;
use engine_traits::Engines;
pub fn wait_for_signal(_: Option<Engines<RocksEngine, RocksEngine>>) {}
}