@@ -27,14 +27,12 @@ use foyer::HybridCachePolicy;
2727use foyer:: IoEngineConfig ;
2828use foyer:: IopsCounter ;
2929use foyer:: LfuConfig ;
30- use foyer:: PsyncIoEngineConfig ;
3130use foyer:: RecoverMode ;
3231use foyer:: Spawner ;
3332use mixtrics:: registry:: noop:: NoopMetricsRegistry ;
3433use mixtrics:: registry:: opentelemetry_0_31:: OpenTelemetryMetricsRegistry ;
3534use parse_display:: Display ;
3635
37- use crate :: Runtime ;
3836use crate :: newtype:: DiskThrottle ;
3937use crate :: num_cpus;
4038use crate :: runtime;
@@ -51,12 +49,11 @@ impl std::error::Error for EngineError {}
5149pub struct FoyerEngine {
5250 inner : HybridCache < Vec < u8 > , Vec < u8 > > ,
5351 capacity : ByteSize ,
54- #[ expect( dead_code) ]
55- runtime : Runtime ,
5652}
5753
5854impl FoyerEngine {
5955 pub async fn try_new (
56+ io_runtime : & runtime:: Runtime ,
6057 data_dir : & Path ,
6158 memory_capacity : ByteSize ,
6259 disk_capacity : ByteSize ,
@@ -96,8 +93,6 @@ impl FoyerEngine {
9693 . build ( )
9794 . map_err ( |err| EngineError ( format ! ( "failed to create device: {err}" ) ) ) ?;
9895
99- let psync_engine = Box :: new ( PsyncIoEngineConfig :: new ( ) ) ;
100-
10196 let io_engine: Box < dyn IoEngineConfig > = {
10297 #[ cfg( target_os = "linux" ) ]
10398 {
@@ -107,16 +102,11 @@ impl FoyerEngine {
107102
108103 #[ cfg( not( target_os = "linux" ) ) ]
109104 {
110- psync_engine
105+ use foyer:: PsyncIoEngineConfig ;
106+ Box :: new ( PsyncIoEngineConfig :: new ( ) )
111107 }
112108 } ;
113109
114- let runtime = runtime:: Builder :: new ( "foyer_io_runtime" , "foyer_io_thread" )
115- . worker_threads ( 4 )
116- . max_blocking_threads ( num_cpus ( ) . get ( ) * 2 )
117- . build ( )
118- . map_err ( |err| EngineError ( format ! ( "failed to build foyer IO runtime: {err}" ) ) ) ?;
119-
120110 let parallelism = num_cpus ( ) . get ( ) ;
121111 let cache = HybridCacheBuilder :: new ( )
122112 . with_policy ( HybridCachePolicy :: WriteOnEviction )
@@ -141,15 +131,14 @@ impl FoyerEngine {
141131 )
142132 . with_io_engine_config ( io_engine)
143133 . with_recover_mode ( RecoverMode :: Quiet )
144- . with_spawner ( runtime . spawn_blocking ( Spawner :: current) . await )
134+ . with_spawner ( io_runtime . spawn_blocking ( Spawner :: current) . await )
145135 . build ( )
146136 . await
147137 . map_err ( |err| EngineError ( err. to_string ( ) ) ) ?;
148138
149139 Ok ( FoyerEngine {
150140 inner : cache,
151141 capacity : disk_capacity,
152- runtime,
153142 } )
154143 }
155144
@@ -188,25 +177,30 @@ mod tests {
188177
189178 use super :: * ;
190179
191- #[ tokio:: test]
192- async fn test_get ( ) {
193- let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
194-
195- let engine = FoyerEngine :: try_new (
196- temp_dir. path ( ) ,
197- ByteSize :: kib ( 512 ) ,
198- ByteSize :: mib ( 1 ) ,
199- None ,
200- None ,
201- )
202- . await
203- . unwrap ( ) ;
204-
205- engine. put ( b"foo" . to_vec ( ) . as_ref ( ) , b"bar" . to_vec ( ) . as_ref ( ) ) ;
206-
207- assert_compact_debug_snapshot ! (
208- engine. get( b"foo" . to_vec( ) . as_ref( ) ) . await ,
209- @"Some([98, 97, 114])"
210- ) ;
180+ #[ test]
181+ fn test_get ( ) {
182+ let runtime = runtime:: make_runtime ( "test_runtime" , "test_thread" , 2 ) ;
183+
184+ runtime. block_on ( async {
185+ let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
186+
187+ let engine = FoyerEngine :: try_new (
188+ & runtime,
189+ temp_dir. path ( ) ,
190+ ByteSize :: kib ( 512 ) ,
191+ ByteSize :: mib ( 1 ) ,
192+ None ,
193+ None ,
194+ )
195+ . await
196+ . unwrap ( ) ;
197+
198+ engine. put ( b"foo" . to_vec ( ) . as_ref ( ) , b"bar" . to_vec ( ) . as_ref ( ) ) ;
199+
200+ assert_compact_debug_snapshot ! (
201+ engine. get( b"foo" . to_vec( ) . as_ref( ) ) . await ,
202+ @"Some([98, 97, 114])"
203+ ) ;
204+ } ) ;
211205 }
212206}
0 commit comments