From 886918cb958ba819ec9eb252c962066c74a7d95b Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Mon, 6 May 2024 17:24:37 +0200 Subject: [PATCH 1/5] Temporary constructor for the ChangeSet while migration --- src/cache/change_set.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cache/change_set.rs b/src/cache/change_set.rs index 5abd6b8..ee79363 100644 --- a/src/cache/change_set.rs +++ b/src/cache/change_set.rs @@ -25,6 +25,14 @@ impl ChangeSet { } } + /// Create new `ChangeSet + pub fn new_with_operations(id: SnapshotId, operations: SchemaBatch) -> Self { + Self { + id, operations + } + + } + /// Get value from its own cache pub fn get(&self, key: &impl KeyCodec) -> anyhow::Result> { self.operations.get(key) From 62ddb01da56825b5b095753df6a06e2da2d6adeb Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 8 May 2024 13:19:51 +0200 Subject: [PATCH 2/5] Public "get" for schema batch --- src/cache/change_set.rs | 5 +---- src/schema_batch.rs | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/cache/change_set.rs b/src/cache/change_set.rs index ee79363..9da375e 100644 --- a/src/cache/change_set.rs +++ b/src/cache/change_set.rs @@ -27,10 +27,7 @@ impl ChangeSet { /// Create new `ChangeSet pub fn new_with_operations(id: SnapshotId, operations: SchemaBatch) -> Self { - Self { - id, operations - } - + Self { id, operations } } /// Get value from its own cache diff --git a/src/schema_batch.rs b/src/schema_batch.rs index f47b716..0fca7d5 100644 --- a/src/schema_batch.rs +++ b/src/schema_batch.rs @@ -19,6 +19,7 @@ impl SchemaBatch { } /// Adds an insert/update operation to the batch. + // TODO: made this pub(crate) ??? pub fn put( &mut self, key: &impl KeyCodec, @@ -38,6 +39,7 @@ impl SchemaBatch { } /// Adds a delete operation to the batch. + // TODO: Make this pub(crate) pub fn delete(&mut self, key: &impl KeyCodec) -> anyhow::Result<()> { let key = key.encode_key()?; self.insert_operation::(key, Operation::Delete); @@ -50,10 +52,8 @@ impl SchemaBatch { column_writes.insert(key, operation); } - pub(crate) fn get( - &self, - key: &impl KeyCodec, - ) -> anyhow::Result> { + /// Getting the + pub fn get(&self, key: &impl KeyCodec) -> anyhow::Result> { let key = key.encode_key()?; if let Some(column_writes) = self.last_writes.get(&S::COLUMN_FAMILY_NAME) { From 6febf63f61bc775324b96dc1d1a0290b8a3d9e41 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 8 May 2024 13:28:49 +0200 Subject: [PATCH 3/5] get_value --- src/cache/change_set.rs | 2 +- src/lib.rs | 1 + src/schema_batch.rs | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cache/change_set.rs b/src/cache/change_set.rs index 9da375e..bbf36f1 100644 --- a/src/cache/change_set.rs +++ b/src/cache/change_set.rs @@ -32,7 +32,7 @@ impl ChangeSet { /// Get value from its own cache pub fn get(&self, key: &impl KeyCodec) -> anyhow::Result> { - self.operations.get(key) + self.operations.get_operation(key) } /// Get the ID of this [`ChangeSet`]. diff --git a/src/lib.rs b/src/lib.rs index 65e6220..94d4ecb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -313,6 +313,7 @@ pub type SchemaValue = Vec; /// Represents operation written to the database. #[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] #[derive(Debug, PartialEq, Eq, Hash, Clone)] +// TODO: Do we want "generic" operation, with 2 options: S::Value and SchemaValue? pub enum Operation { /// Writing a value to the DB. Put { diff --git a/src/schema_batch.rs b/src/schema_batch.rs index 0fca7d5..1c830ca 100644 --- a/src/schema_batch.rs +++ b/src/schema_batch.rs @@ -52,8 +52,11 @@ impl SchemaBatch { column_writes.insert(key, operation); } - /// Getting the - pub fn get(&self, key: &impl KeyCodec) -> anyhow::Result> { + /// Getting the operation from current schema batch if present + pub(crate) fn get_operation( + &self, + key: &impl KeyCodec, + ) -> anyhow::Result> { let key = key.encode_key()?; if let Some(column_writes) = self.last_writes.get(&S::COLUMN_FAMILY_NAME) { @@ -63,6 +66,17 @@ impl SchemaBatch { } } + /// Getting value by key if it was written in this batch. + /// Deleted operation will return None as well as missing key + pub fn get_value(&self, key: &impl KeyCodec) -> anyhow::Result> { + let operation = self.get_operation(key)?; + if let Some(operation) = operation { + let value = operation.decode_value::()?; + return Ok(value); + } + Ok(None) + } + /// Iterator over all values in lexicographic order. pub fn iter(&self) -> btree_map::Iter { self.last_writes @@ -319,7 +333,7 @@ mod tests { let get_value = |field: &TestField| -> Option { batch1 - .get::(field) + .get_operation::(field) .unwrap() .unwrap() .decode_value::() From 834a1db1f6467d633c1efa3e7fbcfd255de8aead Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Mon, 13 May 2024 17:45:01 +0200 Subject: [PATCH 4/5] Remove irrelevant todos --- src/schema_batch.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/schema_batch.rs b/src/schema_batch.rs index 1c830ca..604f1b6 100644 --- a/src/schema_batch.rs +++ b/src/schema_batch.rs @@ -19,7 +19,6 @@ impl SchemaBatch { } /// Adds an insert/update operation to the batch. - // TODO: made this pub(crate) ??? pub fn put( &mut self, key: &impl KeyCodec, @@ -39,7 +38,6 @@ impl SchemaBatch { } /// Adds a delete operation to the batch. - // TODO: Make this pub(crate) pub fn delete(&mut self, key: &impl KeyCodec) -> anyhow::Result<()> { let key = key.encode_key()?; self.insert_operation::(key, Operation::Delete); From 8d846ae1c07f13d72d866183998855d4b528d422 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Tue, 14 May 2024 20:26:28 +0200 Subject: [PATCH 5/5] Remove Todo --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 94d4ecb..65e6220 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -313,7 +313,6 @@ pub type SchemaValue = Vec; /// Represents operation written to the database. #[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] #[derive(Debug, PartialEq, Eq, Hash, Clone)] -// TODO: Do we want "generic" operation, with 2 options: S::Value and SchemaValue? pub enum Operation { /// Writing a value to the DB. Put {