feat: Implement delete for the storage engine (#777)

* docs: Fix incorrect comment of Vector::only_null

* feat: Add delete to WriteRequest and WriteBatch

* feat: Filter deleted rows

* fix: Fix panic after reopening engine

This is detected by adding a reopen step to the delete test for region.

* fix: Fix OpType::min_type()

* test: Add delete absent key test

* chore: Address CR comments
This commit is contained in:
Yingwen
2022-12-30 17:12:18 +08:00
committed by GitHub
parent 6fe205f3b5
commit 4d56d896ca
24 changed files with 413 additions and 55 deletions

View File

@@ -31,6 +31,11 @@ pub trait WriteRequest: Send {
///
/// `data` is the columnar format of the data to put.
fn put(&mut self, data: HashMap<String, VectorRef>) -> Result<(), Self::Error>;
/// Delete rows by `keys`.
///
/// `keys` are the row keys, in columnar format, of the rows to delete.
fn delete(&mut self, keys: HashMap<String, VectorRef>) -> Result<(), Self::Error>;
}
#[derive(Default)]

View File

@@ -19,20 +19,27 @@
pub type SequenceNumber = u64;
/// Operation type of the value to write to storage.
///
/// The enum values are stored in the SST files so don't change
/// them if possible.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum OpType {
/// Delete operation.
Delete = 0,
/// Put operation.
Put,
Put = 1,
}
impl OpType {
/// Cast the [OpType] to u8.
#[inline]
pub fn as_u8(&self) -> u8 {
*self as u8
}
/// Minimal op type after casting to u8.
pub const fn min_type() -> OpType {
OpType::Put
OpType::Delete
}
}
@@ -42,7 +49,8 @@ mod tests {
#[test]
fn test_op_type() {
assert_eq!(0, OpType::Put.as_u8());
assert_eq!(0, OpType::Delete.as_u8());
assert_eq!(1, OpType::Put.as_u8());
assert_eq!(0, OpType::min_type().as_u8());
}
}