mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Consolidate RockDB code
Moves explicitly to zstd. RockDB recommends zstd, or at least lz4 over snappy, and this minimizes which dependencies we pull in.
This commit is contained in:
parent
49ce792b91
commit
32435d8a4c
6 changed files with 15 additions and 22 deletions
|
@ -13,7 +13,7 @@ all-features = true
|
|||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[dependencies]
|
||||
rocksdb = { version = "0.21", optional = true }
|
||||
rocksdb = { version = "0.21", default-features = false, features = ["zstd"], optional = true }
|
||||
|
||||
[features]
|
||||
rocksdb = ["dep:rocksdb"]
|
||||
|
|
|
@ -3,6 +3,8 @@ pub use mem::*;
|
|||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
mod rocks;
|
||||
#[cfg(feature = "rocksdb")]
|
||||
pub use rocks::{RocksDB, new_rocksdb};
|
||||
|
||||
/// An object implementing get.
|
||||
pub trait Get {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use rocksdb::{ThreadMode, Transaction, TransactionDB};
|
||||
use rocksdb::{DBCompressionType, ThreadMode, SingleThreaded, Options, Transaction, TransactionDB};
|
||||
|
||||
use crate::*;
|
||||
|
||||
|
@ -32,3 +32,10 @@ impl<T: ThreadMode + 'static> Db for Arc<TransactionDB<T>> {
|
|||
self.transaction()
|
||||
}
|
||||
}
|
||||
|
||||
pub type RocksDB = Arc<TransactionDB<SingleThreaded>>;
|
||||
pub fn new_rocksdb(path: &str) -> RocksDB {
|
||||
let mut options = Options::default();
|
||||
options.set_compression_type(DBCompressionType::Zstd);
|
||||
Arc::new(TransactionDB::open(&options, &Default::default(), path).unwrap())
|
||||
}
|
||||
|
|
|
@ -669,12 +669,7 @@ pub async fn run<D: Db, Pro: Processors, P: P2p>(
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let db = Arc::new(
|
||||
rocksdb::TransactionDB::<rocksdb::SingleThreaded>::open_default(
|
||||
env::var("DB_PATH").expect("path to DB wasn't specified"),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let db = serai_db::new_rocksdb(&env::var("DB_PATH").expect("path to DB wasn't specified"));
|
||||
|
||||
let key = Zeroizing::new(<Ristretto as Ciphersuite>::F::ZERO); // TODO
|
||||
let p2p = LocalP2p::new(1).swap_remove(0); // TODO
|
||||
|
|
|
@ -16,7 +16,7 @@ use messages::*;
|
|||
mod queue;
|
||||
use queue::Queue;
|
||||
|
||||
type Db = Arc<rocksdb::TransactionDB>;
|
||||
type Db = serai_db::RocksDB;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref KEYS: Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>> =
|
||||
|
@ -117,12 +117,7 @@ async fn main() {
|
|||
log::info!("Starting message-queue service...");
|
||||
|
||||
// Open the DB
|
||||
let db = Arc::new(
|
||||
rocksdb::TransactionDB::open_default(
|
||||
serai_env::var("DB_PATH").expect("path to DB wasn't specified"),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let db = serai_db::new_rocksdb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
|
||||
|
||||
let read_key = |str| {
|
||||
let key = serai_env::var(str)?;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::{
|
||||
time::Duration,
|
||||
sync::Arc,
|
||||
collections::{VecDeque, HashMap},
|
||||
};
|
||||
|
||||
|
@ -730,12 +729,7 @@ async fn main() {
|
|||
}
|
||||
env_logger::init();
|
||||
|
||||
let db = Arc::new(
|
||||
rocksdb::TransactionDB::<rocksdb::SingleThreaded>::open_default(
|
||||
env::var("DB_PATH").expect("path to DB wasn't specified"),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let db = serai_db::new_rocksdb(&env::var("DB_PATH").expect("path to DB wasn't specified"));
|
||||
|
||||
// Network configuration
|
||||
let url = {
|
||||
|
|
Loading…
Reference in a new issue