Skip to content

Commit

Permalink
!fix: Ensure default column family uses specified open options
Browse files Browse the repository at this point in the history
Previously, the default column family was initialized with default settings if not explicitly included in the column family descriptors.
This commit ensures that the default column family inherits the open options
  • Loading branch information
0xdeafbeef committed Apr 30, 2024
1 parent b7f2f3b commit 8890da6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* Expose rocksdb cumulative statistics and histograms (AhmedSoliman)
* Make FlushOptions Send and Sync (jansegre)
* Export memory usage builder and MemoryUsage structs to users (AhmedSoliman)
* `default` column family inherits open options (0xdeafbeef)

## 0.21.0 (2023-05-09)

Expand Down
16 changes: 15 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {

/// Opens a database with the given database with a Time to Live compaction filter and
/// column family descriptors.
/// *NOTE*: `default` column family is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_descriptors_with_ttl<P, I>(
opts: &Options,
path: P,
Expand Down Expand Up @@ -454,6 +456,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
}

/// Opens a database for read only with the given database options and column family names.
/// *NOTE*: `default` cf is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_for_read_only<P, I, N>(
opts: &Options,
path: P,
Expand All @@ -480,6 +484,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
}

/// Opens a database for read only with the given database options and column family names.
/// *NOTE*: `default` column family is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_with_opts_for_read_only<P, I, N>(
db_opts: &Options,
path: P,
Expand Down Expand Up @@ -507,6 +513,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {

/// Opens a database for ready only with the given database options and
/// column family descriptors.
/// *NOTE*: `default` column family is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_descriptors_read_only<P, I>(
opts: &Options,
path: P,
Expand All @@ -528,6 +536,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
}

/// Opens the database as a secondary with the given database options and column family names.
/// *NOTE*: `default` column family is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_as_secondary<P, I, N>(
opts: &Options,
primary_path: P,
Expand Down Expand Up @@ -555,6 +565,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {

/// Opens the database as a secondary with the given database options and
/// column family descriptors.
/// *NOTE*: `default` cf is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_descriptors_as_secondary<P, I>(
opts: &Options,
path: P,
Expand All @@ -576,6 +588,8 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
}

/// Opens a database with the given database options and column family descriptors.
/// *NOTE*: `default` column family is opened with `opts`.
/// If you want to open `default` cf with different options, set them explicitly in `cfs`.
pub fn open_cf_descriptors<P, I>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
where
P: AsRef<Path>,
Expand Down Expand Up @@ -619,7 +633,7 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
if !cfs_v.iter().any(|cf| cf.name == DEFAULT_COLUMN_FAMILY_NAME) {
cfs_v.push(ColumnFamilyDescriptor {
name: String::from(DEFAULT_COLUMN_FAMILY_NAME),
options: Options::default(),
options: opts.clone(),
});
}
// We need to store our CStrings in an intermediate vector
Expand Down
3 changes: 2 additions & 1 deletion src/transactions/optimistic_transaction_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl<T: ThreadMode> OptimisticTransactionDB<T> {
/// Opens a database with the given database options and column family names.
///
/// Column families opened using this function will be created with default `Options`.
/// `default` column family will have the same options as the database.
pub fn open_cf<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
where
P: AsRef<Path>,
Expand Down Expand Up @@ -152,7 +153,7 @@ impl<T: ThreadMode> OptimisticTransactionDB<T> {
if !cfs_v.iter().any(|cf| cf.name == DEFAULT_COLUMN_FAMILY_NAME) {
cfs_v.push(ColumnFamilyDescriptor {
name: String::from(DEFAULT_COLUMN_FAMILY_NAME),
options: Options::default(),
options: opts.clone(),
});
}
// We need to store our CStrings in an intermediate vector
Expand Down

0 comments on commit 8890da6

Please sign in to comment.