From 04319be5910567a492cb08db024088b019cec5fb Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu Date: Wed, 11 Oct 2023 15:10:39 +0100 Subject: [PATCH 1/4] update op ordering --- grovedb/src/batch/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 9724ea7b..a833a4da 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -175,10 +175,22 @@ impl PartialOrd for Op { impl Ord for Op { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { - (Op::Delete, Op::Insert { .. }) => Ordering::Less, - (Op::Delete, Op::Replace { .. }) => Ordering::Less, - (Op::Insert { .. }, Op::Delete) => Ordering::Greater, - (Op::Replace { .. }, Op::Delete) => Ordering::Greater, + // deal with relationship between delete ops + (Op::DeleteTree, Op::DeleteSumTree) | (Op::DeleteSumTree, Op::DeleteTree) => { + Ordering::Equal + } + (Op::DeleteTree, Op::Delete) => Ordering::Less, + (Op::Delete, Op::DeleteTree) => Ordering::Greater, + (Op::DeleteSumTree, Op::Delete) => Ordering::Less, + (Op::Delete, Op::DeleteSumTree) => Ordering::Greater, + + // deal with the relationship between delete and other ops + // delete should always happen first + (Op::Delete, _) => Ordering::Less, + (Op::DeleteSumTree, _) => Ordering::Less, + (Op::DeleteTree, _) => Ordering::Less, + + // all insert operations are considered equal _ => Ordering::Equal, } } From e814f9fb7c7cda5c215262cb4839ebbd9335c845 Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu Date: Wed, 11 Oct 2023 15:21:27 +0100 Subject: [PATCH 2/4] fix comment --- grovedb/src/batch/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index a833a4da..0b2d8a8d 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -175,7 +175,7 @@ impl PartialOrd for Op { impl Ord for Op { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { - // deal with relationship between delete ops + // deal with the relationship between delete ops (Op::DeleteTree, Op::DeleteSumTree) | (Op::DeleteSumTree, Op::DeleteTree) => { Ordering::Equal } @@ -190,7 +190,7 @@ impl Ord for Op { (Op::DeleteSumTree, _) => Ordering::Less, (Op::DeleteTree, _) => Ordering::Less, - // all insert operations are considered equal + // all other operations are considered equal _ => Ordering::Equal, } } From 51dce4be542992ad95797b9a96d4bd56dfa1cb0b Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu Date: Wed, 11 Oct 2023 15:53:39 +0100 Subject: [PATCH 3/4] do fixed ordering, remove equality --- grovedb/src/batch/mod.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 0b2d8a8d..f40c905d 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -166,6 +166,22 @@ pub enum Op { DeleteSumTree, } +impl Op { + fn to_u8(&self) -> u8 { + match self { + Op::DeleteTree => 0, + Op::DeleteSumTree => 1, + Op::Delete => 2, + Op::InsertTreeWithRootHash {..} => 3, + Op::ReplaceTreeRootKey {..} => 4, + Op::RefreshReference {..} => 5, + Op::Replace {..} => 6, + Op::Patch {..} => 7, + Op::Insert {..} => 8 + } + } +} + impl PartialOrd for Op { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) @@ -174,25 +190,7 @@ impl PartialOrd for Op { impl Ord for Op { fn cmp(&self, other: &Self) -> Ordering { - match (self, other) { - // deal with the relationship between delete ops - (Op::DeleteTree, Op::DeleteSumTree) | (Op::DeleteSumTree, Op::DeleteTree) => { - Ordering::Equal - } - (Op::DeleteTree, Op::Delete) => Ordering::Less, - (Op::Delete, Op::DeleteTree) => Ordering::Greater, - (Op::DeleteSumTree, Op::Delete) => Ordering::Less, - (Op::Delete, Op::DeleteSumTree) => Ordering::Greater, - - // deal with the relationship between delete and other ops - // delete should always happen first - (Op::Delete, _) => Ordering::Less, - (Op::DeleteSumTree, _) => Ordering::Less, - (Op::DeleteTree, _) => Ordering::Less, - - // all other operations are considered equal - _ => Ordering::Equal, - } + self.to_u8().cmp(&other.to_u8()) } } From 078061498276a0649bd14cead6b185c2f9c760bd Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu Date: Wed, 11 Oct 2023 15:55:12 +0100 Subject: [PATCH 4/4] fmt --- grovedb/src/batch/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index f40c905d..8f275095 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -172,12 +172,12 @@ impl Op { Op::DeleteTree => 0, Op::DeleteSumTree => 1, Op::Delete => 2, - Op::InsertTreeWithRootHash {..} => 3, - Op::ReplaceTreeRootKey {..} => 4, - Op::RefreshReference {..} => 5, - Op::Replace {..} => 6, - Op::Patch {..} => 7, - Op::Insert {..} => 8 + Op::InsertTreeWithRootHash { .. } => 3, + Op::ReplaceTreeRootKey { .. } => 4, + Op::RefreshReference { .. } => 5, + Op::Replace { .. } => 6, + Op::Patch { .. } => 7, + Op::Insert { .. } => 8, } } }