From d646eac6946893e00bb166da953132381bd0ed1e Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Fri, 26 Jul 2024 22:21:06 +0100 Subject: [PATCH] misc changes --- Cargo.toml | 1 - storage/blockchain/src/service/read.rs | 13 ++++++++++++- storage/service/src/lib.rs | 2 -- storage/service/src/reader_threads.rs | 2 +- storage/service/src/service/read.rs | 11 ++++++++++- storage/service/src/service/write.rs | 12 ++++++++---- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ebaefd9..da82d9ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -244,7 +244,6 @@ try_err = "deny" lossy_float_literal = "deny" let_underscore_must_use = "deny" iter_over_hash_type = "deny" -impl_trait_in_params = "deny" get_unwrap = "deny" error_impl_error = "deny" empty_structs_with_brackets = "deny" diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index 664b35e4..a549d3a7 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -37,13 +37,24 @@ use crate::{ }; //---------------------------------------------------------------------------------------------------- init_read_service -/// Initialize the blockchain database read service. +/// Initialize the [`BCReadHandle`] thread-pool backed by `rayon`. +/// +/// This spawns `threads` amount of reader threads +/// attached to `env` and returns a handle to the pool. +/// +/// Should be called _once_ per actual database. +#[cold] +#[inline(never)] // Only called once. pub fn init_read_service(env: Arc, threads: ReaderThreads) -> BCReadHandle { init_read_service_with_pool(env, init_thread_pool(threads)) } /// Initialize the blockchain database read service, with a specific rayon thread-pool instead of /// creating a new one. +/// +/// Should be called _once_ per actual database. +#[cold] +#[inline(never)] // Only called once. pub fn init_read_service_with_pool(env: Arc, pool: Arc) -> BCReadHandle { DatabaseReadService::new(env, pool, map_request) } diff --git a/storage/service/src/lib.rs b/storage/service/src/lib.rs index 1a2a54ca..543174a2 100644 --- a/storage/service/src/lib.rs +++ b/storage/service/src/lib.rs @@ -1,5 +1,3 @@ -#![allow(clippy::impl_trait_in_params)] - mod reader_threads; mod service; diff --git a/storage/service/src/reader_threads.rs b/storage/service/src/reader_threads.rs index b4408b33..506ca392 100644 --- a/storage/service/src/reader_threads.rs +++ b/storage/service/src/reader_threads.rs @@ -16,7 +16,7 @@ use rayon::ThreadPool; use serde::{Deserialize, Serialize}; //---------------------------------------------------------------------------------------------------- init_thread_pool - +/// Initialize the reader thread-pool backed by `rayon`. pub fn init_thread_pool(reader_threads: ReaderThreads) -> Arc { // How many reader threads to spawn? let reader_count = reader_threads.as_threads().get(); diff --git a/storage/service/src/service/read.rs b/storage/service/src/service/read.rs index 00d39674..5e4be93f 100644 --- a/storage/service/src/service/read.rs +++ b/storage/service/src/service/read.rs @@ -14,13 +14,17 @@ use cuprate_helper::asynch::InfallibleOneshotReceiver; /// /// Uses an inner request handler and a rayon thread-pool to asynchronously handler requests. pub struct DatabaseReadService { - /// The rayon thread-pool. + /// Handle to the custom `rayon` DB reader thread-pool. + /// + /// Requests are [`rayon::ThreadPool::spawn`]ed in this thread-pool, + /// and responses are returned via a channel we (the caller) provide. pool: Arc, /// The function used to handle request. inner_handler: Arc Result + Send + Sync + 'static>, } +// deriving clone means Req & Res needs to be clone, when they don't. impl Clone for DatabaseReadService { fn clone(&self) -> Self { Self { @@ -35,6 +39,11 @@ where Req: Send + 'static, Res: Send + 'static, { + /// Creates the [`DatabaseReadService`] with the provided backing thread-pool. + /// + /// Should be called _once_ per actual database. + #[cold] + #[inline(never)] // Only called once. pub fn new( env: Arc, pool: Arc, diff --git a/storage/service/src/service/write.rs b/storage/service/src/service/write.rs index 56d0a3f6..f75d6151 100644 --- a/storage/service/src/service/write.rs +++ b/storage/service/src/service/write.rs @@ -1,9 +1,13 @@ +use std::{ + fmt::Debug, + sync::Arc, + task::{Context, Poll}, +}; + +use futures::channel::oneshot; + use cuprate_database::{ConcreteEnv, Env, RuntimeError}; use cuprate_helper::asynch::InfallibleOneshotReceiver; -use futures::channel::oneshot; -use std::fmt::Debug; -use std::sync::Arc; -use std::task::{Context, Poll}; //---------------------------------------------------------------------------------------------------- Constants /// Name of the writer thread.