update index updated at on index writes

This commit is contained in:
mpostma 2021-03-11 18:42:21 +01:00
parent 80d0f9c49d
commit 615fe095e1
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
7 changed files with 14 additions and 2 deletions

View File

@ -30,7 +30,7 @@ pub const SOFT_EXTERNAL_DOCUMENTS_IDS_KEY: &str = "soft-external-documents-ids";
pub const WORDS_FST_KEY: &str = "words-fst"; pub const WORDS_FST_KEY: &str = "words-fst";
pub const WORDS_PREFIXES_FST_KEY: &str = "words-prefixes-fst"; pub const WORDS_PREFIXES_FST_KEY: &str = "words-prefixes-fst";
const CREATED_AT_KEY: &str = "created-at"; const CREATED_AT_KEY: &str = "created-at";
const UPDATED_AT_KEY: &str ="updated-at"; const UPDATED_AT_KEY: &str = "updated-at";
#[derive(Clone)] #[derive(Clone)]
pub struct Index { pub struct Index {
@ -416,7 +416,7 @@ impl Index {
Ok(time) Ok(time)
} }
/// Returns the index creation time. /// Returns the index last updated time.
pub fn updated_at(&self, rtxn: &RoTxn) -> heed::Result<DateTime<Utc>> { pub fn updated_at(&self, rtxn: &RoTxn) -> heed::Result<DateTime<Utc>> {
let time = self.main let time = self.main
.get::<_, Str, SerdeJson<DateTime<Utc>>>(rtxn, UPDATED_AT_KEY)? .get::<_, Str, SerdeJson<DateTime<Utc>>>(rtxn, UPDATED_AT_KEY)?

View File

@ -1,3 +1,4 @@
use chrono::Utc;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use crate::{ExternalDocumentsIds, Index}; use crate::{ExternalDocumentsIds, Index};
@ -18,6 +19,7 @@ impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
} }
pub fn execute(self) -> anyhow::Result<u64> { pub fn execute(self) -> anyhow::Result<u64> {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
let Index { let Index {
env: _env, env: _env,
main: _main, main: _main,

View File

@ -1,4 +1,5 @@
use anyhow::anyhow; use anyhow::anyhow;
use chrono::Utc;
use fst::IntoStreamer; use fst::IntoStreamer;
use heed::types::ByteSlice; use heed::types::ByteSlice;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
@ -52,6 +53,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
} }
pub fn execute(self) -> anyhow::Result<u64> { pub fn execute(self) -> anyhow::Result<u64> {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
// We retrieve the current documents ids that are in the database. // We retrieve the current documents ids that are in the database.
let mut documents_ids = self.index.documents_ids(self.wtxn)?; let mut documents_ids = self.index.documents_ids(self.wtxn)?;

View File

@ -2,6 +2,7 @@ use std::cmp;
use std::fs::File; use std::fs::File;
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use chrono::Utc;
use grenad::{CompressionType, Reader, Writer, FileFuse}; use grenad::{CompressionType, Reader, Writer, FileFuse};
use heed::types::{ByteSlice, DecodeIgnore}; use heed::types::{ByteSlice, DecodeIgnore};
use heed::{BytesEncode, Error}; use heed::{BytesEncode, Error};
@ -57,6 +58,7 @@ impl<'t, 'u, 'i> Facets<'t, 'u, 'i> {
} }
pub fn execute(self) -> anyhow::Result<()> { pub fn execute(self) -> anyhow::Result<()> {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
// We get the faceted fields to be able to create the facet levels. // We get the faceted fields to be able to create the facet levels.
let faceted_fields = self.index.faceted_fields_ids(self.wtxn)?; let faceted_fields = self.index.faceted_fields_ids(self.wtxn)?;

View File

@ -8,6 +8,7 @@ use std::time::Instant;
use anyhow::Context; use anyhow::Context;
use bstr::ByteSlice as _; use bstr::ByteSlice as _;
use chrono::Utc;
use grenad::{MergerIter, Writer, Sorter, Merger, Reader, FileFuse, CompressionType}; use grenad::{MergerIter, Writer, Sorter, Merger, Reader, FileFuse, CompressionType};
use heed::types::ByteSlice; use heed::types::ByteSlice;
use log::{debug, info, error}; use log::{debug, info, error};
@ -316,6 +317,7 @@ impl<'t, 'u, 'i, 'a> IndexDocuments<'t, 'u, 'i, 'a> {
R: io::Read, R: io::Read,
F: Fn(UpdateIndexingStep, u64) + Sync, F: Fn(UpdateIndexingStep, u64) + Sync,
{ {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
let before_transform = Instant::now(); let before_transform = Instant::now();
let update_id = self.update_id; let update_id = self.update_id;
let progress_callback = |step| progress_callback(step, update_id); let progress_callback = |step| progress_callback(step, update_id);

View File

@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
use anyhow::Context; use anyhow::Context;
use chrono::Utc;
use grenad::CompressionType; use grenad::CompressionType;
use itertools::Itertools; use itertools::Itertools;
use rayon::ThreadPool; use rayon::ThreadPool;
@ -249,6 +250,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
where where
F: Fn(UpdateIndexingStep, u64) + Sync F: Fn(UpdateIndexingStep, u64) + Sync
{ {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
let old_fields_ids_map = self.index.fields_ids_map(&self.wtxn)?; let old_fields_ids_map = self.index.fields_ids_map(&self.wtxn)?;
self.update_displayed()?; self.update_displayed()?;
let facets_updated = self.update_facets()?; let facets_updated = self.update_facets()?;

View File

@ -1,6 +1,7 @@
use std::iter::FromIterator; use std::iter::FromIterator;
use std::str; use std::str;
use chrono::Utc;
use fst::automaton::Str; use fst::automaton::Str;
use fst::{Automaton, Streamer, IntoStreamer}; use fst::{Automaton, Streamer, IntoStreamer};
use grenad::CompressionType; use grenad::CompressionType;
@ -68,6 +69,7 @@ impl<'t, 'u, 'i> WordsPrefixes<'t, 'u, 'i> {
} }
pub fn execute(self) -> anyhow::Result<()> { pub fn execute(self) -> anyhow::Result<()> {
self.index.set_updated_at(self.wtxn, &Utc::now())?;
// Clear the words prefixes datastructures. // Clear the words prefixes datastructures.
self.index.word_prefix_docids.clear(self.wtxn)?; self.index.word_prefix_docids.clear(self.wtxn)?;
self.index.word_prefix_pair_proximity_docids.clear(self.wtxn)?; self.index.word_prefix_pair_proximity_docids.clear(self.wtxn)?;