Skip to content

Commit

Permalink
Merge pull request #128 from weibocom/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
FicoHu authored Sep 7, 2022
2 parents 4736ffd + dbcac9d commit 1da9e52
Show file tree
Hide file tree
Showing 61 changed files with 1,066 additions and 450 deletions.
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ members = [
]


[profile.release-test]
inherits = "release"

[profile.release]
#panic = "abort"
#overflow-checks = false
#debug = false
#codegen-units = 1
#lto = "fat"
#opt-level = 3
panic = "abort"
overflow-checks = false
debug = false
codegen-units = 1
lto = "fat"
opt-level = 3
strip = "symbols"

[profile.release-perf]
inherits = "release"
3 changes: 1 addition & 2 deletions agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ net = { path = "../net"}
protocol = { path = "../protocol" }
endpoint = { path = "../endpoint" }
discovery = { path = "../discovery" }
elog = { path = "../log", package = "log" }
log = { path = "../log" }
stream = { path = "../stream" }
metrics = { path = "../metrics" }
rt = { path = "../rt" }
ds = { path = "../ds" }
api = { path = "../api" }

log = "0.4.14"
backtrace = "0.3.63"

tokio = { version = "1.20.1", features = ["rt", "net", "rt-multi-thread", "time", "macros"]}
Expand Down
22 changes: 10 additions & 12 deletions agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use protocol::Result;
use std::ops::Deref;
use std::panic;

use backtrace::Backtrace;

// 默认支持
fn main() -> Result<()> {
let ctx = Context::from_os_args();
Expand All @@ -26,7 +24,7 @@ fn main() -> Result<()> {
set_panic_hook();

// 提前初始化log,避免延迟导致的异常
if let Err(e) = elog::init(ctx.log_dir(), &ctx.log_level) {
if let Err(e) = log::init(ctx.log_dir(), &ctx.log_level) {
panic!("log init failed: {:?}", e);
}

Expand Down Expand Up @@ -65,7 +63,7 @@ async fn run(ctx: Context) -> Result<()> {
let snapshot = ctx.snapshot().to_string();
let tick = ctx.tick();
let mut fix = discovery::Fixed::default();
fix.register(ctx.idc_path(), sharding::build_refresh_idc());
fix.register(ctx.idc_path(), discovery::distance::build_refresh_idc());
rt::spawn(watch_discovery(snapshot, discovery, rx, tick, fix));

log::info!("server({}) inited {:?}", context::get_short_version(), ctx);
Expand All @@ -82,7 +80,7 @@ async fn run(ctx: Context) -> Result<()> {
spawn(async move {
match service::process_one(&quard, discovery).await {
Ok(_) => log::info!("service complete:{}", quard),
Err(e) => log::warn!("service failed. {} err:{:?}", quard, e),
Err(_e) => log::warn!("service failed. {} err:{:?}", quard, _e),
}
});
}
Expand All @@ -92,31 +90,31 @@ async fn run(ctx: Context) -> Result<()> {

fn set_rlimit(no: u64) {
// set number of file
if let Err(e) = rlimit::setrlimit(rlimit::Resource::NOFILE, no, no) {
log::info!("set rlimit to {} failed:{:?}", no, e);
if let Err(_e) = rlimit::setrlimit(rlimit::Resource::NOFILE, no, no) {
log::info!("set rlimit to {} failed:{:?}", no, _e);
}
}
fn set_panic_hook() {
panic::set_hook(Box::new(|panic_info| {
let (filename, line) = panic_info
let (_filename, _line) = panic_info
.location()
.map(|loc| (loc.file(), loc.line()))
.unwrap_or(("<unknown>", 0));

let cause = panic_info
let _cause = panic_info
.payload()
.downcast_ref::<String>()
.map(String::deref);

let cause = cause.unwrap_or_else(|| {
let _cause = _cause.unwrap_or_else(|| {
panic_info
.payload()
.downcast_ref::<&str>()
.map(|s| *s)
.unwrap_or("<cause unknown>")
});

log::error!("A panic occurred at {}:{}: {}", filename, line, cause);
log::error!("panic backtrace: {:?}", Backtrace::new())
log::error!("A panic occurred at {}:{}: {}", _filename, _line, _cause);
log::error!("panic backtrace: {:?}", backtrace::Backtrace::new())
}));
}
10 changes: 5 additions & 5 deletions agent/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub(super) async fn process_one(
let path = Path::new(vec![quard.protocol(), &quard.biz()]);

// 服务注册完成,侦听端口直到成功。
while let Err(e) = _process_one(quard, &p, &top, &path).await {
log::warn!("service process failed. {}, err:{:?}", quard, e);
while let Err(_e) = _process_one(quard, &p, &top, &path).await {
log::warn!("service process failed. {}, err:{:?}", quard, _e);
tokio::time::sleep(Duration::from_secs(6)).await;
}
switcher.off();
Expand All @@ -85,8 +85,8 @@ async fn _process_one(
let client = rt::Stream::from(client);
let p = p.clone();
let metrics = StreamMetrics::new(path);
let path = format!("{:?}", path);
log::debug!("connection established:{:?}", path);
let _path = format!("{:?}", path);
log::debug!("connection established:{:?}", _path);
let ctop;
loop {
if let Some(t) = top.build() {
Expand All @@ -102,7 +102,7 @@ async fn _process_one(
match e {
protocol::Error::Quit => {} // client发送quit协议退出
protocol::Error::ReadEof => {}
e => log::debug!("{:?} disconnected. {:?}", path, e),
_e => log::debug!("{:?} disconnected. {:?}", _path, _e),
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
[dependencies]
context = { path = "../context" }
metrics = { path = "../metrics" }

log = "0.4.14"
log = { path = "../log" }
#log = "0.4.14"
tokio = { version = "1.20.1", features = ["fs"] }

trust-dns-resolver = "0.20.0"
Expand Down
4 changes: 2 additions & 2 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub async fn start_whitelist_refresh(host: String) {
whitelist.insert(ip.to_string());
}
}
Err(err) => {
log::warn!("api - parse whitelist host {} failed: {:?}", host, err);
Err(_err) => {
log::warn!("api - parse whitelist host {} failed: {:?}", host, _err);
}
}
if whitelist.len() > 0 {
Expand Down
4 changes: 2 additions & 2 deletions api/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub async fn meta_list(cip: IpAddr) -> Json<Meta> {
}

let mut meta = Meta::from_evn();
if let Err(e) = meta.load_sockfile_list().await {
log::warn!("load sockfile list failed: {:?}", e);
if let Err(_e) = meta.load_sockfile_list().await {
log::warn!("load sockfile list failed: {:?}", _e);
}
Json(meta)
}
Expand Down
3 changes: 1 addition & 2 deletions context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#log = { path = "../log" }
log = { path = "../log" }

clap = {version = "3.1.1", features = ["derive"] }
url = "2.2.2"
tokio = { version = "1.20.1", features = ["fs"] }
log = "0.4.14"
git-version = "0.3.5"
lazy_static = "1.4.0"

Expand Down
8 changes: 4 additions & 4 deletions context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ impl ListenerIter {
}
}
}
Err(e) => {
log::warn!("failed to scan '{}' err:{:?}", self.path, e);
Err(_e) => {
log::warn!("failed to scan '{}' err:{:?}", self.path, _e);
failed += 1;
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ impl ListenerIter {
Ok(name) => {
found.push(name);
}
Err(os_str) => log::warn!("{:?} is not a valid file name", os_str),
Err(_os_str) => log::warn!("{:?} is not a valid file name", _os_str),
}
}
}
Expand All @@ -263,7 +263,7 @@ impl ListenerIter {
Ok(name) => {
found.push(name);
}
Err(os_str) => log::warn!("{:?} is not a valid file name", os_str),
Err(_os_str) => log::warn!("{:?} is not a valid file name", _os_str),
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#log = { path = "../log" }
log = { path = "../log" }
ds = { path = "../ds" }
metrics = { path = "../metrics" }

log = "0.4.14"
url = "2.2.2"
async-trait = "0.1.51"
enum_dispatch = "0.3.7"
Expand All @@ -29,6 +29,7 @@ rand = "0.8.4"
futures = "0.3.16"
md5 = "0.7"
bs58 = "0.4"
trust-dns-resolver = "0.20.0"
trust-dns-resolver = "0.21.2"
once_cell = "1.8.0"
noop-waker = "0.1.0"

4 changes: 2 additions & 2 deletions discovery/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ where
Ok((cfg, sig))
}
async fn dump(&self, snapshot: &str, cfg: &str) {
if let Err(e) = self.try_dump(snapshot, cfg).await {
log::warn!("failed to dump {:?} len:{} err:{:?}", self, cfg.len(), e)
if let Err(_e) = self.try_dump(snapshot, cfg).await {
log::warn!("failed to dump {:?} len:{} err:{:?}", self, cfg.len(), _e)
}
}
async fn try_dump(&self, snapshot: &str, cfg: &str) -> Result<()> {
Expand Down
Loading

0 comments on commit 1da9e52

Please sign in to comment.