Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Nov 7, 2024
1 parent 644efb3 commit be17531
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
8 changes: 3 additions & 5 deletions grovedb/src/element/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Element {
let changed = previous_element
.as_ref()
.map(|p| !p.eq_no_backreferences(&to_insert))
.unwrap_or_default();
.unwrap_or(true);

if changed {
let has_references = to_insert.has_backward_references();
Expand Down Expand Up @@ -673,12 +673,11 @@ mod tests {

let batch = StorageBatch::new();
let mut merk = empty_path_merk(&*storage, &batch, &tx, grove_version);
let (inserted, previous) = Element::new_item(b"value2".to_vec())
let (_, previous) = Element::new_item(b"value2".to_vec())
.insert_if_changed_value(&mut merk, b"another-key", None, grove_version)
.unwrap()
.expect("expected successful insertion 2");

assert!(inserted);
assert_eq!(previous, Some(Element::new_item(b"value".to_vec())),);

storage
Expand All @@ -703,12 +702,11 @@ mod tests {
.insert(&mut merk, b"mykey", None, grove_version)
.unwrap()
.expect("expected successful insertion");
let (inserted, previous) = Element::new_item(b"value2".to_vec())
let (_, previous) = Element::new_item(b"value2".to_vec())
.insert_if_changed_value(&mut merk, b"another-key", None, grove_version)
.unwrap()
.expect("expected successful insertion 2");

assert!(inserted);
assert_eq!(previous, None);

assert_eq!(
Expand Down
43 changes: 22 additions & 21 deletions grovedb/src/operations/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 3, // 1 to get tree, 1 to insert, 1 to insert into root tree
seek_count: 4, /* 1 to get tree, 1 to check prev value for ref propagation, 1 to
* insert, 1 to insert into root tree */
storage_cost: StorageCost {
added_bytes: 149,
replaced_bytes: 0,
Expand Down Expand Up @@ -917,7 +918,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 5,
seek_count: 6,
storage_cost: StorageCost {
added_bytes: 170,
replaced_bytes: 84, // todo: verify
Expand Down Expand Up @@ -1000,7 +1001,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 7,
seek_count: 8,
storage_cost: StorageCost {
added_bytes: 170,
replaced_bytes: 217,
Expand Down Expand Up @@ -1079,7 +1080,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 7,
seek_count: 8,
storage_cost: StorageCost {
added_bytes: 170,
replaced_bytes: 217, // todo: verify
Expand Down Expand Up @@ -1140,7 +1141,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 3, // 1 to get tree, 1 to insert, 1 to insert into root tree
seek_count: 4, // 1 to get tree, 1 to insert, 1 to insert into root tree
storage_cost: StorageCost {
added_bytes: 153,
replaced_bytes: 0,
Expand Down Expand Up @@ -1405,7 +1406,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 5, // todo: verify this
seek_count: 6, // todo: verify this
storage_cost: StorageCost {
added_bytes: 150,
replaced_bytes: 78,
Expand Down Expand Up @@ -1470,7 +1471,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 3, // todo: verify this
seek_count: 4, // todo: verify this
storage_cost: StorageCost {
added_bytes: 156,
replaced_bytes: 0,
Expand Down Expand Up @@ -1564,7 +1565,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 5, // todo: verify this
seek_count: 6, // todo: verify this
storage_cost: StorageCost {
added_bytes: 156,
replaced_bytes: 78,
Expand Down Expand Up @@ -1660,7 +1661,7 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 5, // todo: verify this
seek_count: 6, // todo: verify this
storage_cost: StorageCost {
added_bytes: 156,
replaced_bytes: 82,
Expand Down Expand Up @@ -1729,13 +1730,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 3, // todo: verify this
seek_count: 4, // todo: verify this
storage_cost: StorageCost {
added_bytes: 0,
replaced_bytes: 112,
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 77,
storage_loaded_bytes: 124,
hash_node_calls: 2,
}
);
Expand Down Expand Up @@ -1783,13 +1784,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 6, // todo: verify this
seek_count: 7, // todo: verify this
storage_cost: StorageCost {
added_bytes: 0,
replaced_bytes: 190,
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 230, // todo verify this
storage_loaded_bytes: 277, // todo verify this
hash_node_calls: 8,
}
);
Expand Down Expand Up @@ -1837,13 +1838,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 6, // todo: verify this
seek_count: 7, // todo: verify this
storage_cost: StorageCost {
added_bytes: 0,
replaced_bytes: 248,
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 266, // todo verify this
storage_loaded_bytes: 411, // todo verify this
hash_node_calls: 9,
}
);
Expand Down Expand Up @@ -1903,13 +1904,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 9, // todo: verify this
seek_count: 10, // todo: verify this
storage_cost: StorageCost {
added_bytes: 0,
replaced_bytes: 409, // todo: verify this
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 487, // todo verify this
storage_loaded_bytes: 632, // todo verify this
hash_node_calls: 11,
}
);
Expand Down Expand Up @@ -1957,13 +1958,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 6, // todo: verify this
seek_count: 7, // todo: verify this
storage_cost: StorageCost {
added_bytes: 0,
replaced_bytes: 248,
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 276, // todo verify this
storage_loaded_bytes: 421, // todo verify this
hash_node_calls: 9,
}
);
Expand Down Expand Up @@ -2011,13 +2012,13 @@ mod tests {
assert_eq!(
cost,
OperationCost {
seek_count: 6, // todo: verify this
seek_count: 7, // todo: verify this
storage_cost: StorageCost {
added_bytes: 1,
replaced_bytes: 191, // todo: verify this
removed_bytes: NoStorageRemoval
},
storage_loaded_bytes: 231,
storage_loaded_bytes: 279,
hash_node_calls: 8,
}
);
Expand Down

0 comments on commit be17531

Please sign in to comment.