mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-29 11:20:38 +00:00
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:
@@ -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)]
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user