diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index 02cfdb178..903a58bf1 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -788,7 +788,7 @@ impl IndexScheduler { let index = if must_create_index { // create the index if it doesn't already exist let wtxn = self.env.write_txn()?; - self.index_mapper.create_index(wtxn, index_uid)? + self.index_mapper.create_index(wtxn, index_uid, None, None)? } else { let rtxn = self.env.read_txn()?; self.index_mapper.index(&rtxn, index_uid)? @@ -805,7 +805,7 @@ impl IndexScheduler { if self.index_mapper.exists(&wtxn, &index_uid)? { return Err(Error::IndexAlreadyExists(index_uid)); } - self.index_mapper.create_index(wtxn, &index_uid)?; + self.index_mapper.create_index(wtxn, &index_uid, None, None)?; self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task }) } diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index c65d76837..82bf0ceb4 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -66,15 +66,30 @@ impl IndexMapper { /// Create or open an index in the specified path. /// The path *must* exists or an error will be thrown. - fn create_or_open_index(&self, path: &Path) -> Result { + fn create_or_open_index(&self, path: &Path, created: Option, updated: Option) -> Result { let mut options = EnvOpenOptions::new(); options.map_size(clamp_to_page_size(self.index_size)); options.max_readers(1024); - Ok(Index::new(options, path)?) + + let created_at; + if created == None { + created_at = time::OffsetDateTime::now_utc(); + } else { + created_at = created.unwrap(); + } + + let updated_at; + if updated == None { + updated_at = time::OffsetDateTime::now_utc(); + } else { + updated_at = updated.unwrap(); + } + + Ok(Index::new_with_creation_dates(options, path, created_at, updated_at)?) } /// Get or create the index. - pub fn create_index(&self, mut wtxn: RwTxn, name: &str) -> Result { + pub fn create_index(&self, mut wtxn: RwTxn, name: &str, created_at: Option, updated_at: Option) -> Result { match self.index(&wtxn, name) { Ok(index) => { wtxn.commit()?; @@ -86,7 +101,10 @@ impl IndexMapper { let index_path = self.base_path.join(uuid.to_string()); fs::create_dir_all(&index_path)?; - let index = self.create_or_open_index(&index_path)?; + + //let created_at = Some(time::OffsetDateTime::now_utc()); + //let updated_at = Some(time::OffsetDateTime::now_utc()); + let index = self.create_or_open_index(&index_path, created_at, updated_at)?; wtxn.commit()?; // TODO: it would be better to lazily create the index. But we need an Index::open function for milli. @@ -179,7 +197,10 @@ impl IndexMapper { match index_map.entry(uuid) { Entry::Vacant(entry) => { let index_path = self.base_path.join(uuid.to_string()); - let index = self.create_or_open_index(&index_path)?; + + let created_at = Some(time::OffsetDateTime::now_utc()); + let updated_at = Some(time::OffsetDateTime::now_utc()); + let index = self.create_or_open_index(&index_path, created_at, updated_at)?; entry.insert(Available(index.clone())); index } diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 1e551f9f8..8b207165b 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -867,7 +867,9 @@ impl IndexScheduler { /// Create a new index without any associated task. pub fn create_raw_index(&self, name: &str) -> Result { let wtxn = self.env.write_txn()?; - let index = self.index_mapper.create_index(wtxn, name)?; + let created_at = Some(time::OffsetDateTime::now_utc()); + let updated_at = Some(time::OffsetDateTime::now_utc()); + let index = self.index_mapper.create_index(wtxn, name, created_at, updated_at)?; Ok(index) }