-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow database migration upon adding new database column family to schema #1851
Merged
xgreenx
merged 3 commits into
FuelLabs:feature/support-new-tables-rocksdb
from
simrankedia:fix_rocksdb
Apr 29, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -202,13 +202,6 @@ where | |||||
} | ||||||
block_opts.set_bloom_filter(10.0, true); | ||||||
|
||||||
let cf_descriptors = columns.clone().into_iter().map(|i| { | ||||||
ColumnFamilyDescriptor::new( | ||||||
Self::col_name(i.id()), | ||||||
Self::cf_opts(i, &block_opts), | ||||||
) | ||||||
}); | ||||||
|
||||||
let mut opts = Options::default(); | ||||||
opts.create_if_missing(true); | ||||||
opts.set_compression_type(DBCompressionType::Lz4); | ||||||
|
@@ -227,34 +220,53 @@ where | |||||
opts.set_row_cache(&cache); | ||||||
} | ||||||
|
||||||
let db = match DB::open_cf_descriptors(&opts, &path, cf_descriptors) { | ||||||
Err(_) => { | ||||||
// setup cfs | ||||||
match DB::open_cf(&opts, &path, &[] as &[&str]) { | ||||||
Ok(db) => { | ||||||
for i in columns { | ||||||
let opts = Self::cf_opts(i, &block_opts); | ||||||
db.create_cf(Self::col_name(i.id()), &opts) | ||||||
.map_err(|e| DatabaseError::Other(e.into()))?; | ||||||
} | ||||||
Ok(db) | ||||||
} | ||||||
Err(err) => { | ||||||
tracing::error!("Couldn't open the database with an error: {}. \nTrying to repair the database", err); | ||||||
DB::repair(&opts, &path) | ||||||
.map_err(|e| DatabaseError::Other(e.into()))?; | ||||||
|
||||||
let cf_descriptors = columns.clone().into_iter().map(|i| { | ||||||
ColumnFamilyDescriptor::new( | ||||||
Self::col_name(i.id()), | ||||||
Self::cf_opts(i, &block_opts), | ||||||
) | ||||||
}); | ||||||
DB::open_cf_descriptors(&opts, &path, cf_descriptors) | ||||||
} | ||||||
} | ||||||
let existing_column_families = match DB::list_cf(&opts, &path) { | ||||||
Ok(cfs) => cfs, | ||||||
Err(err) => { | ||||||
tracing::error!( | ||||||
"Couldn't get the list of cfs: {}. Returning an empty list", | ||||||
err | ||||||
); | ||||||
vec![] | ||||||
} | ||||||
ok => ok, | ||||||
}; | ||||||
|
||||||
let mut cf_descriptors_to_open = vec![]; | ||||||
let mut cf_descriptors_to_create = vec![]; | ||||||
for column in columns.clone() { | ||||||
let column_name = Self::col_name(column.id()); | ||||||
if existing_column_families.contains(&column_name) { | ||||||
cf_descriptors_to_open.push(ColumnFamilyDescriptor::new( | ||||||
column_name, | ||||||
Self::cf_opts(column, &block_opts), | ||||||
)); | ||||||
} else { | ||||||
let opts = Self::cf_opts(column, &block_opts); | ||||||
cf_descriptors_to_create.push((column_name, opts)); | ||||||
} | ||||||
} | ||||||
let db = match DB::open_cf_descriptors(&opts, &path, cf_descriptors_to_open) { | ||||||
Ok(db) => { | ||||||
// Setup cfs | ||||||
for (name, opt) in cf_descriptors_to_create { | ||||||
db.create_cf(name, &opt) | ||||||
.map_err(|e| DatabaseError::Other(e.into()))?; | ||||||
} | ||||||
Ok(db) | ||||||
}, | ||||||
Err(err) => { | ||||||
tracing::error!("Couldn't open the database with an error: {}. \nTrying to repair the database", err); | ||||||
DB::repair(&opts, &path) | ||||||
.map_err(|e| DatabaseError::Other(e.into()))?; | ||||||
|
||||||
let cf_descriptors = columns.clone().into_iter().map(|i| { | ||||||
ColumnFamilyDescriptor::new( | ||||||
Self::col_name(i.id()), | ||||||
Self::cf_opts(i, &block_opts), | ||||||
) | ||||||
}); | ||||||
DB::open_cf_descriptors(&opts, &path, cf_descriptors) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
} | ||||||
.map_err(|e| DatabaseError::Other(e.into()))?; | ||||||
let rocks_db = RocksDb { | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes sense to move this loop after
db
is opened(below of thematch
statement). In this case you also will handle the case of the error with repair.