Skip to content

Commit

Permalink
add a thread local for request client info
Browse files Browse the repository at this point in the history
Summary: add a thread local for request client info

Reviewed By: quark-zju

Differential Revision: D49776307

fbshipit-source-id: 7079997ae8f5c85114da385cc1d0a30706004db5
  • Loading branch information
Liubov Dmitrieva authored and facebook-github-bot committed Oct 2, 2023
1 parent dfeec9a commit 60c6cbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eden/scm/lib/clientinfo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use facebook::FbClientInfo;
use oss as facebook;

pub use crate::request_info::get_client_request_info;
pub use crate::request_info::get_client_request_info_thread_local;
pub use crate::request_info::set_client_request_info_thread_local;
pub use crate::request_info::ClientEntryPoint;
pub use crate::request_info::ClientRequestInfo;

Expand Down
14 changes: 14 additions & 0 deletions eden/scm/lib/clientinfo/src/request_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* GNU General Public License version 2.
*/

use std::cell::RefCell;
use std::env::var;
use std::fmt::Display;

Expand All @@ -23,6 +24,7 @@ const ENV_SAPLING_CLIENT_CORRELATOR: &str = "SAPLING_CLIENT_CORRELATOR";
const DEFAULT_CLIENT_ENTRY_POINT_SAPLING: ClientEntryPoint = ClientEntryPoint::Sapling;
const DEFAULT_CLIENT_ENTRY_POINT_EDENFS: ClientEntryPoint = ClientEntryPoint::EdenFS;

// The global static ClientRequestInfo
lazy_static! {
pub static ref CLIENT_REQUEST_INFO: ClientRequestInfo = new_client_request_info();
}
Expand Down Expand Up @@ -79,6 +81,18 @@ fn new_client_request_info() -> ClientRequestInfo {
ClientRequestInfo::new_ext(entry_point, correlator)
}

thread_local! {
pub static CLIENT_REQUEST_INFO_THREAD_LOCAL: RefCell<Option<ClientRequestInfo>> = Default::default();
}

pub fn set_client_request_info_thread_local(cri: ClientRequestInfo) {
CLIENT_REQUEST_INFO_THREAD_LOCAL.with(move |cri_old| *cri_old.borrow_mut() = Some(cri));
}

pub fn get_client_request_info_thread_local() -> Option<ClientRequestInfo> {
CLIENT_REQUEST_INFO_THREAD_LOCAL.with(|cri| cri.borrow().clone())
}

/// ClientRequestInfo holds information that will be used for tracing the request
/// through Source Control systems.
#[derive(Clone, Deserialize, Serialize, Debug)]
Expand Down

0 comments on commit 60c6cbc

Please sign in to comment.