Skip to content

Commit

Permalink
feat(reqpool): remove memory pool
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jan 14, 2025
1 parent c4f5787 commit 65c5d7e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 123 deletions.
3 changes: 1 addition & 2 deletions reqpool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod config;
mod macros;
mod memory_pool;
#[cfg(test)]
#[cfg(any(test, feature = "enable-mock"))]
mod mock;
mod redis_pool;
mod request;
Expand Down
115 changes: 0 additions & 115 deletions reqpool/src/memory_pool.rs

This file was deleted.

3 changes: 3 additions & 0 deletions reqpool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type GlobalStorage = Mutex<HashMap<String, SingleStorage>>;

lazy_static! {
// #{redis_url => single_storage}
//
// We use redis_url to distinguish different redis database for tests, to prevent
// data race problem when running multiple tests.
static ref GLOBAL_STORAGE: GlobalStorage = Mutex::new(HashMap::new());
}

Expand Down
14 changes: 8 additions & 6 deletions reqpool/src/redis_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use crate::{
impl_display_using_json_pretty, proof_key_to_hack_request_key, RedisPoolConfig, RequestEntity,
RequestKey, StatusWithContext,
};
use backoff::{exponential::ExponentialBackoff, SystemClock};
use raiko_lib::prover::{IdStore, IdWrite, ProofKey, ProverError, ProverResult};
use raiko_redis_derive::RedisValue;
#[allow(unused_imports)]
use redis::{Client, Commands, RedisResult};
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[derive(Debug, Clone)]
pub struct Pool {
Expand Down Expand Up @@ -136,19 +137,20 @@ impl Pool {
Ok(Self { client, config })
}

#[cfg(test)]
#[cfg(any(test, feature = "enable-mock"))]
pub(crate) fn conn(&mut self) -> Result<crate::mock::MockRedisConnection, redis::RedisError> {
let _ = self.client;
Ok(crate::mock::MockRedisConnection::new(
self.config.redis_url.clone(),
))
}

#[cfg(not(test))]
#[cfg(not(any(test, feature = "enable-mock")))]
fn conn(&mut self) -> Result<redis::Connection, redis::RedisError> {
use backoff::{exponential::ExponentialBackoff, SystemClock};
use std::time::Duration;
self.redis_conn()
}

#[allow(dead_code)]
fn redis_conn(&mut self) -> Result<redis::Connection, redis::RedisError> {
let backoff: ExponentialBackoff<SystemClock> = ExponentialBackoff {
initial_interval: Duration::from_secs(10),
max_interval: Duration::from_secs(60),
Expand Down

0 comments on commit 65c5d7e

Please sign in to comment.