diff --git a/benchmarks/benches/indexing.rs b/benchmarks/benches/indexing.rs index 0c19b89cf..bebf11ba0 100644 --- a/benchmarks/benches/indexing.rs +++ b/benchmarks/benches/indexing.rs @@ -32,7 +32,7 @@ fn setup_index() -> Index { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.max_readers(10); - Index::new(options, path).unwrap() + Index::new(None, options, path).unwrap() } fn setup_settings<'t>( diff --git a/benchmarks/benches/utils.rs b/benchmarks/benches/utils.rs index b848560ad..ab52a9a6a 100644 --- a/benchmarks/benches/utils.rs +++ b/benchmarks/benches/utils.rs @@ -66,7 +66,7 @@ pub fn base_setup(conf: &Conf) -> Index { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.max_readers(10); - let index = Index::new(options, conf.database_name).unwrap(); + let index = Index::new(None, options, conf.database_name).unwrap(); let config = IndexerConfig::default(); let mut wtxn = index.write_txn().unwrap(); diff --git a/fuzzers/src/bin/fuzz-indexing.rs b/fuzzers/src/bin/fuzz-indexing.rs index baf705709..608933016 100644 --- a/fuzzers/src/bin/fuzz-indexing.rs +++ b/fuzzers/src/bin/fuzz-indexing.rs @@ -56,7 +56,7 @@ fn main() { Some(path) => TempDir::new_in(path).unwrap(), None => TempDir::new().unwrap(), }; - let index = Index::new(options, tempdir.path()).unwrap(); + let index = Index::new(None, options, tempdir.path()).unwrap(); let indexer_config = IndexerConfig::default(); let index_documents_config = IndexDocumentsConfig::default(); diff --git a/index-scheduler/src/index_mapper/index_map.rs b/index-scheduler/src/index_mapper/index_map.rs index f8080d23b..c3873e465 100644 --- a/index-scheduler/src/index_mapper/index_map.rs +++ b/index-scheduler/src/index_mapper/index_map.rs @@ -103,7 +103,7 @@ impl ReopenableIndex { return Ok(()); } map.unavailable.remove(&self.uuid); - map.create(&self.uuid, path, None, self.enable_mdb_writemap, self.map_size)?; + map.create(None, &self.uuid, path, None, self.enable_mdb_writemap, self.map_size)?; } Ok(()) } @@ -167,6 +167,7 @@ impl IndexMap { /// pub fn create( &mut self, + name: Option, uuid: &Uuid, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, @@ -176,7 +177,7 @@ impl IndexMap { if !matches!(self.get_unavailable(uuid), Missing) { panic!("Attempt to open an index that was unavailable"); } - let index = create_or_open_index(path, date, enable_mdb_writemap, map_size)?; + let index = create_or_open_index(name, path, date, enable_mdb_writemap, map_size)?; match self.available.insert(*uuid, index.clone()) { InsertionOutcome::InsertedNew => (), InsertionOutcome::Evicted(evicted_uuid, evicted_index) => { @@ -296,6 +297,7 @@ impl IndexMap { /// Create or open an index in the specified path. /// The path *must* exist or an error will be thrown. fn create_or_open_index( + name: Option, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, enable_mdb_writemap: bool, @@ -309,9 +311,9 @@ fn create_or_open_index( } if let Some((created, updated)) = date { - Ok(Index::new_with_creation_dates(options, path, created, updated)?) + Ok(Index::new_with_creation_dates(name, options, path, created, updated)?) } else { - Ok(Index::new(options, path)?) + Ok(Index::new(name, options, path)?) } } diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 14908120c..245de8363 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -182,6 +182,7 @@ impl IndexMapper { // This is very unlikely to happen in practice. // TODO: it would be better to lazily create the index. But we need an Index::open function for milli. let index = self.index_map.write().unwrap().create( + Some(name.to_string()), &uuid, &index_path, date, @@ -371,6 +372,7 @@ impl IndexMapper { let index_path = self.base_path.join(uuid.to_string()); break index_map.create( + Some(name.to_string()), &uuid, &index_path, None, diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index adb3d4942..4640058d7 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -282,6 +282,9 @@ pub struct IndexSchedulerOptions { /// Structure which holds meilisearch's indexes and schedules the tasks /// to be performed on them. pub struct IndexScheduler { + /// A String representing the name of the index + pub(crate) name: String, + /// The LMDB environment which the DBs are associated with. pub(crate) env: Env, diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 8be70d162..697156450 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -882,7 +882,7 @@ async fn sort_unsortable_attribute() { index.wait_task(1).await; let expected_response = json!({ - "message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.", + "message": "Attribute `title` of index `test` is not sortable. Available sortable attributes are: `id`.", "code": "invalid_search_sort", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_search_sort" diff --git a/meilitool/src/main.rs b/meilitool/src/main.rs index f199df216..1cbab32c5 100644 --- a/meilitool/src/main.rs +++ b/meilitool/src/main.rs @@ -267,7 +267,7 @@ fn export_a_dump( for result in index_mapping.iter(&rtxn)? { let (uid, uuid) = result?; let index_path = db_path.join("indexes").join(uuid.to_string()); - let index = Index::new(EnvOpenOptions::new(), &index_path).with_context(|| { + let index = Index::new(None, EnvOpenOptions::new(), &index_path).with_context(|| { format!("While trying to open the index at path {:?}", index_path.display()) })?; diff --git a/milli/examples/index.rs b/milli/examples/index.rs index 781440b56..466c0a853 100644 --- a/milli/examples/index.rs +++ b/milli/examples/index.rs @@ -41,7 +41,7 @@ fn main() -> Result<(), Box> { options.map_size(100 * 1024 * 1024 * 1024); // 100 GB std::fs::create_dir_all(&index_path).unwrap(); - let index = Index::new(options, index_path).unwrap(); + let index = Index::new(Some(program_name), options, index_path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/examples/search.rs b/milli/examples/search.rs index a94677771..1b31b8bf5 100644 --- a/milli/examples/search.rs +++ b/milli/examples/search.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), Box> { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB - let index = Index::new(options, dataset)?; + let index = Index::new(Some(program_name), options, dataset)?; let txn = index.read_txn()?; let mut query = String::new(); while stdin().read_line(&mut query)? > 0 { diff --git a/milli/examples/settings.rs b/milli/examples/settings.rs index c7f4780cb..846e3b070 100644 --- a/milli/examples/settings.rs +++ b/milli/examples/settings.rs @@ -10,7 +10,7 @@ fn main() { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB - let index = Index::new(options, "data_movies.ms").unwrap(); + let index = Index::new(None, options, "data_movies.ms").unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/src/error.rs b/milli/src/error.rs index 1147085dd..6326f696d 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -122,8 +122,12 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco InvalidFilter(String), #[error("Invalid type for filter subexpression: expected: {}, found: {1}.", .0.join(", "))] InvalidFilterExpression(&'static [&'static str], Value), - #[error("Attribute `{}` is not sortable. {}", + #[error("Attribute `{}`{} is not sortable. {}", .field, + match .index_name.is_some() { + true => format!(" of index `{}`", index_name.clone().unwrap()), + false => String::from(""), + }, match .valid_fields.is_empty() { true => "This index does not have configured sortable attributes.".to_string(), false => format!("Available sortable attributes are: `{}{}`.", @@ -132,7 +136,12 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco ), } )] - InvalidSortableAttribute { field: String, valid_fields: BTreeSet, hidden_fields: bool }, + InvalidSortableAttribute { + field: String, + index_name: Option, + valid_fields: BTreeSet, + hidden_fields: bool, + }, #[error("Attribute `{}` is not facet-searchable. {}", .field, match .valid_fields.is_empty() { @@ -451,7 +460,7 @@ impl std::fmt::Display for FaultSource { #[test] fn conditionally_lookup_for_error_message() { - let prefix = "Attribute `name` is not sortable."; + let prefix = "Attribute `name` of index `index` is not sortable."; let messages = vec![ (BTreeSet::new(), "This index does not have configured sortable attributes."), (BTreeSet::from(["age".to_string()]), "Available sortable attributes are: `age`."), @@ -460,6 +469,7 @@ fn conditionally_lookup_for_error_message() { for (list, suffix) in messages { let err = UserError::InvalidSortableAttribute { field: "name".to_string(), + index_name: Some("index".to_string()), valid_fields: list, hidden_fields: false, }; diff --git a/milli/src/index.rs b/milli/src/index.rs index 6ad39dcb1..6df7ea748 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1548,7 +1548,7 @@ pub(crate) mod tests { let mut options = EnvOpenOptions::new(); options.map_size(size); let _tempdir = TempDir::new_in(".").unwrap(); - let inner = Index::new(options, _tempdir.path()).unwrap(); + let inner = Index::new(Some("temp".to_string()), options, _tempdir.path()).unwrap(); let indexer_config = IndexerConfig::default(); let index_documents_config = IndexDocumentsConfig::default(); Self { inner, indexer_config, index_documents_config, _tempdir } diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index ae661e3f6..0f2ec3610 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -714,6 +714,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: field.to_string(), + index_name: ctx.index.name.clone(), valid_fields, hidden_fields, } @@ -725,6 +726,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: "_geo".to_string(), + index_name: ctx.index.name.clone(), valid_fields, hidden_fields, } diff --git a/milli/src/search/new/tests/integration.rs b/milli/src/search/new/tests/integration.rs index e2ea4580e..48e71f286 100644 --- a/milli/src/search/new/tests/integration.rs +++ b/milli/src/search/new/tests/integration.rs @@ -13,7 +13,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index { let path = tempfile::tempdir().unwrap(); let mut options = EnvOpenOptions::new(); options.map_size(10 * 1024 * 1024); // 10 MB - let index = Index::new(options, &path).unwrap(); + let index = Index::new(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index 6715939dc..a1cfbd70a 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -25,6 +25,7 @@ impl<'t, 'i> ClearDocuments<'t, 'i> { self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; let Index { + name: _name, env: _env, main: _main, external_documents_ids, diff --git a/milli/tests/search/facet_distribution.rs b/milli/tests/search/facet_distribution.rs index 03405531d..55bc78fb2 100644 --- a/milli/tests/search/facet_distribution.rs +++ b/milli/tests/search/facet_distribution.rs @@ -13,7 +13,7 @@ fn test_facet_distribution_with_no_facet_values() { let path = tempfile::tempdir().unwrap(); let mut options = EnvOpenOptions::new(); options.map_size(10 * 1024 * 1024); // 10 MB - let index = Index::new(options, &path).unwrap(); + let index = Index::new(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index 9193ab762..3ecbe6d67 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -31,7 +31,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index { let path = tempfile::tempdir().unwrap(); let mut options = EnvOpenOptions::new(); options.map_size(10 * 1024 * 1024); // 10 MB - let index = Index::new(options, &path).unwrap(); + let index = Index::new(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/query_criteria.rs b/milli/tests/search/query_criteria.rs index 65d403097..35c18426d 100644 --- a/milli/tests/search/query_criteria.rs +++ b/milli/tests/search/query_criteria.rs @@ -262,7 +262,7 @@ fn criteria_ascdesc() { let path = tempfile::tempdir().unwrap(); let mut options = EnvOpenOptions::new(); options.map_size(12 * 1024 * 1024); // 10 MB - let index = Index::new(options, &path).unwrap(); + let index = Index::new(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/typo_tolerance.rs b/milli/tests/search/typo_tolerance.rs index 863d2758a..83024fb2f 100644 --- a/milli/tests/search/typo_tolerance.rs +++ b/milli/tests/search/typo_tolerance.rs @@ -104,7 +104,7 @@ fn test_typo_disabled_on_word() { let tmp = tempdir().unwrap(); let mut options = EnvOpenOptions::new(); options.map_size(4096 * 100); - let index = Index::new(options, tmp.path()).unwrap(); + let index = Index::new(None, options, tmp.path()).unwrap(); let mut builder = milli::documents::DocumentsBatchBuilder::new(Vec::new()); let doc1 = json!({