Skip to content

Commit

Permalink
finalize magic values
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed May 16, 2024
1 parent 7e09994 commit 8593270
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use seahash::SeaHasher;
use std::hash::Hasher;
use std::io::{Read, Write};

pub const BLOOM_HEADER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'S', b'B', b'F', b'1'];
pub const BLOOM_HEADER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'S', b'B', b'F', b'1'];

/// A standard bloom filter
///
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn absolute_path<P: AsRef<Path>>(path: P) -> PathBuf {
.into()
}

pub const CONFIG_HEADER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'C', b'F', b'G', b'1'];
pub const CONFIG_HEADER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'C', b'F', b'G', b'1'];

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum TreeType {
Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {
#[rustfmt::skip]
let raw = &[
// Magic
b'L', b'S', b'M', b'T', b'C', b'F', b'G', b'1',
b'F', b'J', b'L', b'L', b'C', b'F', b'G', b'1',

// Tree type
0,
Expand Down
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fs::File, io::Write, path::Path};

#[doc(hidden)]
pub const LSM_MARKER: &str = ".lsm";
pub const LSM_MARKER: &str = "version";
pub const CONFIG_FILE: &str = "config";
pub const SEGMENTS_FOLDER: &str = "segments";
pub const LEVELS_MANIFEST_FILE: &str = "levels";
Expand Down
4 changes: 2 additions & 2 deletions src/levels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
sync::Arc,
};

pub const LEVEL_MANIFEST_HEADER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'L', b'V', b'L', b'1'];
pub const LEVEL_MANIFEST_HEADER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'L', b'V', b'L', b'1'];

pub type HiddenSet = HashSet<SegmentId>;

Expand Down Expand Up @@ -456,7 +456,7 @@ mod tests {
#[rustfmt::skip]
let raw = &[
// Magic
b'L', b'S', b'M', b'T', b'L', b'V', b'L', b'1',
b'F', b'J', b'L', b'L', b'L', b'V', b'L', b'1',

// Count
0,
Expand Down
2 changes: 0 additions & 2 deletions src/merge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{value::SeqNo, UserKey, Value};
use double_ended_peekable::{DoubleEndedPeekable, DoubleEndedPeekableExt};

// TODO: rename structs

// TODO: use (ParsedInternalKey, UserValue) instead of Value...

pub type BoxedIterator<'a> = Box<dyn DoubleEndedIterator<Item = crate::Result<Value>> + 'a>;
Expand Down
4 changes: 2 additions & 2 deletions src/segment/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Write};

pub const BLOCK_HEADER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'B', b'L', b'K', b'1'];
pub const BLOCK_HEADER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'B', b'L', b'K', b'1'];

/// Header of a disk-based block
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -95,7 +95,7 @@ mod tests {
#[rustfmt::skip]
let bytes = &[
// Header
b'L', b'S', b'M', b'T', b'B', b'L', b'K', b'1',
b'F', b'J', b'L', b'L', b'B', b'L', b'K', b'1',

// Compression
1,
Expand Down
2 changes: 1 addition & 1 deletion src/segment/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
};
pub use {compression::CompressionType, table_type::TableType};

pub const METADATA_HEADER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'S', b'M', b'D', b'1'];
pub const METADATA_HEADER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'S', b'M', b'D', b'1'];

pub type SegmentId = u64;

Expand Down
2 changes: 1 addition & 1 deletion src/segment/trailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
path::Path,
};

pub const TRAILER_MAGIC: &[u8] = &[b'L', b'S', b'M', b'T', b'T', b'R', b'L', b'1'];
pub const TRAILER_MAGIC: &[u8] = &[b'F', b'J', b'L', b'L', b'T', b'R', b'L', b'1'];
pub const TRAILER_SIZE: usize = 256;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl Tree {

let inner = TreeInner::create_new(config)?;

// NOTE: Lastly, fsync .lsm marker, which contains the version
// NOTE: Lastly, fsync version marker, which contains the version
// -> the LSM is fully initialized
let mut file = File::create(marker_path)?;
Version::V1.write_file_header(&mut file)?;
Expand Down
6 changes: 3 additions & 3 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TryFrom<u16> for Version {
}
}

const MAGIC_BYTES: [u8; 3] = [b'L', b'S', b'M'];
const MAGIC_BYTES: [u8; 3] = [b'F', b'J', b'L'];

impl Version {
pub fn len() -> u8 {
Expand Down Expand Up @@ -75,14 +75,14 @@ mod tests {
pub fn version_serialize() -> crate::Result<()> {
let mut bytes = vec![];
Version::V1.write_file_header(&mut bytes)?;
assert_eq!(bytes, &[b'L', b'S', b'M', 0, 1]);
assert_eq!(bytes, &[b'F', b'J', b'L', 0, 1]);
Ok(())
}

#[test]
#[allow(clippy::expect_used)]
pub fn version_deserialize_success() {
let version = Version::parse_file_header(&[b'L', b'S', b'M', 0, 1]);
let version = Version::parse_file_header(&[b'F', b'J', b'L', 0, 1]);
assert_eq!(version, Some(Version::V1));
}

Expand Down
Binary file removed test_fixture/v1_tree/.lsm
Binary file not shown.
Binary file modified test_fixture/v1_tree/config
Binary file not shown.
Binary file modified test_fixture/v1_tree/levels
Binary file not shown.
Binary file modified test_fixture/v1_tree/segments/0
Binary file not shown.
Binary file added test_fixture/v1_tree/version
Binary file not shown.
Binary file removed test_fixture/v1_tree_corrupt/.lsm
Binary file not shown.
Binary file modified test_fixture/v1_tree_corrupt/config
Binary file not shown.
Binary file modified test_fixture/v1_tree_corrupt/levels
Binary file not shown.
Binary file modified test_fixture/v1_tree_corrupt/segments/0
Binary file not shown.
Binary file added test_fixture/v1_tree_corrupt/version
Binary file not shown.

0 comments on commit 8593270

Please sign in to comment.