Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #403 and #404 to release-8.5 #405

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions proxy_components/proxy_server/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,15 @@ impl<ER: RaftEngine, F: KvFormat> TiKvServer<ER, F> {

// NOTE: Compat disagg arch upgraded from * to 8.0.
{
let raft_engine_path = config.raft_engine.config().dir + "/ps_engine";
let engine_dir = config.raft_engine.config().dir.clone();
let infered_dir = config
.infer_raft_engine_path(None)
.unwrap_or(engine_dir.clone());
info!("raft_engine_dir"; "origin" => engine_dir, "infered" => infered_dir.clone());
let raft_engine_path = infered_dir.clone() + "/ps_engine";
let path = Path::new(&raft_engine_path);
if path.exists() {
let new_raft_engine_path = config.raft_engine.config().dir + "/ps_engine.raftlog";
let new_raft_engine_path = infered_dir + "/ps_engine.raftlog";
let new_path = Path::new(&new_raft_engine_path);
if !new_path.exists() {
info!("creating ps_engine.raftlog for upgraded cluster");
Expand Down
30 changes: 4 additions & 26 deletions proxy_components/proxy_server/src/status_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use openssl::{
};
use pin_project::pin_project;
use profile::{
activate_heap_profile, deactivate_heap_profile, jeprof_heap_profile, list_heap_profiles,
read_file, start_one_cpu_profile, start_one_heap_profile,
activate_heap_profile, deactivate_heap_profile, dump_one_heap_profile, list_heap_profiles,
start_one_cpu_profile,
};
use raftstore::store::{transport::CasualRouter, CasualMessage};
use regex::Regex;
Expand Down Expand Up @@ -259,29 +259,7 @@ where
}
.to_string();

let result = if let Some(name) = query_pairs.get("name") {
if use_jeprof {
jeprof_heap_profile(name, output_format)
} else {
read_file(name)
}
} else {
let mut seconds = 10;
if let Some(s) = query_pairs.get("seconds") {
match s.parse() {
Ok(val) => seconds = val,
Err(_) => {
let errmsg = "request should have seconds argument".to_owned();
return Ok(make_response(StatusCode::BAD_REQUEST, errmsg));
}
}
}
let timer = GLOBAL_TIMER_HANDLE.delay(Instant::now() + Duration::from_secs(seconds));
let end = Compat01As03::new(timer)
.map_err(|_| TIMER_CANCELED.to_owned())
.into_future();
start_one_heap_profile(end, use_jeprof, output_format).await
};
let result = dump_one_heap_profile(use_jeprof, output_format.clone());

match result {
Ok(body) => {
Expand All @@ -290,7 +268,7 @@ where
.header("X-Content-Type-Options", "nosniff")
.header("Content-Disposition", "attachment; filename=\"profile\"")
.header("Content-Length", body.len());
response = if use_jeprof {
response = if use_jeprof && output_format == "--svg" {
response.header("Content-Type", mime::IMAGE_SVG.to_string())
} else {
response.header("Content-Type", mime::APPLICATION_OCTET_STREAM.to_string())
Expand Down
16 changes: 16 additions & 0 deletions proxy_components/proxy_server/src/status_server/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ where
ProfileGuard::new(on_start, on_end, end.boxed())?.await
}

/// Trigger a heap profie and return the content.
#[allow(dead_code)]
pub fn dump_one_heap_profile(use_jeprof: bool, output_format: String) -> Result<Vec<u8>, String> {
info!("dump_one_heap_profile"; "use_jeprof" => use_jeprof, "output_format" => &output_format);
let f = NamedTempFile::new().map_err(|e| format!("create tmp file fail: {}", e))?;
let path = f.path().to_str().unwrap();
dump_prof(path).map_err(|e| format!("dump_prof: {}", e))?;
if use_jeprof {
// Use jeprof to transform heap file into svg/raw/collapsed...
jeprof_heap_profile(path, output_format)
} else {
// Juse return the heap file.
read_file(path)
}
}

pub fn set_prof_active(val: bool) -> Result<(), String> {
let activate = has_activate_prof();
if activate == val {
Expand Down
Loading