Use spawn_blocking for storage task.

This commit is contained in:
Peilun Li 2024-06-20 16:57:15 +08:00
parent 8f37a4a594
commit c67ae6f835
9 changed files with 8 additions and 21 deletions

View File

@ -2,7 +2,6 @@ use async_trait::async_trait;
use std::sync::Arc;
use storage::log_store::{MineLoadChunk, Store};
#[async_trait]
pub trait PoraLoader: Send + Sync {
async fn load_sealed_data(&self, index: u64) -> Option<MineLoadChunk>;

View File

@ -8,7 +8,6 @@ use std::sync::Arc;
use storage::log_store::{config::ConfigurableExt, Store};
use storage::H256;
const MINER_ID: &str = "mine.miner_id";
pub fn load_miner_id(store: &dyn Store) -> storage::error::Result<Option<H256>> {

View File

@ -1,9 +1,7 @@
use std::{collections::BTreeMap, sync::Arc};
use ethereum_types::H256;
use tokio::{
time::{sleep, Duration, Instant},
};
use tokio::time::{sleep, Duration, Instant};
use contract_interface::{EpochRangeWithContextDigest, ZgsFlow};
use storage::{

View File

@ -6,8 +6,8 @@ use network::NetworkMessage;
use std::sync::Arc;
use storage::config::ShardConfig;
use storage::log_store::Store;
use tokio::sync::broadcast;
use tokio::sync::mpsc;
use tokio::sync::{broadcast};
#[derive(Clone, Debug)]
pub enum MinerMessage {

View File

@ -8,7 +8,7 @@ use shared_types::FlowRangeProof;
use std::sync::Arc;
use storage::log_store::Store;
use task_executor::TaskExecutor;
use tokio::sync::{mpsc};
use tokio::sync::mpsc;
use crate::config::{MineServiceMiddleware, MinerConfig};
use crate::pora::AnswerWithoutProof;

View File

@ -6,7 +6,7 @@ use shared_types::{Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof,
use std::sync::Arc;
use storage::{error, error::Result, log_store::Store as LogStore, H256};
use task_executor::TaskExecutor;
use tokio::sync::{oneshot};
use tokio::sync::oneshot;
pub use storage::config::ShardConfig;
@ -70,8 +70,8 @@ impl Store {
let store = self.store.clone();
let (tx, rx) = oneshot::channel();
self.executor.spawn(
async move {
self.executor.spawn_blocking(
move || {
// FIXME(zz): Not all functions need `write`. Refactor store usage.
let res = f(&*store);

View File

@ -71,10 +71,7 @@ impl SyncStore {
let mut tx = ConfigTx::default();
// not in pending queue
if !self
.pending_txs
.remove(store, Some(&mut tx), tx_seq)?
{
if !self.pending_txs.remove(store, Some(&mut tx), tx_seq)? {
return Ok(false);
}
@ -92,10 +89,7 @@ impl SyncStore {
let mut tx = ConfigTx::default();
// not in ready queue
if !self
.ready_txs
.remove(store, Some(&mut tx), tx_seq)?
{
if !self.ready_txs.remove(store, Some(&mut tx), tx_seq)? {
return Ok(false);
}

View File

@ -652,7 +652,6 @@ mod tests {
use task_executor::{test_utils::TestRuntime, TaskExecutor};
use tokio::sync::mpsc::{self, UnboundedReceiver};
#[test]
fn test_status() {
let runtime = TestRuntime::default();

View File

@ -9,7 +9,6 @@ use storage::{
LogManager,
};
/// Creates stores for local node and peers with initialized transaction of specified chunk count.
/// The first store is for local node, and data not stored. The second store is for peers, and all
/// transactions are finalized for file sync.
@ -102,7 +101,6 @@ pub mod tests {
use storage_async::Store;
use task_executor::test_utils::TestRuntime;
pub struct TestStoreRuntime {
pub runtime: TestRuntime,
pub store: Store,