Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes compression threshold explicitly fixed at runtime #103

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/btree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
error::{Error, Result},
index::Address,
log::{LogAction, LogQuery, LogReader, LogWriter},
options::Options,
options::{Metadata, Options, DEFAULT_COMPRESSION_THRESHOLD},
table::{
key::{TableKey, TableKeyQuery},
Entry as ValueTableEntry, Value, ValueTable,
Expand Down Expand Up @@ -122,7 +122,8 @@ impl BTreeTable {
pub fn open(
id: ColId,
values: Vec<ValueTable>,
metadata: &crate::options::Metadata,
options: &Options,
metadata: &Metadata,
) -> Result<Self> {
let size_tier = HEADER_ADDRESS.size_tier() as usize;
if !values[size_tier].is_init() {
Expand All @@ -131,12 +132,19 @@ impl BTreeTable {
entry.write_header(&btree_header);
values[size_tier].init_with_entry(&*entry.encoded.inner_mut())?;
}
let options = &metadata.columns[id as usize];
let col_options = &metadata.columns[id as usize];
Ok(BTreeTable {
id,
tables: RwLock::new(values),
ref_counted: options.ref_counted,
compression: Compress::new(options.compression, options.compression_threshold),
ref_counted: col_options.ref_counted,
compression: Compress::new(
col_options.compression,
options
.compression_threshold
.get(&id)
.copied()
.unwrap_or(DEFAULT_COMPRESSION_THRESHOLD),
),
})
}

Expand Down
21 changes: 14 additions & 7 deletions src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
error::{Error, Result},
index::{Address, IndexTable, PlanOutcome, TableId as IndexTableId},
log::{Log, LogAction, LogOverlays, LogQuery, LogReader, LogWriter},
options::{ColumnOptions, Metadata, Options},
options::{ColumnOptions, Metadata, Options, DEFAULT_COMPRESSION_THRESHOLD},
stats::{ColumnStatSummary, ColumnStats},
table::{
key::{TableKey, TableKeyQuery},
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Column {
.collect::<Result<_>>()?;

if column_options.btree_index {
Ok(Column::Tree(BTreeTable::open(col, value, metadata)?))
Ok(Column::Tree(BTreeTable::open(col, value, options, metadata)?))
} else {
Ok(Column::Hash(HashColumn::open(col, value, options, metadata)?))
}
Expand Down Expand Up @@ -300,20 +300,27 @@ impl HashColumn {
let (index, reindexing, stats) = Self::open_index(&options.path, col)?;
let collect_stats = options.stats;
let path = &options.path;
let options = &metadata.columns[col as usize];
let col_options = &metadata.columns[col as usize];
let db_version = metadata.version;
Ok(HashColumn {
col,
tables: RwLock::new(Tables { index, value }),
reindex: RwLock::new(Reindex { queue: reindexing, progress: AtomicU64::new(0) }),
path: path.into(),
preimage: options.preimage,
uniform_keys: options.uniform,
ref_counted: options.ref_counted,
preimage: col_options.preimage,
uniform_keys: col_options.uniform,
ref_counted: col_options.ref_counted,
collect_stats,
salt: metadata.salt,
stats,
compression: Compress::new(options.compression, options.compression_threshold),
compression: Compress::new(
col_options.compression,
options
.compression_threshold
.get(&col)
.copied()
.unwrap_or(DEFAULT_COMPRESSION_THRESHOLD),
),
db_version,
})
}
Expand Down
11 changes: 7 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub const CURRENT_VERSION: u32 = 7;
// TODO on last supported 5, remove MULTIHEAD_V4 and MULTIPART_V4
const LAST_SUPPORTED_VERSION: u32 = 4;

pub const DEFAULT_COMPRESSION_THRESHOLD: u32 = 4096;

/// Database configuration.
#[derive(Clone, Debug)]
pub struct Options {
Expand All @@ -31,6 +33,10 @@ pub struct Options {
/// Override salt value. If `None` is specified salt is loaded from metadata
/// or randomly generated when creating a new database.
pub salt: Option<Salt>,
/// Minimal value size threshold to attempt compressing a value per column.
///
/// Optional. A sensible default is used if nothing is set for a given column.
pub compression_threshold: HashMap<ColId, u32>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -50,8 +56,6 @@ pub struct ColumnOptions {
pub ref_counted: bool,
/// Compression to use for this column.
pub compression: CompressionType,
/// Minimal value size threshold to attempt compressing a value.
pub compression_threshold: u32,
/// Column is using a btree indexing.
pub btree_index: bool,
}
Expand Down Expand Up @@ -106,7 +110,6 @@ impl ColumnOptions {
uniform,
ref_counted,
compression: compression.into(),
compression_threshold: ColumnOptions::default().compression_threshold,
btree_index,
})
}
Expand All @@ -119,7 +122,6 @@ impl Default for ColumnOptions {
uniform: false,
ref_counted: false,
compression: CompressionType::NoCompression,
compression_threshold: 4096,
btree_index: false,
}
}
Expand All @@ -134,6 +136,7 @@ impl Options {
stats: true,
salt: None,
columns: (0..num_columns).map(|_| Default::default()).collect(),
compression_threshold: HashMap::new(),
}
}

Expand Down