Skip to content

Commit

Permalink
no versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aeyakovenko committed Nov 4, 2018
1 parent 08c838b commit aab08ce
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ use std::cmp;
pub struct Crds {
/// Stores the map of labels and values
pub table: IndexMap<CrdsValueLabel, VersionedCrdsValue>,

/// the version of the `table`
/// every change to `table` should increase this version number
pub version: u64,
}

#[derive(PartialEq, Debug)]
Expand All @@ -55,8 +51,6 @@ pub struct VersionedCrdsValue {
pub insert_timestamp: u64,
/// local time when updated
pub local_timestamp: u64,
/// local crds version when added
local_version: u64,
/// value hash
pub value_hash: Hash,
}
Expand All @@ -75,13 +69,12 @@ impl PartialOrd for VersionedCrdsValue {
}
}
impl VersionedCrdsValue {
pub fn new(local_timestamp: u64, version: u64, value: CrdsValue) -> Self {
pub fn new(local_timestamp: u64, value: CrdsValue) -> Self {
let value_hash = hash(&serialize(&value).unwrap());
VersionedCrdsValue {
value,
insert_timestamp: local_timestamp,
local_timestamp,
local_version: version,
value_hash,
}
}
Expand All @@ -91,15 +84,14 @@ impl Default for Crds {
fn default() -> Self {
Crds {
table: IndexMap::new(),
version: 0,
}
}
}

impl Crds {
/// must be called atomically with `insert_versioned`
pub fn new_versioned(&self, local_timestamp: u64, value: CrdsValue) -> VersionedCrdsValue {
VersionedCrdsValue::new(local_timestamp, self.version, value)
VersionedCrdsValue::new(local_timestamp, value)
}
/// insert the new value, returns the old value if insert succeeds
pub fn insert_versioned(
Expand All @@ -114,7 +106,6 @@ impl Crds {
.map(|current| new_value > *current)
.unwrap_or(true);
if do_insert {
self.version += 1;
let old = self.table.insert(label, new_value);
Ok(old)
} else {
Expand Down Expand Up @@ -214,11 +205,9 @@ mod test {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
assert_eq!(crds.insert(val.clone(), 0).ok(), Some(None));
assert_eq!(crds.version, 1);
assert_eq!(crds.table.len(), 1);
assert!(crds.table.contains_key(&val.label()));
assert_eq!(crds.table[&val.label()].local_timestamp, 0);
assert_eq!(crds.table[&val.label()].local_version, crds.version - 1);
}
#[test]
fn test_update_old() {
Expand All @@ -227,8 +216,6 @@ mod test {
assert_eq!(crds.insert(val.clone(), 0), Ok(None));
assert_eq!(crds.insert(val.clone(), 1), Err(CrdsError::InsertFailed));
assert_eq!(crds.table[&val.label()].local_timestamp, 0);
assert_eq!(crds.table[&val.label()].local_version, crds.version - 1);
assert_eq!(crds.version, 1);
}
#[test]
fn test_update_new() {
Expand All @@ -245,8 +232,6 @@ mod test {
original
);
assert_eq!(crds.table[&val.label()].local_timestamp, 1);
assert_eq!(crds.table[&val.label()].local_version, crds.version - 1);
assert_eq!(crds.version, 2);
}
#[test]
fn test_update_timestsamp() {
Expand Down Expand Up @@ -303,7 +288,6 @@ mod test {
fn test_equal() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -312,7 +296,6 @@ mod test {
}),
);
let v2 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -327,7 +310,6 @@ mod test {
fn test_hash_order() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -336,7 +318,6 @@ mod test {
}),
);
let v2 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -356,7 +337,6 @@ mod test {
fn test_wallclock_order() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -365,7 +345,6 @@ mod test {
}),
);
let v2 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: key.pubkey(),
Expand All @@ -381,7 +360,6 @@ mod test {
#[test]
fn test_label_order() {
let v1 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: Keypair::new().pubkey(),
Expand All @@ -390,7 +368,6 @@ mod test {
}),
);
let v2 = VersionedCrdsValue::new(
1,
1,
CrdsValue::LeaderId(LeaderId {
id: Keypair::new().pubkey(),
Expand Down

0 comments on commit aab08ce

Please sign in to comment.