misc changes

This commit is contained in:
Boog900 2024-07-26 22:21:06 +01:00
parent d3c6128fc7
commit d646eac694
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
6 changed files with 31 additions and 10 deletions

View file

@ -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"

View file

@ -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<ConcreteEnv>, 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<ConcreteEnv>, pool: Arc<ThreadPool>) -> BCReadHandle {
DatabaseReadService::new(env, pool, map_request)
}

View file

@ -1,5 +1,3 @@
#![allow(clippy::impl_trait_in_params)]
mod reader_threads;
mod service;

View file

@ -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<ThreadPool> {
// How many reader threads to spawn?
let reader_count = reader_threads.as_threads().get();

View file

@ -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<Req, Res> {
/// 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<ThreadPool>,
/// The function used to handle request.
inner_handler: Arc<dyn Fn(Req) -> Result<Res, RuntimeError> + Send + Sync + 'static>,
}
// deriving clone means Req & Res needs to be clone, when they don't.
impl<Req, Res> Clone for DatabaseReadService<Req, Res> {
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<ConcreteEnv>,
pool: Arc<ThreadPool>,

View file

@ -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.