From 509a265659ad759ccf97922a8a160c1970145ebc Mon Sep 17 00:00:00 2001 From: PSeitz Date: Fri, 4 Nov 2022 09:19:16 +0800 Subject: [PATCH] add docstore version (#1652) * add docstore version closes #1589 * assert for docstore version --- src/store/footer.rs | 12 ++++++++++-- src/store/mod.rs | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/store/footer.rs b/src/store/footer.rs index 880c1e2d2..e04d7a0ff 100644 --- a/src/store/footer.rs +++ b/src/store/footer.rs @@ -2,7 +2,7 @@ use std::io; use common::{BinarySerializable, FixedSize, HasLen}; -use super::Decompressor; +use super::{Decompressor, DOC_STORE_VERSION}; use crate::directory::FileSlice; #[derive(Debug, Clone, PartialEq)] @@ -17,6 +17,7 @@ pub struct DocStoreFooter { /// - reserved for future use: 15 bytes impl BinarySerializable for DocStoreFooter { fn serialize(&self, writer: &mut W) -> io::Result<()> { + BinarySerializable::serialize(&DOC_STORE_VERSION, writer)?; BinarySerializable::serialize(&self.offset, writer)?; BinarySerializable::serialize(&self.decompressor.get_id(), writer)?; writer.write_all(&[0; 15])?; @@ -24,6 +25,13 @@ impl BinarySerializable for DocStoreFooter { } fn deserialize(reader: &mut R) -> io::Result { + let doc_store_version = u32::deserialize(reader)?; + if doc_store_version != DOC_STORE_VERSION { + panic!( + "actual doc store version: {}, expected: {}", + doc_store_version, DOC_STORE_VERSION + ); + } let offset = u64::deserialize(reader)?; let compressor_id = u8::deserialize(reader)?; let mut skip_buf = [0; 15]; @@ -36,7 +44,7 @@ impl BinarySerializable for DocStoreFooter { } impl FixedSize for DocStoreFooter { - const SIZE_IN_BYTES: usize = 24; + const SIZE_IN_BYTES: usize = 28; } impl DocStoreFooter { diff --git a/src/store/mod.rs b/src/store/mod.rs index ecd2f30b1..dd82c9370 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -44,6 +44,9 @@ pub use self::reader::{CacheStats, StoreReader}; pub use self::writer::StoreWriter; mod store_compressor; +/// Doc store version in footer to handle format changes. +pub(crate) const DOC_STORE_VERSION: u32 = 1; + #[cfg(feature = "lz4-compression")] mod compression_lz4_block;