From d885de16002e4c8aaf58602078cf8f88240b4d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 21 Sep 2022 17:16:11 +0200 Subject: [PATCH] Add option to avoid soft deletion of documents --- milli/src/update/delete_documents.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index de2f4480c..2626c1555 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -26,6 +26,8 @@ pub struct DeleteDocuments<'t, 'u, 'i> { index: &'i Index, external_documents_ids: ExternalDocumentsIds<'static>, to_delete_docids: RoaringBitmap, + #[cfg(test)] + disable_soft_delete: bool, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -46,9 +48,16 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { index, external_documents_ids, to_delete_docids: RoaringBitmap::new(), + #[cfg(test)] + disable_soft_delete: false, }) } + #[cfg(test)] + fn disable_soft_delete(&mut self, disable: bool) { + self.disable_soft_delete = disable; + } + pub fn delete_document(&mut self, docid: u32) { self.to_delete_docids.insert(docid); } @@ -147,7 +156,20 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { // We run the deletion. // - With 100Go of disk and 50Go used including 15Go of soft-deleted documents // We run the deletion. - if percentage_available > 10 && percentage_used_by_soft_deleted_documents < 10 { + let disable_soft_delete = { + #[cfg(not(test))] + { + false + } + #[cfg(test)] + { + self.disable_soft_delete + } + }; + if !disable_soft_delete + && percentage_available > 10 + && percentage_used_by_soft_deleted_documents < 10 + { self.index.put_soft_deleted_documents_ids(self.wtxn, &soft_deleted_docids)?; return Ok(DocumentDeletionResult { deleted_documents: self.to_delete_docids.len(),