Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3280037
D5031.id16224.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D5031.id16224.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
@@ -6,7 +6,7 @@
use proto::GetRequest;
use crate::constants::{BLOB_ADDRESS, MPSC_CHANNEL_BUFFER_CAPACITY};
-use crate::tools::report_error;
+use crate::tools::{report_error, check_error};
use lazy_static::lazy_static;
use libc;
use libc::c_char;
@@ -23,7 +23,8 @@
lazy_static! {
static ref CLIENT: Arc<Mutex<Option<ReadClient>>> =
- Arc::new(Mutex::new(None)); // todo we should probably create separate clients for different IDs
+ Arc::new(Mutex::new(None));
+ // todo we should probably create separate clients for different IDs
static ref RUNTIME: Runtime = Runtime::new().unwrap();
static ref ERROR_MESSAGES: Arc<Mutex<Vec<String>>> =
Arc::new(Mutex::new(Vec::new()));
@@ -40,16 +41,6 @@
false
}
-fn check_error() -> Result<(), String> {
- if let Ok(errors) = ERROR_MESSAGES.lock() {
- return match errors.is_empty() {
- true => Ok(()),
- false => Err(errors.join("\n")),
- };
- }
- Err("could not access error messages".to_string())
-}
-
pub fn get_client_initialize_cxx(
holder_char: *const c_char,
) -> Result<(), String> {
@@ -120,7 +111,7 @@
pub fn get_client_blocking_read_cxx() -> Result<Vec<u8>, String> {
let mut response: Option<Vec<u8>> = None;
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
RUNTIME.block_on(async {
if let Ok(mut maybe_client) = CLIENT.lock() {
if let Some(mut client) = (*maybe_client).take() {
@@ -137,13 +128,13 @@
report_error(&ERROR_MESSAGES, "couldn't access client".to_string());
}
});
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
let response: Vec<u8> = response.unwrap();
Ok(response)
}
pub fn get_client_terminate_cxx() -> Result<(), String> {
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
if !is_initialized() {
return Ok(());
}
@@ -168,6 +159,6 @@
!is_initialized(),
"client transmitter handler released properly"
);
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
Ok(())
}
diff --git a/services/backup/blob_client/src/put_client.rs b/services/backup/blob_client/src/put_client.rs
--- a/services/backup/blob_client/src/put_client.rs
+++ b/services/backup/blob_client/src/put_client.rs
@@ -9,7 +9,7 @@
use proto::PutResponse;
use crate::constants::{BLOB_ADDRESS, MPSC_CHANNEL_BUFFER_CAPACITY};
-use crate::tools::report_error;
+use crate::tools::{report_error, check_error};
use lazy_static::lazy_static;
use libc;
use libc::c_char;
@@ -52,16 +52,6 @@
false
}
-fn check_error() -> Result<(), String> {
- if let Ok(errors) = ERROR_MESSAGES.lock() {
- return match errors.is_empty() {
- true => Ok(()),
- false => Err(errors.join("\n")),
- };
- }
- Err("could not access error messages".to_string())
-}
-
pub fn put_client_initialize_cxx() -> Result<(), String> {
if is_initialized() {
put_client_terminate_cxx()?;
@@ -187,7 +177,7 @@
pub fn put_client_blocking_read_cxx() -> Result<String, String> {
let mut response: Option<String> = None;
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
RUNTIME.block_on(async {
if let Ok(mut maybe_client) = CLIENT.lock() {
if let Some(mut client) = (*maybe_client).take() {
@@ -207,7 +197,7 @@
report_error(&ERROR_MESSAGES, "couldn't access client".to_string());
}
});
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
response.ok_or("response not received properly".to_string())
}
@@ -221,7 +211,7 @@
field_index: usize,
data: *const c_char,
) -> Result<(), String> {
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
let data_c_str: &CStr = unsafe { CStr::from_ptr(data) };
let data_bytes: Vec<u8> = data_c_str.to_bytes().to_vec();
@@ -254,7 +244,7 @@
}
pub fn put_client_terminate_cxx() -> Result<(), String> {
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
if !is_initialized() {
return Ok(());
}
@@ -281,6 +271,6 @@
!is_initialized(),
"client transmitter handler released properly"
);
- check_error()?;
+ check_error(&ERROR_MESSAGES)?;
Ok(())
}
diff --git a/services/backup/blob_client/src/tools.rs b/services/backup/blob_client/src/tools.rs
--- a/services/backup/blob_client/src/tools.rs
+++ b/services/backup/blob_client/src/tools.rs
@@ -8,3 +8,13 @@
}
error!("could not access error messages");
}
+
+pub fn check_error(error_messages: &Arc<Mutex<Vec<String>>>) -> Result<(), String> {
+ if let Ok(errors) = error_messages.lock() {
+ return match errors.is_empty() {
+ true => Ok(()),
+ false => Err(errors.join("\n")),
+ };
+ }
+ Err("could not access error messages".to_string())
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 9:00 AM (20 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2520897
Default Alt Text
D5031.id16224.diff (4 KB)
Attached To
Mode
D5031: [services] Rust Integration - Backup - Make check_error shared
Attached
Detach File
Event Timeline
Log In to Comment