Sharded cluster node roles

This commit is contained in:
mdecimus
2025-10-20 12:10:36 +02:00
parent a4720e1efe
commit 59ab6d91ab
10 changed files with 105 additions and 29 deletions

View File

@@ -4,11 +4,9 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use std::time::Duration;
use crate::expr::{if_block::IfBlock, tokenizer::TokenMap};
use ahash::AHashSet;
use std::time::Duration;
use utils::config::{Config, Rate, utils::ParseValue};
use super::*;
@@ -356,8 +354,8 @@ impl AsnGeoLookupConfig {
}
impl ClusterRole {
pub fn is_enabled(&self) -> bool {
matches!(self, ClusterRole::Enabled)
pub fn is_enabled_or_sharded(&self) -> bool {
matches!(self, ClusterRole::Enabled | ClusterRole::Sharded { .. })
}
pub fn is_enabled_for_account(&self, account_id: u32) -> bool {
@@ -370,4 +368,18 @@ impl ClusterRole {
} => (account_id % total_shards) == *shard_id,
}
}
pub fn is_enabled_for_hash(&self, item: &impl std::hash::Hash) -> bool {
match self {
ClusterRole::Enabled => true,
ClusterRole::Disabled => false,
ClusterRole::Sharded {
shard_id,
total_shards,
} => {
(ahash::RandomState::new().hash_one(item) % (*total_shards as u64))
== (*shard_id as u64)
}
}
}
}

View File

@@ -41,7 +41,10 @@ pub enum PurgeType {
store: InMemoryStore,
prefix: Option<Vec<u8>>,
},
Account(Option<u32>),
Account {
account_id: Option<u32>,
use_roles: bool,
},
}
#[derive(Debug)]