Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit fc7618d

Browse files
committed
Add DeletionStrategy
1 parent 5114686 commit fc7618d

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

milli/src/update/delete_documents.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct DeleteDocuments<'t, 'u, 'i> {
2626
index: &'i Index,
2727
external_documents_ids: ExternalDocumentsIds<'static>,
2828
to_delete_docids: RoaringBitmap,
29-
disable_soft_deletion: bool,
29+
strategy: DeletionStrategy,
3030
}
3131

3232
/// Result of a [`DeleteDocuments`] operation.
@@ -36,6 +36,36 @@ pub struct DocumentDeletionResult {
3636
pub remaining_documents: u64,
3737
}
3838

39+
/// Strategy for deleting documents.
40+
///
41+
/// - Soft-deleted documents are simply marked as deleted without being actually removed from DB.
42+
/// - Hard-deleted documents are definitely suppressed from the DB.
43+
///
44+
/// Soft-deleted documents trade disk space for runtime performance.
45+
///
46+
/// Note that any of these variants can be used at any given moment for any indexation in a database.
47+
/// For instance, you can use an [`AlwaysSoft`] followed by an [`AlwaysHard`] option without issue.
48+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
49+
pub enum DeletionStrategy {
50+
#[default]
51+
/// Definitely suppress documents according to the number of size of soft-deleted documents
52+
Dynamic,
53+
/// Never definitely suppress documents
54+
AlwaysSoft,
55+
/// Always definitely suppress documents
56+
AlwaysHard,
57+
}
58+
59+
impl std::fmt::Display for DeletionStrategy {
60+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61+
match self {
62+
DeletionStrategy::Dynamic => write!(f, "dynamic"),
63+
DeletionStrategy::AlwaysSoft => write!(f, "always_soft"),
64+
DeletionStrategy::AlwaysHard => write!(f, "always_hard"),
65+
}
66+
}
67+
}
68+
3969
/// Result of a [`DeleteDocuments`] operation, used for internal purposes.
4070
///
4171
/// It is a superset of the [`DocumentDeletionResult`] structure, giving
@@ -59,12 +89,12 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
5989
index,
6090
external_documents_ids,
6191
to_delete_docids: RoaringBitmap::new(),
62-
disable_soft_deletion: false,
92+
strategy: Default::default(),
6393
})
6494
}
6595

66-
pub fn disable_soft_deletion(&mut self, disable: bool) {
67-
self.disable_soft_deletion = disable;
96+
pub fn strategy(&mut self, strategy: DeletionStrategy) {
97+
self.strategy = strategy;
6898
}
6999

70100
pub fn delete_document(&mut self, docid: u32) {

milli/src/update/index_documents/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use crate::documents::{obkv_to_object, DocumentsBatchReader};
3535
use crate::error::{Error, InternalError, UserError};
3636
pub use crate::update::index_documents::helpers::CursorClonableMmap;
3737
use crate::update::{
38-
self, IndexerConfig, PrefixWordPairsProximityDocids, UpdateIndexingStep, WordPrefixDocids,
39-
WordPrefixPositionDocids, WordsPrefixesFst,
38+
self, DeletionStrategy, IndexerConfig, PrefixWordPairsProximityDocids, UpdateIndexingStep,
39+
WordPrefixDocids, WordPrefixPositionDocids, WordsPrefixesFst,
4040
};
4141
use crate::{Index, Result, RoaringBitmapCodec};
4242

@@ -88,7 +88,7 @@ pub struct IndexDocumentsConfig {
8888
pub words_positions_level_group_size: Option<NonZeroU32>,
8989
pub words_positions_min_level_size: Option<NonZeroU32>,
9090
pub update_method: IndexDocumentsMethod,
91-
pub disable_soft_deletion: bool,
91+
pub deletion_strategy: DeletionStrategy,
9292
pub autogenerate_docids: bool,
9393
}
9494

@@ -332,7 +332,7 @@ where
332332
// able to simply insert all the documents even if they already exist in the database.
333333
if !replaced_documents_ids.is_empty() {
334334
let mut deletion_builder = update::DeleteDocuments::new(self.wtxn, self.index)?;
335-
deletion_builder.disable_soft_deletion(self.config.disable_soft_deletion);
335+
deletion_builder.strategy(self.config.deletion_strategy);
336336
debug!("documents to delete {:?}", replaced_documents_ids);
337337
deletion_builder.delete_documents(&replaced_documents_ids);
338338
let deleted_documents_result = deletion_builder.execute_inner()?;

milli/src/update/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub use self::available_documents_ids::AvailableDocumentsIds;
22
pub use self::clear_documents::ClearDocuments;
3-
pub use self::delete_documents::{DeleteDocuments, DocumentDeletionResult};
3+
pub use self::delete_documents::{DeleteDocuments, DeletionStrategy, DocumentDeletionResult};
44
pub use self::facet::bulk::FacetsUpdateBulk;
55
pub use self::facet::incremental::FacetsUpdateIncrementalInner;
66
pub use self::index_documents::{

0 commit comments

Comments
 (0)