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

kvdb-rocksdb: replace tempdir with tempfile(#350) #477

Merged
merged 1 commit into from
Dec 10, 2020
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
2 changes: 1 addition & 1 deletion kvdb-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ criterion = "0.3"
ethereum-types = { path = "../ethereum-types" }
kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.5" }
rand = "0.7.2"
tempdir = "0.3.7"
tempfile = "3.1.0"
keccak-hash = { path = "../keccak-hash" }
sysinfo = "0.15.3"
ctrlc = "3.1.4"
Expand Down
2 changes: 1 addition & 1 deletion kvdb-rocksdb/examples/memtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn main() {
for c in 0..=COLUMN_COUNT {
config.memory_budget.insert(c, mb_per_col);
}
let dir = tempdir::TempDir::new("rocksdb-example").unwrap();
let dir = tempfile::Builder::new().prefix("rocksdb-example").tempdir().unwrap();

println!("Database is put in: {} (maybe check if it was deleted)", dir.path().to_string_lossy());
let db = Database::open(&config, &dir.path().to_string_lossy()).unwrap();
Expand Down
22 changes: 11 additions & 11 deletions kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,10 @@ mod tests {
use super::*;
use kvdb_shared_tests as st;
use std::io::{self, Read};
use tempdir::TempDir;
use tempfile::Builder as TempfileBuilder;

fn create(columns: u32) -> io::Result<Database> {
let tempdir = TempDir::new("")?;
let tempdir = TempfileBuilder::new().prefix("").tempdir()?;
let config = DatabaseConfig::with_columns(columns);
Database::open(&config, tempdir.path().to_str().expect("tempdir path is valid unicode"))
}
Expand Down Expand Up @@ -846,7 +846,7 @@ mod tests {

#[test]
fn secondary_db_get() -> io::Result<()> {
let primary = TempDir::new("")?;
let primary = TempfileBuilder::new().prefix("").tempdir()?;
let config = DatabaseConfig::with_columns(1);
let db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?;

Expand All @@ -856,7 +856,7 @@ mod tests {
db.write(transaction)?;

let config = DatabaseConfig {
secondary: TempDir::new("")?.path().to_str().map(|s| s.to_string()),
secondary: TempfileBuilder::new().prefix("").tempdir()?.path().to_str().map(|s| s.to_string()),
..DatabaseConfig::with_columns(1)
};
let second_db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?;
Expand All @@ -866,12 +866,12 @@ mod tests {

#[test]
fn secondary_db_catch_up() -> io::Result<()> {
let primary = TempDir::new("")?;
let primary = TempfileBuilder::new().prefix("").tempdir()?;
let config = DatabaseConfig::with_columns(1);
let db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?;

let config = DatabaseConfig {
secondary: TempDir::new("")?.path().to_str().map(|s| s.to_string()),
secondary: TempfileBuilder::new().prefix("").tempdir()?.path().to_str().map(|s| s.to_string()),
..DatabaseConfig::with_columns(1)
};
let second_db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?;
Expand All @@ -888,7 +888,7 @@ mod tests {

#[test]
fn mem_tables_size() {
let tempdir = TempDir::new("").unwrap();
let tempdir = TempfileBuilder::new().prefix("").tempdir().unwrap();

let config = DatabaseConfig {
max_open_files: 512,
Expand Down Expand Up @@ -950,7 +950,7 @@ mod tests {
let config_1 = DatabaseConfig::default();
let config_5 = DatabaseConfig::with_columns(5);

let tempdir = TempDir::new("").unwrap();
let tempdir = TempfileBuilder::new().prefix("").tempdir().unwrap();

// open 1, add 4.
{
Expand All @@ -975,7 +975,7 @@ mod tests {
let config_1 = DatabaseConfig::default();
let config_5 = DatabaseConfig::with_columns(5);

let tempdir = TempDir::new("drop_columns").unwrap();
let tempdir = TempfileBuilder::new().prefix("drop_columns").tempdir().unwrap();

// open 5, remove 4.
{
Expand All @@ -997,7 +997,7 @@ mod tests {

#[test]
fn test_num_keys() {
let tempdir = TempDir::new("").unwrap();
let tempdir = TempfileBuilder::new().prefix("").tempdir().unwrap();
let config = DatabaseConfig::with_columns(1);
let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap();

Expand Down Expand Up @@ -1059,7 +1059,7 @@ rocksdb.db.get.micros P50 : 2.000000 P95 : 3.000000 P99 : 4.000000 P100 : 5.0000
cfg.compaction.initial_file_size = 102030;
cfg.memory_budget = [(0, 30), (1, 300)].iter().cloned().collect();

let db_path = TempDir::new("config_test").expect("the OS can create tmp dirs");
let db_path = TempfileBuilder::new().prefix("config_test").tempdir().expect("the OS can create tmp dirs");
let db = Database::open(&cfg, db_path.path().to_str().unwrap()).expect("can open a db");
let mut rocksdb_log = std::fs::File::open(format!("{}/LOG", db_path.path().to_str().unwrap()))
.expect("rocksdb creates a LOG file");
Expand Down