Skip to content

Commit

Permalink
[Rocksdb] remove unused arguments and move overrides into typed_store (
Browse files Browse the repository at this point in the history
…MystenLabs#9303)

## Description 

Remove `default_db_options()` arguments that are basically unused. The
only overrides to these options are for index storage, which I believe
is going away. In any case, it seems better to override at callsites
instead of passing in overrides as arguments.

Move the overrides in `default_db_options()` into the base
`default_db_options()` in typed store. This allows sharing the settings
with Narwhal.

## Test Plan 

n/a

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
mwtian authored Mar 14, 2023
1 parent a3d3fc0 commit 87f5996
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 93 deletions.
7 changes: 4 additions & 3 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::future::Future;
use std::iter;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use sui_storage::default_db_options;
use sui_storage::write_ahead_log::{DBWriteAheadLog, TxGuard, WriteAheadLog};
use sui_types::accumulator::Accumulator;
use sui_types::base_types::{AuthorityName, EpochId, ObjectID, SequenceNumber, TransactionDigest};
Expand All @@ -29,7 +28,9 @@ use sui_types::messages::{
};
use sui_types::signature::GenericSignature;
use tracing::{debug, info, trace, warn};
use typed_store::rocks::{DBBatch, DBMap, DBOptions, MetricConf, TypedStoreError};
use typed_store::rocks::{
point_lookup_db_options, DBBatch, DBMap, DBOptions, MetricConf, TypedStoreError,
};
use typed_store::traits::{TableSummary, TypedStoreDebug};

use crate::authority::authority_notify_read::NotifyRead;
Expand Down Expand Up @@ -1883,7 +1884,7 @@ impl AuthorityPerEpochStore {
}

fn transactions_table_default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}

impl ExecutionComponents {
Expand Down
15 changes: 8 additions & 7 deletions crates/sui-core/src/authority/authority_store_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use super::*;
use crate::authority::authority_store::LockDetailsWrapper;
use rocksdb::Options;
use std::path::Path;
use sui_storage::default_db_options;
use sui_types::accumulator::Accumulator;
use sui_types::base_types::SequenceNumber;
use sui_types::digests::TransactionEventsDigest;
use sui_types::storage::ObjectStore;
use typed_store::metrics::SamplingInterval;
use typed_store::rocks::util::{empty_compaction_filter, reference_count_merge_operator};
use typed_store::rocks::{DBBatch, DBMap, DBOptions, MetricConf, ReadWriteOptions};
use typed_store::rocks::{
point_lookup_db_options, DBBatch, DBMap, DBOptions, MetricConf, ReadWriteOptions,
};
use typed_store::traits::{Map, TableSummary, TypedStoreDebug};

use crate::authority::authority_store_types::{
Expand Down Expand Up @@ -299,11 +300,11 @@ impl Iterator for LiveSetIter<'_> {

// These functions are used to initialize the DB tables
fn owned_object_transaction_locks_table_default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}

fn objects_table_default_config() -> DBOptions {
let db_options = default_db_options(None, None).1;
let db_options = point_lookup_db_options();
DBOptions {
options: db_options.options,
rw_options: ReadWriteOptions {
Expand All @@ -313,15 +314,15 @@ fn objects_table_default_config() -> DBOptions {
}

fn transactions_table_default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}

fn effects_table_default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}

fn indirect_move_objects_table_default_config() -> DBOptions {
let mut options = default_db_options(None, None).1;
let mut options = point_lookup_db_options();
options.options.set_merge_operator(
"refcount operator",
reference_count_merge_operator,
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-core/src/epoch/committee_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use rocksdb::Options;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use sui_storage::default_db_options;
use sui_types::base_types::ObjectID;
use sui_types::committee::{Committee, EpochId};
use sui_types::error::{SuiError, SuiResult};
use typed_store::rocks::{DBMap, DBOptions, MetricConf};
use typed_store::rocks::{point_lookup_db_options, DBMap, DBOptions, MetricConf};
use typed_store::traits::{TableSummary, TypedStoreDebug};

use typed_store::Map;
Expand All @@ -32,7 +31,7 @@ pub struct CommitteeStoreTables {

// These functions are used to initialize the DB tables
fn committee_table_default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}

impl CommitteeStore {
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-rosetta/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ use std::time::{Duration, UNIX_EPOCH};
use sui_json_rpc_types::SuiTransactionResponseOptions;
use sui_sdk::rpc_types::Checkpoint;
use sui_sdk::SuiClient;
use sui_storage::default_db_options;
use sui_types::base_types::{EpochId, SuiAddress};
use sui_types::messages_checkpoint::CheckpointSequenceNumber;
use tracing::{debug, error, info, warn};
use typed_store::rocks::{DBMap, DBOptions, MetricConf};
use typed_store::rocks::{point_lookup_db_options, DBMap, DBOptions, MetricConf};
use typed_store::traits::TableSummary;
use typed_store::traits::TypedStoreDebug;
use typed_store::Map;
Expand Down Expand Up @@ -347,5 +346,5 @@ impl CheckpointIndexStore {
}

fn default_config() -> DBOptions {
default_db_options(None, None).1
point_lookup_db_options()
}
26 changes: 12 additions & 14 deletions crates/sui-storage/src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ use sui_types::messages::TransactionEvents;
use sui_types::object::Owner;
use sui_types::query::TransactionFilter;
use typed_store::rocks::DBOptions;
use typed_store::rocks::{DBMap, MetricConf};
use typed_store::rocks::{default_db_options, point_lookup_db_options, DBMap, MetricConf};
use typed_store::traits::Map;
use typed_store::traits::{TableSummary, TypedStoreDebug};
use typed_store_derive::DBMapUtils;

use crate::default_db_options;

type OwnerIndexKey = (SuiAddress, ObjectID);
type DynamicFieldKey = (ObjectID, ObjectID);
type EventId = (TxSequenceNumber, usize);
Expand Down Expand Up @@ -118,37 +116,37 @@ pub struct IndexStore {

// These functions are used to initialize the DB tables
fn transactions_order_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_seq_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_from_addr_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_to_addr_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_by_input_object_id_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_by_mutated_object_id_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn transactions_by_move_function_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn timestamps_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).1
point_lookup_db_options()
}
fn owner_index_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn dynamic_field_index_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}
fn index_table_default_config() -> DBOptions {
default_db_options(None, Some(1_000_000)).0
default_db_options()
}

impl IndexStore {
Expand Down
44 changes: 0 additions & 44 deletions crates/sui-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,3 @@ pub mod mutex_table;
pub mod object_store;
pub mod write_ahead_log;
pub mod write_path_pending_tx_log;

use rocksdb::Options;
use typed_store::rocks::{
default_db_options as default_rocksdb_options, DBOptions, ReadWriteOptions,
};

/// Given a provided `db_options`, add a few default options.
/// Returns the default option and the point lookup option.
pub fn default_db_options(
db_options: Option<Options>,
cache_capacity: Option<usize>,
) -> (DBOptions, DBOptions) {
let mut db_options = db_options
.map(|o| DBOptions {
options: o,
rw_options: ReadWriteOptions::default(),
})
.unwrap_or_else(default_rocksdb_options);

// One common issue when running tests on Mac is that the default ulimit is too low,
// leading to I/O errors such as "Too many open files". Raising fdlimit to bypass it.
if let Some(limit) = fdlimit::raise_fd_limit() {
// on windows raise_fd_limit return None
db_options.options.set_max_open_files((limit / 8) as i32);
}

// The table cache is locked for updates and this determines the number
// of shareds, ie 2^10. Increase in case of lock contentions.
let row_cache =
rocksdb::Cache::new_lru_cache(cache_capacity.unwrap_or(300_000)).expect("Cache is ok");
db_options.options.set_row_cache(&row_cache);
db_options.options.set_table_cache_num_shard_bits(10);
db_options
.options
.set_compression_type(rocksdb::DBCompressionType::None);

let mut point_lookup = db_options.clone();
point_lookup
.options
.optimize_for_point_lookup(64 /* 64MB (default is 8) */);
point_lookup.options.set_memtable_whole_key_filtering(true);

(db_options, point_lookup)
}
34 changes: 15 additions & 19 deletions crates/sui-tool/src/db_tool/db_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ use sui_core::authority::authority_per_epoch_store::AuthorityEpochTables;
use sui_core::authority::authority_store_tables::AuthorityPerpetualTables;
use sui_core::authority::authority_store_types::StoreData;
use sui_core::epoch::committee_store::CommitteeStoreTables;
use sui_storage::default_db_options;
use sui_storage::write_ahead_log::DBWriteAheadLogTables;
use sui_storage::IndexStoreTables;
use sui_types::base_types::{EpochId, ObjectID};
use sui_types::messages::{SignedTransactionEffects, TrustedCertificate};
use sui_types::temporary_store::InnerTemporaryStore;
use typed_store::rocks::MetricConf;
use typed_store::rocks::{default_db_options, MetricConf};
use typed_store::traits::{Map, TableSummary};

#[derive(EnumString, Clone, Parser, Debug, ValueEnum)]
Expand All @@ -36,23 +35,20 @@ impl std::fmt::Display for StoreName {
}

pub fn list_tables(path: PathBuf) -> anyhow::Result<Vec<String>> {
rocksdb::DBWithThreadMode::<MultiThreaded>::list_cf(
&default_db_options(None, None).0.options,
path,
)
.map_err(|e| e.into())
.map(|q| {
q.iter()
.filter_map(|s| {
// The `default` table is not used
if s != "default" {
Some(s.clone())
} else {
None
}
})
.collect()
})
rocksdb::DBWithThreadMode::<MultiThreaded>::list_cf(&default_db_options().options, path)
.map_err(|e| e.into())
.map(|q| {
q.iter()
.filter_map(|s| {
// The `default` table is not used
if s != "default" {
Some(s.clone())
} else {
None
}
})
.collect()
})
}

pub fn table_summary(
Expand Down
27 changes: 27 additions & 0 deletions crates/typed-store/src/rocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,23 @@ pub struct DBOptions {
/// Creates a default RocksDB option, to be used when RocksDB option is not specified..
pub fn default_db_options() -> DBOptions {
let mut opt = rocksdb::Options::default();

// One common issue when running tests on Mac is that the default ulimit is too low,
// leading to I/O errors such as "Too many open files". Raising fdlimit to bypass it.
if let Some(limit) = fdlimit::raise_fd_limit() {
// on windows raise_fd_limit return None
opt.set_max_open_files((limit / 8) as i32);
}

let row_cache = rocksdb::Cache::new_lru_cache(300_000).expect("Cache is ok");
opt.set_row_cache(&row_cache);

// The table cache is locked for updates and this determines the number
// of shards, ie 2^10. Increase in case of lock contentions.
opt.set_table_cache_num_shard_bits(10);

opt.set_compression_type(rocksdb::DBCompressionType::None);

// Sui uses multiple RocksDB in a node, so total sizes of write buffers and WAL can be higher
// than the limits below.
//
Expand Down Expand Up @@ -1821,6 +1838,16 @@ pub fn default_db_options() -> DBOptions {
}
}

/// Creates a default RocksDB option, optimized for point lookup.
pub fn point_lookup_db_options() -> DBOptions {
let mut db_options = default_db_options();
db_options
.options
.optimize_for_point_lookup(64 /* 64MB (default is 8) */);
db_options.options.set_memtable_whole_key_filtering(true);
db_options
}

/// Opens a database with options, and a number of column families that are created if they do not exist.
#[instrument(level="debug", skip_all, fields(path = ?path.as_ref(), cf = ?opt_cfs), err)]
pub fn open_cf<P: AsRef<Path>>(
Expand Down

0 comments on commit 87f5996

Please sign in to comment.