mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
Merge #4787
4787: Add index exists function in index_scheduler which stops opening indexes to only check if they exist. r=Kerollmops a=Karribalu # Pull Request ## Related issue Fixes #4784 ## What does this PR do? - Added index_exists function in the index_scheduler. - Resolved opening indexes to only check if they exist. - Made changes to existing tests to test this function. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: karribalu <karri.balu123456@gmail.com>
This commit is contained in:
commit
677ed6bbf6
@ -662,7 +662,11 @@ impl IndexScheduler {
|
|||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
self.index_mapper.index(&rtxn, name)
|
self.index_mapper.index(&rtxn, name)
|
||||||
}
|
}
|
||||||
|
/// Return the boolean referring if index exists.
|
||||||
|
pub fn index_exists(&self, name: &str) -> Result<bool> {
|
||||||
|
let rtxn = self.env.read_txn()?;
|
||||||
|
self.index_mapper.index_exists(&rtxn, name)
|
||||||
|
}
|
||||||
/// Return the name of all indexes without opening them.
|
/// Return the name of all indexes without opening them.
|
||||||
pub fn index_names(&self) -> Result<Vec<String>> {
|
pub fn index_names(&self) -> Result<Vec<String>> {
|
||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
@ -3795,15 +3799,15 @@ mod tests {
|
|||||||
]);
|
]);
|
||||||
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "after_processing_the_10_tasks");
|
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "after_processing_the_10_tasks");
|
||||||
|
|
||||||
// The index should not exists.
|
// The index should not exist.
|
||||||
snapshot!(format!("{}", index_scheduler.index("doggos").map(|_| ()).unwrap_err()), @"Index `doggos` not found.");
|
snapshot!(matches!(index_scheduler.index_exists("doggos"), Ok(true)), @"false");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_document_addition_cant_create_index_without_index_without_autobatching() {
|
fn test_document_addition_cant_create_index_without_index_without_autobatching() {
|
||||||
// We're going to execute multiple document addition that don't have
|
// We're going to execute multiple document addition that don't have
|
||||||
// the right to create an index while there is no index currently.
|
// the right to create an index while there is no index currently.
|
||||||
// Since the autobatching is disabled, every tasks should be processed
|
// Since the auto-batching is disabled, every task should be processed
|
||||||
// sequentially and throw an IndexDoesNotExists.
|
// sequentially and throw an IndexDoesNotExists.
|
||||||
let (index_scheduler, mut handle) = IndexScheduler::test(false, vec![]);
|
let (index_scheduler, mut handle) = IndexScheduler::test(false, vec![]);
|
||||||
|
|
||||||
@ -3845,8 +3849,8 @@ mod tests {
|
|||||||
handle.advance_n_failed_batches(5);
|
handle.advance_n_failed_batches(5);
|
||||||
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "all_tasks_processed");
|
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "all_tasks_processed");
|
||||||
|
|
||||||
// The index should not exists.
|
// The index should not exist.
|
||||||
snapshot!(format!("{}", index_scheduler.index("doggos").map(|_| ()).unwrap_err()), @"Index `doggos` not found.");
|
snapshot!(matches!(index_scheduler.index_exists("doggos"), Ok(true)), @"false");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -102,7 +102,7 @@ pub trait Analytics: Sync + Send {
|
|||||||
/// This method should be called to aggregate post facet values searches
|
/// This method should be called to aggregate post facet values searches
|
||||||
fn post_facet_search(&self, aggregate: FacetSearchAggregator);
|
fn post_facet_search(&self, aggregate: FacetSearchAggregator);
|
||||||
|
|
||||||
// this method should be called to aggregate a add documents request
|
// this method should be called to aggregate an add documents request
|
||||||
fn add_documents(
|
fn add_documents(
|
||||||
&self,
|
&self,
|
||||||
documents_query: &UpdateDocumentsQuery,
|
documents_query: &UpdateDocumentsQuery,
|
||||||
|
@ -305,7 +305,11 @@ pub async fn replace_documents(
|
|||||||
debug!(parameters = ?params, "Replace documents");
|
debug!(parameters = ?params, "Replace documents");
|
||||||
let params = params.into_inner();
|
let params = params.into_inner();
|
||||||
|
|
||||||
analytics.add_documents(¶ms, index_scheduler.index(&index_uid).is_err(), &req);
|
analytics.add_documents(
|
||||||
|
¶ms,
|
||||||
|
index_scheduler.index_exists(&index_uid).map_or(true, |x| !x),
|
||||||
|
&req,
|
||||||
|
);
|
||||||
|
|
||||||
let allow_index_creation = index_scheduler.filters().allow_index_creation(&index_uid);
|
let allow_index_creation = index_scheduler.filters().allow_index_creation(&index_uid);
|
||||||
let uid = get_task_id(&req, &opt)?;
|
let uid = get_task_id(&req, &opt)?;
|
||||||
@ -342,7 +346,11 @@ pub async fn update_documents(
|
|||||||
let params = params.into_inner();
|
let params = params.into_inner();
|
||||||
debug!(parameters = ?params, "Update documents");
|
debug!(parameters = ?params, "Update documents");
|
||||||
|
|
||||||
analytics.update_documents(¶ms, index_scheduler.index(&index_uid).is_err(), &req);
|
analytics.add_documents(
|
||||||
|
¶ms,
|
||||||
|
index_scheduler.index_exists(&index_uid).map_or(true, |x| !x),
|
||||||
|
&req,
|
||||||
|
);
|
||||||
|
|
||||||
let allow_index_creation = index_scheduler.filters().allow_index_creation(&index_uid);
|
let allow_index_creation = index_scheduler.filters().allow_index_creation(&index_uid);
|
||||||
let uid = get_task_id(&req, &opt)?;
|
let uid = get_task_id(&req, &opt)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user