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

Commit 2101e3c

Browse files
bors[bot]ManyTheFishloiclec
authored
Merge #739
739: Cherry pick bug fixes for v0.37.3 r=curquiza a=curquiza Integrate #734 and #737 into the `release-v0.37.3` branch to avoid to release on `main` <s>Wait for meilisearch/meilisearch#3235 investigation without merging this PR. Indeed, if a bug fix on milli's side, we might wait for it before merging this PR/</s> -> no need to wait, not a bug Co-authored-by: ManyTheFish <[email protected]> Co-authored-by: Loïc Lecrenier <[email protected]>
2 parents 74322ec + 3c97f62 commit 2101e3c

File tree

5 files changed

+123
-12
lines changed

5 files changed

+123
-12
lines changed

milli/src/index.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,4 +2111,80 @@ pub(crate) mod tests {
21112111
"###);
21122112
db_snap!(index, soft_deleted_documents_ids, 6, @"[]");
21132113
}
2114+
2115+
#[test]
2116+
fn bug_3021_third() {
2117+
// https://github.com/meilisearch/meilisearch/issues/3021
2118+
let mut index = TempIndex::new();
2119+
index.index_documents_config.update_method = IndexDocumentsMethod::UpdateDocuments;
2120+
2121+
index
2122+
.update_settings(|settings| {
2123+
settings.set_primary_key("primary_key".to_owned());
2124+
})
2125+
.unwrap();
2126+
2127+
index
2128+
.add_documents(documents!([
2129+
{ "primary_key": 3 },
2130+
{ "primary_key": 4 },
2131+
{ "primary_key": 5 }
2132+
]))
2133+
.unwrap();
2134+
2135+
db_snap!(index, documents_ids, @"[0, 1, 2, ]");
2136+
db_snap!(index, external_documents_ids, 1, @r###"
2137+
soft:
2138+
hard:
2139+
3 0
2140+
4 1
2141+
5 2
2142+
"###);
2143+
db_snap!(index, soft_deleted_documents_ids, 1, @"[]");
2144+
2145+
let mut wtxn = index.write_txn().unwrap();
2146+
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
2147+
delete.delete_external_id("3");
2148+
delete.execute().unwrap();
2149+
wtxn.commit().unwrap();
2150+
2151+
db_snap!(index, documents_ids, @"[1, 2, ]");
2152+
db_snap!(index, external_documents_ids, 2, @r###"
2153+
soft:
2154+
hard:
2155+
3 0
2156+
4 1
2157+
5 2
2158+
"###);
2159+
db_snap!(index, soft_deleted_documents_ids, 2, @"[0, ]");
2160+
2161+
index.index_documents_config.disable_soft_deletion = true;
2162+
2163+
index.add_documents(documents!([{ "primary_key": "4", "a": 2 }])).unwrap();
2164+
2165+
db_snap!(index, documents_ids, @"[2, 3, ]");
2166+
db_snap!(index, external_documents_ids, 2, @r###"
2167+
soft:
2168+
hard:
2169+
4 3
2170+
5 2
2171+
"###);
2172+
db_snap!(index, soft_deleted_documents_ids, 2, @"[]");
2173+
2174+
index
2175+
.add_documents(documents!([
2176+
{ "primary_key": "3" },
2177+
]))
2178+
.unwrap();
2179+
2180+
db_snap!(index, documents_ids, @"[0, 2, 3, ]");
2181+
db_snap!(index, external_documents_ids, 2, @r###"
2182+
soft:
2183+
hard:
2184+
3 0
2185+
4 3
2186+
5 2
2187+
"###);
2188+
db_snap!(index, soft_deleted_documents_ids, 2, @"[]");
2189+
}
21142190
}

milli/src/search/criteria/typo.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ impl<'t> Criterion for Typo<'t> {
141141
filtered_candidates,
142142
initial_candidates,
143143
}) => {
144-
self.initial_candidates = initial_candidates;
144+
self.initial_candidates =
145+
match (self.initial_candidates.take(), initial_candidates) {
146+
(Some(self_ic), Some(parent_ic)) => Some(self_ic | parent_ic),
147+
(self_ic, parent_ic) => self_ic.or(parent_ic),
148+
};
149+
145150
let candidates = match candidates.or(filtered_candidates) {
146151
Some(candidates) => {
147152
Candidates::Allowed(candidates - params.excluded_candidates)

milli/src/search/criteria/words.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl<'t> Criterion for Words<'t> {
7474

7575
self.initial_candidates =
7676
match (self.initial_candidates.take(), initial_candidates) {
77-
(Some(self_bc), Some(parent_bc)) => Some(self_bc | parent_bc),
78-
(self_bc, parent_bc) => self_bc.or(parent_bc),
77+
(Some(self_ic), Some(parent_ic)) => Some(self_ic | parent_ic),
78+
(self_ic, parent_ic) => self_ic.or(parent_ic),
7979
};
8080
}
8181
Some(CriterionResult {

milli/src/update/delete_documents.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,24 @@ pub struct DeleteDocuments<'t, 'u, 'i> {
2929
disable_soft_deletion: bool,
3030
}
3131

32+
/// Result of a [`DeleteDocuments`] operation.
3233
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3334
pub struct DocumentDeletionResult {
3435
pub deleted_documents: u64,
3536
pub remaining_documents: u64,
3637
}
3738

39+
/// Result of a [`DeleteDocuments`] operation, used for internal purposes.
40+
///
41+
/// It is a superset of the [`DocumentDeletionResult`] structure, giving
42+
/// additional information about the algorithm used to delete the documents.
43+
#[derive(Debug)]
44+
pub(crate) struct DetailedDocumentDeletionResult {
45+
pub deleted_documents: u64,
46+
pub remaining_documents: u64,
47+
pub soft_deletion_used: bool,
48+
}
49+
3850
impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
3951
pub fn new(
4052
wtxn: &'t mut heed::RwTxn<'i, 'u>,
@@ -68,8 +80,16 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
6880
self.delete_document(docid);
6981
Some(docid)
7082
}
71-
72-
pub fn execute(mut self) -> Result<DocumentDeletionResult> {
83+
pub fn execute(self) -> Result<DocumentDeletionResult> {
84+
let DetailedDocumentDeletionResult {
85+
deleted_documents,
86+
remaining_documents,
87+
soft_deletion_used: _,
88+
} = self.execute_inner()?;
89+
90+
Ok(DocumentDeletionResult { deleted_documents, remaining_documents })
91+
}
92+
pub(crate) fn execute_inner(mut self) -> Result<DetailedDocumentDeletionResult> {
7393
self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?;
7494

7595
// We retrieve the current documents ids that are in the database.
@@ -83,7 +103,11 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
83103
if !soft_deleted_docids.is_empty() {
84104
ClearDocuments::new(self.wtxn, self.index).execute()?;
85105
}
86-
return Ok(DocumentDeletionResult { deleted_documents: 0, remaining_documents: 0 });
106+
return Ok(DetailedDocumentDeletionResult {
107+
deleted_documents: 0,
108+
remaining_documents: 0,
109+
soft_deletion_used: false,
110+
});
87111
}
88112

89113
// We remove the documents ids that we want to delete
@@ -95,9 +119,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
95119
// to delete is exactly the number of documents in the database.
96120
if current_documents_ids_len == self.to_delete_docids.len() {
97121
let remaining_documents = ClearDocuments::new(self.wtxn, self.index).execute()?;
98-
return Ok(DocumentDeletionResult {
122+
return Ok(DetailedDocumentDeletionResult {
99123
deleted_documents: current_documents_ids_len,
100124
remaining_documents,
125+
soft_deletion_used: false,
101126
});
102127
}
103128

@@ -159,9 +184,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
159184
&& percentage_used_by_soft_deleted_documents < 10
160185
{
161186
self.index.put_soft_deleted_documents_ids(self.wtxn, &soft_deleted_docids)?;
162-
return Ok(DocumentDeletionResult {
187+
return Ok(DetailedDocumentDeletionResult {
163188
deleted_documents: self.to_delete_docids.len(),
164189
remaining_documents: documents_ids.len(),
190+
soft_deletion_used: true,
165191
});
166192
}
167193

@@ -488,9 +514,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
488514
&self.to_delete_docids,
489515
)?;
490516

491-
Ok(DocumentDeletionResult {
517+
Ok(DetailedDocumentDeletionResult {
492518
deleted_documents: self.to_delete_docids.len(),
493519
remaining_documents: documents_ids.len(),
520+
soft_deletion_used: false,
494521
})
495522
}
496523
}

milli/src/update/index_documents/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ where
210210
primary_key,
211211
fields_ids_map,
212212
field_distribution,
213-
external_documents_ids,
213+
mut external_documents_ids,
214214
new_documents_ids,
215215
replaced_documents_ids,
216216
documents_count,
@@ -335,8 +335,11 @@ where
335335
deletion_builder.disable_soft_deletion(self.config.disable_soft_deletion);
336336
debug!("documents to delete {:?}", replaced_documents_ids);
337337
deletion_builder.delete_documents(&replaced_documents_ids);
338-
let deleted_documents_count = deletion_builder.execute()?;
339-
debug!("{} documents actually deleted", deleted_documents_count.deleted_documents);
338+
let deleted_documents_result = deletion_builder.execute_inner()?;
339+
debug!("{} documents actually deleted", deleted_documents_result.deleted_documents);
340+
if !deleted_documents_result.soft_deletion_used {
341+
external_documents_ids.delete_soft_deleted_documents_ids_from_fsts()?;
342+
}
340343
}
341344

342345
let index_documents_ids = self.index.documents_ids(self.wtxn)?;

0 commit comments

Comments
 (0)