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

[774] BobClient reduce clone overhead #775

Merged
merged 63 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0af16d9
[774] BobClient reduce clone overhead
ikopylov Feb 19, 2023
45acb3e
[774] Fix build
ikopylov Feb 19, 2023
7dd43bc
[774] Fix build
ikopylov Feb 19, 2023
9d75cc2
[774] Fix build warnings
ikopylov Feb 19, 2023
2f1644d
[774] Remove inner data struct for BobClient
ikopylov Feb 19, 2023
0c5c67b
[774] Detect all places where node is clonned
ikopylov Feb 19, 2023
c86f54a
[774] Trace node clones
ikopylov Feb 19, 2023
578b9c4
[774] Add NodeName struct, wrap Node internals into Arc
ikopylov Feb 19, 2023
7e9cee0
[774] Fix build
ikopylov Feb 19, 2023
4e841f8
[774] Build fixes
ikopylov Feb 20, 2023
92562a7
[774] Fix build errors
ikopylov Feb 20, 2023
20aa7e9
[774] Config validation code refactoring
ikopylov Feb 22, 2023
e093329
[774] Better vdisk ids validation
ikopylov Feb 22, 2023
9c81e3a
[774] VDiskMap initialization refactoring
ikopylov Feb 22, 2023
7e018c1
[774] Fix validation error conversion
ikopylov Feb 22, 2023
76f2795
[774] Build fix
ikopylov Feb 22, 2023
e3a953b
[774] Build fix
ikopylov Feb 22, 2023
e182e49
[774] Build fix
ikopylov Feb 23, 2023
22f0af3
[774] NodeName proper comparison
ikopylov Feb 23, 2023
9d1c2bc
[774] Fix build
ikopylov Feb 24, 2023
6396144
[774] Fix build
ikopylov Feb 24, 2023
bdca0c6
[774] Use NodeName everywhere
ikopylov Feb 26, 2023
cb8b3be
[774] Fix build
ikopylov Feb 26, 2023
229e44b
[774] Fix build
ikopylov Feb 26, 2023
cca1d2a
[774] Fix build
ikopylov Feb 26, 2023
5163c02
[774] Fix build
ikopylov Feb 26, 2023
c181186
[774] Fix build
ikopylov Feb 26, 2023
325d5bd
[774] Fix build
ikopylov Feb 26, 2023
ab2b43e
[774] Fix build
ikopylov Feb 26, 2023
83424d8
[774] Move operation options into separate file
ikopylov Feb 26, 2023
ce495e0
[774] Fix build
ikopylov Feb 26, 2023
abe4e01
[774] Move several types into core_types module
ikopylov Feb 26, 2023
2e56608
[774] Fix build
ikopylov Feb 26, 2023
d6ce553
[774] Fix build
ikopylov Feb 26, 2023
392a667
[774] Fix build
ikopylov Feb 26, 2023
b765fe6
[774] Fix build
ikopylov Feb 26, 2023
da92a4d
[774] Add DiskName type
ikopylov Feb 26, 2023
dd45106
[774] Fix build
ikopylov Feb 26, 2023
a47c82e
[774] Implement serialize/deserialize for DiskPath
ikopylov Feb 27, 2023
8c6a4e6
[774] Proper serialization/deserialization implementation for DiskName
ikopylov Apr 6, 2023
a5774e5
[774] Build fix
ikopylov Apr 6, 2023
6d6da39
[774] Build fix
ikopylov Apr 6, 2023
67bfb58
[774] Build fix
ikopylov Apr 6, 2023
280baa2
[774] Fix build
ikopylov Apr 6, 2023
6a695bc
[774] Build fix
ikopylov Apr 6, 2023
e60e4eb
[774] Build fix
ikopylov Apr 6, 2023
300ef5d
[774] Tests build fix
ikopylov Apr 6, 2023
62a95e9
[774] Build fix
ikopylov Apr 6, 2023
7226b10
Merge branch 'master' into 774-reduce-node-and-bob-client-overhead-on…
ikopylov Apr 6, 2023
fb1094a
[774] Update Changelog.md
ikopylov Apr 6, 2023
96ba967
Merge branch 'master' into 774-reduce-node-and-bob-client-overhead-on…
ikopylov May 13, 2023
5d80acc
[774] Fix build
ikopylov May 13, 2023
223cdb4
[774] Replace ref with deref in comparison operations
ikopylov May 13, 2023
738a20f
[774] Fix build
ikopylov May 13, 2023
a6cb385
[774] Fix build
ikopylov May 13, 2023
1897a04
[774] Print validation error only on the top level
ikopylov May 13, 2023
92dbf3d
[774] Declare generic `Name` type instead of separate `NodeName` and …
ikopylov May 13, 2023
07da304
[774] Fix test
ikopylov May 13, 2023
9140fd0
Merge branch 'master' into 774-reduce-node-and-bob-client-overhead-on…
ikopylov May 16, 2023
07548da
[774] Remove `allow(dead_code)` from BobClient
ikopylov May 16, 2023
8953d06
[774] Remove unneeded escape before `'` symbol
ikopylov May 16, 2023
3461dbd
[774] Remove unneeded `must_use` attributes
ikopylov May 16, 2023
f8b291b
[774] Move ArcStrVisitor to the bottom of the file (close to deserial…
ikopylov May 16, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Bob versions changelog
- Added mimalloc allocator for musl target (#688)

#### Changed
- BobClient clone overhead reduced (#774)
- Node struct internals placed inside Arc to reduce clone overhead (#724)
- NodeName and DiskName types introduced to reduce clone overhead (#775)
- Avoid Pearl Storage clone (#791)
- Make iouring optional (#567)

Expand Down
14 changes: 10 additions & 4 deletions bob-apps/bin/bobd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ async fn main() {
return;
}

let cluster_config = matches.value_of("cluster").unwrap();
let cluster_config = matches.value_of("cluster").expect("'cluster' argument is required");
println!("Cluster config: {:?}", cluster_config);
let cluster = ClusterConfig::try_get(cluster_config).await.unwrap();
let cluster = ClusterConfig::try_get(cluster_config).await.map_err(|err| {
eprintln!("Cluster config parsing error: {}", err);
err
}).expect("Cluster config parsing error");

let node_config_file = matches.value_of("node").unwrap();
let node_config_file = matches.value_of("node").expect("'node' argument is required");
println!("Node config: {:?}", node_config_file);
let node = cluster.get(node_config_file).await.unwrap();
let node = cluster.get(node_config_file).await.map_err(|err| {
eprintln!("Node config parsing error: {}", err);
err
}).expect("Node config parsing error");

let mut extra_logstash_fields = HashMap::new();
extra_logstash_fields.insert("node_name".to_string(), serde_json::Value::String(node.name().to_string()));
Expand Down
14 changes: 7 additions & 7 deletions bob-apps/bin/config_cluster_generator/center.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::{

const REPLICA_IN_FIRST_RACK: usize = 2;
type RackName = String;
type NodeName = String;
type DiskName = String;
type NodeName = bob_common::node::NodeName;
type DiskName = bob_common::core_types::DiskName;

#[derive(Debug, Default)]
struct Counter {
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Center {
},
)?;
for node in rack.nodes() {
node_rack_map.insert(node, rack.name())
node_rack_map.insert(NodeName::from(node), rack.name())
.map_or_else(
|| Ok(()),
|_| {
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Center {
self.iter_disks()
.find(|(_, node, disk)| {
self.counter.disk_used_count(&node.name, &disk.name) == min_key
&& list.contains(&Replica::new(node.name.clone(), disk.name.clone()))
&& list.contains(&Replica::new(node.name.to_string(), disk.name.to_string()))
})
.ok_or_else(|| anyhow!("Can't find disk"))
}
Expand Down Expand Up @@ -445,7 +445,7 @@ impl Rack {
let (node, disk) = disks
.find(|(node, disk)| {
min_key == counter.disk_used_count(&node.name, &disk.name)
&& list.contains(&Replica::new(node.name.clone(), disk.name.clone()))
&& list.contains(&Replica::new(node.name.to_string(), disk.name.to_string()))
})
.ok_or_else(|| anyhow!("Can't find disk"))?;

Expand Down Expand Up @@ -521,7 +521,7 @@ impl Disk {
}

fn get_used_nodes_names(replicas: &[Replica]) -> Vec<NodeName> {
replicas.iter().map(|r| r.node().to_string()).collect()
replicas.iter().map(|r| NodeName::from(r.node())).collect()
}

pub fn get_new_disks(
Expand All @@ -541,7 +541,7 @@ pub fn get_new_disks(
&& disk == &old_disk
})
})
.map(|(node, disk)| (node.name().to_owned(), disk.name().to_owned()))
.map(|(node, disk)| (NodeName::from(node.name()), DiskName::from(disk.name())))
.collect()
}

Expand Down
36 changes: 13 additions & 23 deletions bob-backend/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ pub const BACKEND_STARTED: f64 = 1f64;
pub struct Operation {
vdisk_id: VDiskId,
disk_path: Option<DiskPath>,
remote_node_name: Option<String>, // save data to alien/<remote_node_name>
remote_node_name: Option<NodeName>, // save data to alien/<remote_node_name>
}

impl Operation {
pub fn vdisk_id(&self) -> VDiskId {
self.vdisk_id
}

pub fn remote_node_name(&self) -> Option<&str> {
self.remote_node_name.as_deref()
pub fn remote_node_name(&self) -> Option<&NodeName> {
self.remote_node_name.as_ref()
}
}

Expand Down Expand Up @@ -62,18 +62,8 @@ impl Operation {
}
}

// local operation doesn't contain remote node, so node name is passed through argument
#[must_use]
pub fn clone_local_alien(&self, local_node_name: &str) -> Self {
Self {
vdisk_id: self.vdisk_id,
disk_path: None,
remote_node_name: Some(local_node_name.to_owned()),
}
}

#[inline]
pub fn set_remote_folder(&mut self, name: String) {
pub fn set_remote_node_name(&mut self, name: NodeName) {
self.remote_node_name = Some(name);
}

Expand All @@ -83,8 +73,8 @@ impl Operation {
}

#[inline]
pub fn disk_name_local(&self) -> String {
self.disk_path.as_ref().expect("no path").name().to_owned()
pub fn disk_name_local(&self) -> &DiskName {
self.disk_path.as_ref().expect("no path").name()
}
}

Expand Down Expand Up @@ -163,7 +153,7 @@ pub trait MetricsProducer: Send + Sync {

#[derive(Hash, PartialEq, Eq, Debug)]
enum BackendErrorAction {
PUT(String, String),
PUT(DiskName, String),
}

impl Display for BackendErrorAction {
Expand All @@ -181,7 +171,7 @@ impl Display for BackendErrorAction {
}

impl BackendErrorAction {
fn put(disk: String, error: &Error) -> Self {
fn put(disk: DiskName, error: &Error) -> Self {
BackendErrorAction::PUT(disk, error.to_string())
}
}
Expand Down Expand Up @@ -263,7 +253,7 @@ impl Backend {
for node_name in options.remote_nodes() {
debug!("PUT[{}] core backend put remote node: {}", key, node_name);
let mut op = Operation::new_alien(vdisk_id);
op.set_remote_folder(node_name.to_owned());
op.set_remote_node_name(node_name.clone());

//TODO make it parallel?
self.put_single(key, data, op).await?;
Expand Down Expand Up @@ -327,12 +317,12 @@ impl Backend {
local_err
);
let error_to_log =
BackendErrorAction::put(operation.disk_name_local(), &local_err);
BackendErrorAction::put(operation.disk_name_local().clone(), &local_err);
self.error_logger.report_error(error_to_log);

// write to alien/<local name>
let mut op = operation.clone_local_alien(self.mapper().local_node_name());
op.set_remote_folder(self.mapper.local_node_name().to_owned());
let mut op = operation.clone();
op.set_remote_node_name(self.mapper.local_node_name().clone());
self.inner
.put_alien(op, key, data)
.await
Expand Down Expand Up @@ -454,7 +444,7 @@ impl Backend {
for node in self.mapper.get_target_nodes_for_key(key) {
let force_delete = options.is_force_delete(node.name());
let mut op = Operation::new_alien(vdisk_id);
op.set_remote_folder(node.name().to_owned());
op.set_remote_node_name(node.name().clone());
let delete_res = self.delete_single(key, meta, op, force_delete).await;
if let Err(err) = delete_res {
error!("DELETE[{}] Error deleting from aliens (node: {}, force_delete: {}): {:?}", key, node.name(), force_delete, err);
Expand Down
5 changes: 4 additions & 1 deletion bob-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub(crate) mod prelude {
cluster::Cluster as ClusterConfig,
node::{BackendType, Node as NodeConfig, Pearl as PearlConfig},
},
data::{BobData, BobKey, BobMeta, BobPutOptions, BobGetOptions, BobDeleteOptions, DiskPath, VDiskId},
data::{BobData, BobKey, BobMeta},
operation_options::{BobPutOptions, BobGetOptions, BobDeleteOptions},
core_types::{DiskName, DiskPath, VDiskId},
node::NodeName,
error::Error,
mapper::Virtual,
metrics::BACKEND_STATE,
Expand Down
12 changes: 6 additions & 6 deletions bob-backend/src/mem_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ impl VDisk {

#[derive(Clone, Debug)]
pub struct MemDisk {
pub name: String,
pub name: DiskName,
pub vdisks: HashMap<VDiskId, VDisk>,
}

impl MemDisk {
pub fn new_direct(name: String, vdisks_count: u32) -> Self {
pub fn new_direct(name: DiskName, vdisks_count: u32) -> Self {
let vdisks = (0..vdisks_count).map(|i| (i, VDisk::default())).collect();
Self { name, vdisks }
}

pub fn new(name: String, mapper: &Virtual) -> Self {
pub fn new(name: DiskName, mapper: &Virtual) -> Self {
let vdisks = mapper
.get_vdisks_by_disk(&name)
.iter()
Expand Down Expand Up @@ -109,7 +109,7 @@ impl MemDisk {

#[derive(Clone, Debug)]
pub struct MemBackend {
pub disks: HashMap<String, MemDisk>,
pub disks: HashMap<DiskName, MemDisk>,
pub foreign_data: MemDisk,
}

Expand All @@ -119,11 +119,11 @@ impl MemBackend {
.local_disks()
.iter()
.map(DiskPath::name)
.map(|name| (name.to_string(), MemDisk::new(name.to_string(), mapper)))
.map(|name| (name.clone(), MemDisk::new(name.clone(), mapper)))
.collect();
Self {
disks,
foreign_data: MemDisk::new_direct("foreign".to_string(), mapper.vdisks_count()),
foreign_data: MemDisk::new_direct("foreign".into(), mapper.vdisks_count()),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions bob-backend/src/mem_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const VDISKS_COUNT: u32 = 10;
pub(crate) fn new_direct(paths: &[String], vdisks_count: u32) -> MemBackend {
let disks = paths
.iter()
.map(|p| (p.clone(), MemDisk::new_direct(p.clone(), vdisks_count)))
.map(|p| (DiskName::from(p), MemDisk::new_direct(DiskName::from(p), vdisks_count)))
.collect();
MemBackend {
disks,
foreign_data: MemDisk::new_direct("foreign".to_string(), vdisks_count),
foreign_data: MemDisk::new_direct(DiskName::from("foreign"), vdisks_count),
}
}

Expand All @@ -24,7 +24,7 @@ async fn test_mem_put_wrong_disk() {

let retval = backend
.put(
Operation::new_local(0, DiskPath::new("invalid name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("invalid name".into(), "")),
BobKey::from(1u64),
&BobData::new(vec![0].into(), BobMeta::stub()),
)
Expand All @@ -38,15 +38,15 @@ async fn test_mem_put_get() {

backend
.put(
Operation::new_local(0, DiskPath::new("name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("name".into(), "")),
BobKey::from(1u64),
&BobData::new(vec![1].into(), BobMeta::stub()),
)
.await
.unwrap();
let retval = backend
.get(
Operation::new_local(0, DiskPath::new("name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("name".into(), "")),
BobKey::from(1u64),
)
.await
Expand All @@ -60,15 +60,15 @@ async fn test_mem_get_wrong_disk() {

backend
.put(
Operation::new_local(0, DiskPath::new("name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("name".into(), "")),
BobKey::from(1u64),
&BobData::new(vec![1].into(), BobMeta::stub()),
)
.await
.unwrap();
let retval = backend
.get(
Operation::new_local(0, DiskPath::new("invalid name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("invalid name".into(), "")),
BobKey::from(1u64),
)
.await;
Expand All @@ -82,7 +82,7 @@ async fn test_mem_get_no_data() {

let retval = backend
.get(
Operation::new_local(0, DiskPath::new("name".to_owned(), "".to_owned())),
Operation::new_local(0, DiskPath::new("name".into(), "")),
key,
)
.await;
Expand Down
13 changes: 7 additions & 6 deletions bob-backend/src/pearl/disk_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct DiskController {
vdisks: Vec<VDiskId>,
run_sem: Arc<Semaphore>,
monitor_sem: Arc<Semaphore>,
node_name: String,
node_name: NodeName,
groups: Arc<RwLock<Vec<Group>>>,
state: Arc<RwLock<GroupsState>>,
settings: Arc<Settings>,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl DiskController {
vdisks,
run_sem,
monitor_sem: Arc::new(Semaphore::new(1)),
node_name: config.name().to_owned(),
node_name: NodeName::from(config.name()),
groups: Arc::new(RwLock::new(Vec::new())),
state: Arc::new(RwLock::new(GroupsState::NotReady)),
settings,
Expand Down Expand Up @@ -260,13 +260,14 @@ impl DiskController {
.copied()
.map(|vdisk_id| {
let path = self.settings.normal_path(self.disk.path(), vdisk_id);
let owner_node_identifier = self.node_name.to_string();
Group::new(
self.settings.clone(),
vdisk_id,
self.node_name.clone(),
self.disk.name().to_owned(),
self.disk.name().clone(),
path,
self.node_name.clone(),
owner_node_identifier,
self.pearl_creation_context.clone(),
)
})
Expand All @@ -277,7 +278,7 @@ impl DiskController {
let settings = self.settings.clone();
let groups = settings
.collect_alien_groups(
self.disk.name().to_owned(),
self.disk.name(),
&self.node_name,
self.pearl_creation_context.clone(),
)
Expand Down Expand Up @@ -325,7 +326,7 @@ impl DiskController {
.settings
.clone()
.create_alien_group(
operation.remote_node_name().expect("Node name not found"),
operation.remote_node_name().expect("Node name not found").clone(),
operation.vdisk_id(),
&self.node_name,
self.pearl_creation_context.clone(),
Expand Down
2 changes: 1 addition & 1 deletion bob-backend/src/pearl/disk_controller/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DisksEventsLogger {
f.sync_all().await
}

pub(crate) async fn log(&self, disk_name: &str, event: &str, is_alien: bool) {
pub(crate) async fn log(&self, disk_name: &DiskName, event: &str, is_alien: bool) {
let cur_time = Local::now();
let log_msg = format!(
"{};{};{};{}\n",
Expand Down
Loading