Skip to content

Commit

Permalink
kv 新增最大从连接数
Browse files Browse the repository at this point in the history
  • Loading branch information
viciousstar committed Oct 24, 2023
1 parent 11a61b8 commit 6547974
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions endpoint/src/kv/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub struct Basic {
pub(crate) password: String,
#[serde(default)]
pub(crate) user: String,
#[serde(default)]
pub(crate) max_slave_conns: u16,
}
pub const ARCHIVE_DEFAULT_KEY: &str = "__default__";

Expand Down
8 changes: 7 additions & 1 deletion endpoint/src/kv/topo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use protocol::Protocol;
use protocol::Request;
use protocol::ResOption;
use protocol::Resource;
use rand::seq::SliceRandom;
use sharding::hash::{Hash, HashKey};
use sharding::Distance;

Expand Down Expand Up @@ -258,10 +259,11 @@ where
}
}

let mut rng = rand::thread_rng();
for (interval, addrs_per_interval) in addrs {
let mut shards_per_interval = Vec::with_capacity(addrs_per_interval.len());
// 遍历所有的shards_url
for (master_addr, slaves) in addrs_per_interval {
for (master_addr, mut slaves) in addrs_per_interval {
assert_ne!(master_addr.len(), 0);
assert_ne!(slaves.len(), 0);
// 用户名和密码
Expand All @@ -277,6 +279,10 @@ where
);
// slave
let mut replicas = Vec::with_capacity(8);
if self.cfg.basic.max_salve_conns != 0 {
slaves.shuffle(&mut rng);
slaves.truncate(self.cfg.basic.max_salve_conns as usize);
}
for addr in slaves {
let slave = self.take_or_build(
&mut old,
Expand Down

0 comments on commit 6547974

Please sign in to comment.