-
Notifications
You must be signed in to change notification settings - Fork 23
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
[cleanup] Introduce proper key'ing type for our Limit
& Counter
#328
Comments
So I'm getting a little stuck here… This led me to refactor the pub trait CounterStorage: Sync + Send {
fn add_counters(&self, keys: &[CounterKey]) -> Result<(), StorageErr>;
fn get_counters(&self, keys: &[CounterKey]) -> Result<Vec<(u64, Duration)>, StorageErr>;
fn update_counters(&self, key: &[CounterKey], delta: u64) -> Result<Vec<(u64, Duration)>, StorageErr>;
fn delete_counters(&self, keys: &[CounterKey]) -> Result<(), StorageErr>;
fn clear(&self) -> Result<(), StorageErr>;
// This is where things get … interesting.
fn check_and_update(
&self,
counters: &[CounterKey],
delta: u64,
) -> Result<Authorization, StorageErr>;
fn check_and_update_loading(
&self,
counters: &[CounterKey],
delta: u64,
) -> Result<(Authorization, Vec<Counter>), StorageErr>;
} These So my dilemma here is: either we make embrace this race and just have the caller either wdyt? For the curious, here is what I was thinking a pub enum CounterKey {
Identified((Namespace, String)),
Simple((Namespace, SimpleCounterKey)),
Qualified((Namespace, SimpleCounterKey, Vec<String>)),
}
impl CounterKey {
fn namespace(&self) -> &Namespace {
match self {
CounterKey::Identified((ns, _)) => ns,
CounterKey::Simple((ns, _)) => ns,
CounterKey::Qualified((ns, _, _)) => ns,
}
}
}
impl Eq for CounterKey {}
impl PartialEq<Self> for CounterKey {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl PartialOrd<Self> for CounterKey {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for CounterKey {
fn cmp(&self, other: &Self) -> Ordering {
match self.namespace().cmp(other.namespace()) {
Ordering::Equal => {
match self {
CounterKey::Identified((_, id)) => {
match other {
CounterKey::Identified((_, other)) => id.cmp(other),
_ => Ordering::Less,
}
}
CounterKey::Simple((_, key)) => {
match other {
CounterKey::Identified(_) => Ordering::Greater,
CounterKey::Simple((_, other)) => key.cmp(other),
CounterKey::Qualified(_) => Ordering::Less,
}
}
CounterKey::Qualified((_, key, qualifiers)) => {
match other {
CounterKey::Identified(_) => Ordering::Greater,
CounterKey::Simple(_) => Ordering::Greater,
CounterKey::Qualified((_, other_key, other_qualifiers)) => {
match key.cmp(other_key) {
Ordering::Equal => qualifiers.cmp(other_qualifiers),
other => other,
}
}
}
}
}
},
other => other,
}
}
}
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct SimpleCounterKey {
seconds: u64,
conditions: Vec<String>,
}
impl From<&Limit> for CounterKey {
fn from(limit: &Limit) -> Self {
let mut conditions = Vec::from(limit.conditions());
conditions.sort();
let mut variables = Vec::from(limit.variables());
variables.sort();
Self {
namespace: limit.namespace().clone(),
seconds: limit.seconds(),
conditions,
variables,
}
}
} |
My take on this would be |
It's less about it happening than "forcing" all implementation of the |
rather than the hybrid model we currently use that has led to multiple issues in the past.
In Kuadrant, we probably want to leverage the #356 identity field always
The text was updated successfully, but these errors were encountered: