Skip to content

Commit

Permalink
feat: set prefix_extractor for column families (#693)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Aug 26, 2024
1 parent 40aefdc commit 2fe844a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
]

[workspace.package]
version = "0.1.102"
version = "0.1.103"
authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git"
Expand All @@ -22,13 +22,13 @@ readme = "README.md"
edition = "2021"

[workspace.dependencies]
dragonfly-client = { path = "dragonfly-client", version = "0.1.102" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.102" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.102" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.102" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.102" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.102" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.102" }
dragonfly-client = { path = "dragonfly-client", version = "0.1.103" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.103" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.103" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.103" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.103" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.103" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.103" }
thiserror = "1.0"
dragonfly-api = "=2.0.148"
reqwest = { version = "0.12.4", features = ["stream", "native-tls", "default-tls", "rustls-tls"] }
Expand Down
3 changes: 0 additions & 3 deletions dragonfly-client-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,14 @@ impl Storage {

// delete_task deletes the task metadatas, task content and piece metadatas.
pub async fn delete_task(&self, id: &str) {
info!("start to delete task: {}", id);
self.metadata
.delete_task(id)
.unwrap_or_else(|err| error!("delete task metadata failed: {}", err));

info!("start to delete pieces of task: {}", id);
self.metadata.delete_pieces(id).unwrap_or_else(|err| {
error!("delete piece metadatas failed: {}", err);
});

info!("start to delete content of task: {}", id);
self.content.delete_task(id).await.unwrap_or_else(|err| {
error!("delete task content failed: {}", err);
});
Expand Down
17 changes: 15 additions & 2 deletions dragonfly-client-storage/src/storage_engine/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl RocksdbStorageEngine {
let mut options = rocksdb::Options::default();
options.create_if_missing(true);
options.create_missing_column_families(true);
options.optimize_level_style_compaction(Self::DEFAULT_MEMTABLE_MEMORY_BUDGET);
options.increase_parallelism(num_cpus::get() as i32);
options.set_compression_type(rocksdb::DBCompressionType::Lz4);
options.set_max_background_jobs(std::cmp::max(
Expand All @@ -93,6 +92,19 @@ impl RocksdbStorageEngine {
block_options.set_block_size(Self::DEFAULT_BLOCK_SIZE);
options.set_block_based_table_factory(&block_options);

// Initialize column family options.
let mut cf_options = rocksdb::Options::default();
cf_options.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(64));
cf_options.set_memtable_prefix_bloom_ratio(0.2);
cf_options.optimize_level_style_compaction(Self::DEFAULT_MEMTABLE_MEMORY_BUDGET);

// Initialize column families.
let cfs = cf_names
.iter()
.map(|name| (name.to_string(), cf_options.clone()))
.collect::<Vec<_>>();

// Initialize rocksdb directory.
let dir = dir.join(Self::DEFAULT_DIR_NAME);

// If the storage is not kept, remove the db.
Expand All @@ -103,7 +115,8 @@ impl RocksdbStorageEngine {
}

// Open rocksdb.
let db = rocksdb::DB::open_cf(&options, &dir, cf_names).or_err(ErrorType::StorageError)?;
let db =
rocksdb::DB::open_cf_with_opts(&options, &dir, cfs).or_err(ErrorType::StorageError)?;
info!("metadata initialized directory: {:?}", dir);

Ok(Self { inner: db })
Expand Down

0 comments on commit 2fe844a

Please sign in to comment.