From 7a0064db1f872c8f9115401ccf3428175acb6d13 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Mon, 6 Nov 2023 19:02:37 +0100 Subject: [PATCH] bump index version (#2237) * bump index version and add constant for lowest supported version * use range instead of handcoded bounds --- src/directory/footer.rs | 9 +++++---- src/lib.rs | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/directory/footer.rs b/src/directory/footer.rs index 4695c5f69b..70acceebd7 100644 --- a/src/directory/footer.rs +++ b/src/directory/footer.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use crate::directory::error::Incompatibility; use crate::directory::{AntiCallToken, FileSlice, TerminatingWrite}; -use crate::{Version, INDEX_FORMAT_VERSION}; +use crate::{Version, INDEX_FORMAT_OLDEST_SUPPORTED_VERSION, INDEX_FORMAT_VERSION}; const FOOTER_MAX_LEN: u32 = 50_000; @@ -102,10 +102,11 @@ impl Footer { /// Confirms that the index will be read correctly by this version of tantivy /// Has to be called after `extract_footer` to make sure it's not accessing uninitialised memory pub fn is_compatible(&self) -> Result<(), Incompatibility> { + const SUPPORTED_INDEX_FORMAT_VERSION_RANGE: std::ops::RangeInclusive = + INDEX_FORMAT_OLDEST_SUPPORTED_VERSION..=INDEX_FORMAT_VERSION; + let library_version = crate::version(); - if self.version.index_format_version < 4 - || self.version.index_format_version > INDEX_FORMAT_VERSION - { + if !SUPPORTED_INDEX_FORMAT_VERSION_RANGE.contains(&self.version.index_format_version) { return Err(Incompatibility::IndexMismatch { library_version: library_version.clone(), index_version: self.version.clone(), diff --git a/src/lib.rs b/src/lib.rs index 61751e8dd9..c682643ec4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -238,7 +238,9 @@ pub use crate::schema::DatePrecision; pub use crate::schema::{DateOptions, DateTimePrecision, Document, TantivyDocument, Term}; /// Index format version. -const INDEX_FORMAT_VERSION: u32 = 5; +const INDEX_FORMAT_VERSION: u32 = 6; +/// Oldest index format version this tantivy version can read. +const INDEX_FORMAT_OLDEST_SUPPORTED_VERSION: u32 = 4; /// Structure version for the index. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]