mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-09-03 18:55:41 +00:00
New model for buckets
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use garage_util::crdt::*;
|
||||
|
||||
/// Permission given to a key in a bucket
|
||||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub struct BucketKeyPerm {
|
||||
/// Timestamp at which the permission was given
|
||||
pub timestamp: u64,
|
||||
|
||||
/// The key can be used to read the bucket
|
||||
pub allow_read: bool,
|
||||
/// The key can be used to write in the bucket
|
||||
pub allow_write: bool,
|
||||
}
|
||||
|
||||
impl Crdt for BucketKeyPerm {
|
||||
fn merge(&mut self, other: &Self) {
|
||||
match other.timestamp.cmp(&self.timestamp) {
|
||||
Ordering::Greater => {
|
||||
*self = *other;
|
||||
}
|
||||
Ordering::Equal if other != self => {
|
||||
warn!("Different permission sets with same timestamp: {:?} and {:?}, merging to most restricted permission set.", self, other);
|
||||
if !other.allow_read {
|
||||
self.allow_read = false;
|
||||
}
|
||||
if !other.allow_write {
|
||||
self.allow_write = false;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user