Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3361924
D5014.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D5014.diff
View Options
diff --git a/services/backup/blob_client/src/get_client.rs b/services/backup/blob_client/src/get_client.rs
--- a/services/backup/blob_client/src/get_client.rs
+++ b/services/backup/blob_client/src/get_client.rs
@@ -61,7 +61,64 @@
pub fn get_client_initialize_cxx(
holder_char: *const c_char,
) -> Result<(), String> {
- unimplemented!();
+ if is_initialized() {
+ get_client_terminate_cxx()?;
+ }
+
+ assert!(!is_initialized(), "client cannot be initialized twice");
+
+ let holder_cstr: &CStr = unsafe { CStr::from_ptr(holder_char) };
+ let holder: String = holder_cstr.to_str().unwrap().to_owned();
+
+ // grpc
+ if let Ok(mut grpc_client) =
+ RUNTIME.block_on(async { BlobServiceClient::connect(BLOB_ADDRESS).await })
+ {
+ // spawn receiver thread
+ let (response_thread_tx, response_thread_rx) =
+ mpsc::channel::<Vec<u8>>(MPSC_CHANNEL_BUFFER_CAPACITY);
+ let rx_handle = RUNTIME.spawn(async move {
+ if let Ok(response) = grpc_client.get(GetRequest { holder }).await {
+ let mut inner_response = response.into_inner();
+ loop {
+ match inner_response.message().await {
+ Ok(maybe_data) => {
+ let mut result = false;
+ if let Some(data) = maybe_data {
+ let data: Vec<u8> = data.data_chunk;
+ result = match response_thread_tx.send(data).await {
+ Ok(_) => true,
+ Err(err) => {
+ report_error(err.to_string());
+ false
+ }
+ }
+ }
+ if !result {
+ break;
+ }
+ }
+ Err(err) => {
+ report_error(err.to_string());
+ break;
+ }
+ };
+ }
+ } else {
+ report_error("couldn't perform grpc get operation".to_string());
+ }
+ });
+
+ if let Ok(mut client) = CLIENT.lock() {
+ *client = Some(ReadClient {
+ rx_handle,
+ rx: response_thread_rx,
+ });
+ return Ok(());
+ }
+ return Err("could not access client".to_string());
+ }
+ Err("could not successfully connect to the blob server".to_string())
}
pub fn get_client_blocking_read_cxx() -> Result<Vec<u8>, String> {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 8:25 PM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2580894
Default Alt Text
D5014.diff (2 KB)
Attached To
Mode
D5014: [services] Backup - Blob Get Client - Add initialize
Attached
Detach File
Event Timeline
Log In to Comment