@@ -34,7 +34,7 @@ use std::fmt;
3434use std:: { any:: Any , collections:: HashMap , env, sync:: Arc } ;
3535use tokio:: sync:: RwLock ;
3636use tokio_util:: sync:: CancellationToken ;
37- use tracing:: { debug, error, info} ;
37+ use tracing:: { debug, error, info, warn } ;
3838use url:: Url ;
3939
4040// Changed to support multiple tables per project: (project_id, table_name) -> DeltaTable
@@ -349,14 +349,24 @@ impl Database {
349349 config. ttl. as_secs( )
350350 ) ;
351351
352- match SharedFoyerCache :: new ( config) . await {
353- Ok ( cache) => {
354- info ! ( "Shared Foyer cache initialized successfully for all tables" ) ;
355- Some ( Arc :: new ( cache) )
356- }
357- Err ( e) => {
358- error ! ( "Failed to initialize shared Foyer cache: {}. Continuing without cache." , e) ;
359- None
352+ // Retry cache initialization a few times to handle transient failures
353+ let mut retry_count = 0 ;
354+ let max_retries = 3 ;
355+ loop {
356+ match SharedFoyerCache :: new ( config. clone ( ) ) . await {
357+ Ok ( cache) => {
358+ info ! ( "Shared Foyer cache initialized successfully for all tables" ) ;
359+ break Some ( Arc :: new ( cache) ) ;
360+ }
361+ Err ( e) => {
362+ retry_count += 1 ;
363+ if retry_count >= max_retries {
364+ error ! ( "Failed to initialize shared Foyer cache after {} retries: {}. Continuing without cache." , max_retries, e) ;
365+ break None ;
366+ }
367+ warn ! ( "Failed to initialize shared Foyer cache (attempt {}/{}): {}. Retrying..." , retry_count, max_retries, e) ;
368+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
369+ }
360370 }
361371 }
362372 } ;
@@ -891,13 +901,14 @@ impl Database {
891901 // Create the base S3 object store
892902 let base_store = self . create_object_store ( & storage_uri, & storage_options) . await ?;
893903
894- // Wrap with the shared Foyer cache
904+ // Wrap with the shared Foyer cache if available, otherwise use base store
895905 let cached_store = if let Some ( ref shared_cache) = self . object_store_cache {
896906 // Create a new wrapper around the base store using our shared cache
897907 // This allows the same cache to be used across all tables
898- Arc :: new ( FoyerObjectStoreCache :: new_with_shared_cache ( base_store, shared_cache) ) as Arc < dyn object_store:: ObjectStore >
908+ Arc :: new ( FoyerObjectStoreCache :: new_with_shared_cache ( base_store. clone ( ) , shared_cache) ) as Arc < dyn object_store:: ObjectStore >
899909 } else {
900- return Err ( anyhow:: anyhow!( "Shared Foyer cache not initialized" ) ) ;
910+ warn ! ( "Shared Foyer cache not initialized, using uncached object store" ) ;
911+ base_store
901912 } ;
902913
903914 // Try to load or create the table with the cached object store
@@ -1832,7 +1843,7 @@ mod tests {
18321843 project_id, date, timestamp, id, hashes, name, level, status_code, summary
18331844 ) VALUES (
18341845 'project2', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T10:00:00Z',
1835- 'sql_id', ARRAY[], 'sql_name', 'INFO', 'OK', 'SQL inserted test span'
1846+ 'sql_id', ARRAY[], 'sql_name', 'INFO', 'OK', ARRAY[ 'SQL inserted test span']
18361847 )" ;
18371848 let result = ctx. sql ( sql) . await ?. collect ( ) . await ?;
18381849 assert_eq ! ( result[ 0 ] . num_rows( ) , 1 ) ;
@@ -1869,9 +1880,9 @@ mod tests {
18691880 let sql = "INSERT INTO otel_logs_and_spans (
18701881 project_id, date, timestamp, id, hashes, name, level, status_code, summary
18711882 ) VALUES
1872- ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T10:00:00Z', 'id1', ARRAY[], 'name1', 'INFO', 'OK', 'Multi-row insert test 1'),
1873- ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T11:00:00Z', 'id2', ARRAY[], 'name2', 'INFO', 'OK', 'Multi-row insert test 2'),
1874- ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T12:00:00Z', 'id3', ARRAY[], 'name3', 'ERROR', 'ERROR', 'Multi-row insert test 3 - ERROR')" ;
1883+ ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T10:00:00Z', 'id1', ARRAY[], 'name1', 'INFO', 'OK', ARRAY[ 'Multi-row insert test 1'] ),
1884+ ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T11:00:00Z', 'id2', ARRAY[], 'name2', 'INFO', 'OK', ARRAY[ 'Multi-row insert test 2'] ),
1885+ ('project1', TIMESTAMP '2023-01-01', TIMESTAMP '2023-01-01T12:00:00Z', 'id3', ARRAY[], 'name3', 'ERROR', 'ERROR', ARRAY[ 'Multi-row insert test 3 - ERROR'] )" ;
18751886
18761887 // Multi-row INSERT returns a count of rows inserted
18771888 let result = ctx. sql ( sql) . await ?. collect ( ) . await ?;
0 commit comments