Skip to content

Commit

Permalink
def Weight as i64
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Dec 7, 2024
1 parent b1c62ba commit 3491b95
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chaindev"
version = "0.52.3"
version = "0.52.4"
edition = "2021"
authors = ["hui.fan@mail.ru"]
description = "Powerful development and testing utils for blockchain developers."
Expand Down
19 changes: 15 additions & 4 deletions src/beacon_based/ddev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod remote;

use crate::check_errlist;
use crate::common::{
hosts::{Host, HostAddr, HostID, HostMeta, Hosts},
hosts::{Host, HostAddr, HostID, HostMeta, Hosts, Weight},
remote::{exec_cmds_on_hosts, get_file_from_hosts, put_file_to_hosts, Remote},
};
use parking_lot::RwLock;
Expand Down Expand Up @@ -729,7 +729,13 @@ where
.hosts
.as_ref()
.values()
.map(|h| (h.meta.clone(), (h.node_cnt * max_weight) / h.weight))
.filter(|h| h.weight > 0)
.map(|h| {
(
h.meta.clone(),
(h.node_cnt as Weight * max_weight) / h.weight,
)
})
.collect::<Vec<_>>()
})?;
seq.sort_by(|a, b| a.1.cmp(&b.1));
Expand Down Expand Up @@ -1571,8 +1577,13 @@ where
.hosts
.as_ref()
.values()
.filter(|h| h.weight > 0) // never allocate on 'zero-weight hosts'
.map(|h| (h.meta.clone(), (h.node_cnt * max_weight) / h.weight))
.filter(|h| h.weight > 0)
.map(|h| {
(
h.meta.clone(),
(h.node_cnt as Weight * max_weight) / h.weight,
)
})
.collect::<Vec<_>>();
seq.sort_by(|a, b| a.1.cmp(&b.1));
seq.into_iter().next().c(d!()).map(|h| h.0)?
Expand Down
2 changes: 1 addition & 1 deletion src/common/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl FromStr for HostAddr {
pub type HostExpression = String;
pub type HostExpressionRef<'a> = &'a str;

type Weight = u64;
pub type Weight = i64;
type WeightGuard = u16;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
6 changes: 3 additions & 3 deletions src/common/remote.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
check_errlist,
common::hosts::{Host, HostMeta, Hosts},
common::hosts::{Host, HostMeta, Hosts, Weight},
};
use ruc::{ssh, *};
use std::{
Expand Down Expand Up @@ -124,14 +124,14 @@ impl Remote<'_> {
})
}

pub fn get_hosts_weight(&self) -> Result<u64> {
pub fn get_hosts_weight(&self) -> Result<Weight> {
let cpunum = self
.exec_cmd(
r#"if [[ "Linux" = `uname -s` ]]; then nproc; elif [[ "Darwin" = `uname -s` ]]; then sysctl -a | grep 'machdep.cpu.core_count' | grep -o '[0-9]\+$'; else exit 1; fi"#,
)
.c(d!())?
.trim()
.parse::<u64>()
.parse::<Weight>()
.c(d!())?;

// let bogomips = self
Expand Down
19 changes: 15 additions & 4 deletions src/tendermint_based/ddev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod remote;

use crate::check_errlist;
use crate::common::{
hosts::{HostExpression, HostExpressionRef, HostID, HostMeta, Hosts},
hosts::{HostExpression, HostExpressionRef, HostID, HostMeta, Hosts, Weight},
remote::{exec_cmds_on_hosts, get_file_from_hosts, put_file_to_hosts, Remote},
};
use rand::random;
Expand Down Expand Up @@ -552,7 +552,13 @@ where
.hosts
.as_ref()
.values()
.map(|h| (h.meta.clone(), (h.node_cnt * max_weight) / h.weight))
.filter(|h| h.weight > 0)
.map(|h| {
(
h.meta.clone(),
(h.node_cnt as Weight * max_weight) / h.weight,
)
})
.collect::<Vec<_>>()
})?;
seq.sort_by(|a, b| a.1.cmp(&b.1));
Expand Down Expand Up @@ -1278,8 +1284,13 @@ where
.hosts
.as_ref()
.values()
.filter(|h| h.weight > 0) // never allocate on 'zero-weight hosts'
.map(|h| (h.meta.clone(), (h.node_cnt * max_weight) / h.weight))
.filter(|h| h.weight > 0)
.map(|h| {
(
h.meta.clone(),
(h.node_cnt as Weight * max_weight) / h.weight,
)
})
.collect::<Vec<_>>();
seq.sort_by(|a, b| a.1.cmp(&b.1));
seq.into_iter().next().c(d!()).map(|h| h.0)?
Expand Down

0 comments on commit 3491b95

Please sign in to comment.