-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add compact database tool (#9341)
Add a database tool for running SST file compactions. This is useful when changing block size parameters in order to have an optimized layout of data in SST files.
- Loading branch information
Jure Bajic
authored
Aug 3, 2023
1 parent
8e4196f
commit f28033b
Showing
8 changed files
with
44 additions
and
10 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::utils::open_rocksdb; | ||
use clap::Parser; | ||
use near_store::db::Database; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser)] | ||
pub(crate) struct RunCompactionCommand {} | ||
|
||
impl RunCompactionCommand { | ||
pub(crate) fn run(&self, home: &PathBuf) -> anyhow::Result<()> { | ||
let db = open_rocksdb(home, near_store::Mode::ReadWrite)?; | ||
db.compact()?; | ||
eprintln!("Compaction is finished!"); | ||
Ok(()) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use std::path::Path; | ||
|
||
pub(crate) fn open_rocksdb(home: &Path) -> anyhow::Result<near_store::db::RocksDB> { | ||
pub(crate) fn open_rocksdb( | ||
home: &Path, | ||
mode: near_store::Mode, | ||
) -> anyhow::Result<near_store::db::RocksDB> { | ||
let config = nearcore::config::Config::from_file_skip_validation( | ||
&home.join(nearcore::config::CONFIG_FILENAME), | ||
)?; | ||
let store_config = &config.store; | ||
let db_path = store_config.path.as_ref().cloned().unwrap_or_else(|| home.join("data")); | ||
let rocksdb = near_store::db::RocksDB::open( | ||
&db_path, | ||
store_config, | ||
near_store::Mode::ReadOnly, | ||
near_store::Temperature::Hot, | ||
)?; | ||
let rocksdb = | ||
near_store::db::RocksDB::open(&db_path, store_config, mode, near_store::Temperature::Hot)?; | ||
Ok(rocksdb) | ||
} |