1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! The metadata that describes a column family, a level, or a SST file,

use std::fmt;
use std::ops::Deref;

use crate::types::SequenceNumber;

/// The metadata that describes a column family.
pub struct ColumnFamilyMetaData {
    /// The size of this column family in bytes, which is equal to the sum of
    /// the file size of its "levels".
    pub size: u64,
    /// The number of files in this column family.
    pub file_count: usize,
    /// The name of the column family.
    pub name: String,
    /// The metadata of all levels in this column family.
    pub levels: Vec<LevelMetaData>,
}

impl fmt::Debug for ColumnFamilyMetaData {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("ColumnFamilyMetaData")
            .field("name", &self.name)
            .field("file_count", &self.file_count)
            .field("size", &self.size)
            .finish()?;
        write!(f, "\n")?;
        for level in &self.levels {
            write!(f, "  > {:?}\n", level)?;
        }
        Ok(())
    }
}

/// The metadata that describes a level.
pub struct LevelMetaData {
    /// The level which this meta data describes.
    pub level: u32,
    /// The size of this level in bytes, which is equal to the sum of
    /// the file size of its "files".
    pub size: u64,
    /// The metadata of all sst files in this level.
    pub files: Vec<SstFileMetaData>,
}

impl fmt::Debug for LevelMetaData {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("LevelMetaData")
            .field("level", &self.level)
            .field("files", &self.files)
            .finish()
    }
}

/// The metadata that describes a SST file.
pub struct SstFileMetaData {
    /// File size in bytes.
    pub size: u64,
    /// The name of the file.
    pub name: String,
    /// The full path where the file locates.
    pub db_path: String,

    /// Smallest sequence number in file.
    pub smallest_seqno: SequenceNumber,
    /// Largest sequence number in file.
    pub largest_seqno: SequenceNumber,
    /// Smallest user defined key in the file.
    pub smallestkey: Vec<u8>,
    /// Largest user defined key in the file.
    pub largestkey: Vec<u8>,
    /// true if the file is currently being compacted.
    pub being_compacted: bool,
}

impl fmt::Debug for SstFileMetaData {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("SstFile").field("name", &self.name).finish()
    }
}

/// The full set of metadata associated with each SST file.
pub struct LiveFileMetaData {
    pub sst_file: SstFileMetaData,
    /// Name of the column family
    pub column_family_name: String,
    /// Level at which this file resides.
    pub level: u32,
}

impl Deref for LiveFileMetaData {
    type Target = SstFileMetaData;

    fn deref(&self) -> &SstFileMetaData {
        &self.sst_file
    }
}

impl fmt::Debug for LiveFileMetaData {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("LiveFile")
            .field("name", &self.name)
            .field("column_family_name", &self.column_family_name)
            .field("level", &self.level)
            .field("db_path", &self.db_path)
            .field("smallestkey", &String::from_utf8_lossy(&self.smallestkey))
            .field("largestkey", &String::from_utf8_lossy(&self.largestkey))
            .field("being_compacted", &self.being_compacted)
            .field("size", &self.size)
            .finish()
    }
}