refactor: remove unneeded comments

This commit is contained in:
Jun Kurihara 2023-06-03 15:01:58 +09:00
commit 96810a4d4f
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
2 changed files with 12 additions and 11 deletions

View file

@ -12,12 +12,8 @@ pub(super) mod load_balance_options {
pub const STICKY_ROUND_ROBIN: &str = "sticky"; pub const STICKY_ROUND_ROBIN: &str = "sticky";
} }
//
// /// Counter for load balancing
// pub cnt: UpstreamCount,
// TODO: カウンタの移動
#[derive(Debug, Clone, Builder)] #[derive(Debug, Clone, Builder)]
/// Counter object as a pointer to the current serving upstream destination
pub struct LbRoundRobinCount { pub struct LbRoundRobinCount {
#[builder(default)] #[builder(default)]
cnt: Arc<AtomicUsize>, cnt: Arc<AtomicUsize>,
@ -52,12 +48,12 @@ impl LbRoundRobinCount {
pub enum LoadBalance { pub enum LoadBalance {
/// Fix to the first upstream. Use if only one upstream destination is specified /// Fix to the first upstream. Use if only one upstream destination is specified
FixToFirst, FixToFirst,
/// Simple round robin without session persistance
RoundRobin(LbRoundRobinCount), // TODO: カウンタはここにいれる。randomとかには不要なので
/// Randomly chose one upstream server /// Randomly chose one upstream server
Random, Random,
/// Simple round robin without session persistance
RoundRobin(LbRoundRobinCount),
/// Round robin with session persistance using cookie /// Round robin with session persistance using cookie
StickyRoundRobin, StickyRoundRobin(LbRoundRobinCount),
} }
impl Default for LoadBalance { impl Default for LoadBalance {
fn default() -> Self { fn default() -> Self {

View file

@ -96,14 +96,19 @@ impl UpstreamGroupBuilder {
let lb = if let Some(x) = v { let lb = if let Some(x) = v {
match x.as_str() { match x.as_str() {
lb_opts::FIX_TO_FIRST => LoadBalance::FixToFirst, lb_opts::FIX_TO_FIRST => LoadBalance::FixToFirst,
lb_opts::RANDOM => LoadBalance::Random,
lb_opts::ROUND_ROBIN => LoadBalance::RoundRobin( lb_opts::ROUND_ROBIN => LoadBalance::RoundRobin(
LbRoundRobinCountBuilder::default() LbRoundRobinCountBuilder::default()
.max_val(upstream_num) .max_val(upstream_num)
.build() .build()
.unwrap(), .unwrap(),
), ),
lb_opts::RANDOM => LoadBalance::Random, lb_opts::STICKY_ROUND_ROBIN => LoadBalance::StickyRoundRobin(
lb_opts::STICKY_ROUND_ROBIN => LoadBalance::StickyRoundRobin, LbRoundRobinCountBuilder::default()
.max_val(upstream_num)
.build()
.unwrap(),
),
_ => { _ => {
error!("Specified load balancing option is invalid."); error!("Specified load balancing option is invalid.");
LoadBalance::default() LoadBalance::default()
@ -143,7 +148,7 @@ impl UpstreamGroup {
let max = self.upstream.len() - 1; let max = self.upstream.len() - 1;
self.upstream.get(rng.gen_range(0..max)) self.upstream.get(rng.gen_range(0..max))
} }
LoadBalance::StickyRoundRobin => todo!(), // TODO: TODO: LoadBalance::StickyRoundRobin(_cnt) => todo!(), // TODO: TODO:
} }
} }
} }