@@ -24,7 +24,6 @@ use parking_lot::RwLock;
2424use std:: collections:: HashMap ;
2525use std:: io;
2626use std:: path:: { Path , PathBuf } ;
27- use std:: sync:: Arc ;
2827use tempfile:: TempDir ;
2928use tokio:: io:: AsyncWriteExt ;
3029use tokio:: sync:: oneshot;
@@ -117,14 +116,14 @@ impl RemoteLogDownloadFuture {
117116/// Downloader for remote log segment files
118117pub struct RemoteLogDownloader {
119118 local_log_dir : TempDir ,
120- s3_props : Arc < RwLock < HashMap < String , String > > > ,
119+ s3_props : RwLock < HashMap < String , String > > ,
121120}
122121
123122impl RemoteLogDownloader {
124123 pub fn new ( local_log_dir : TempDir ) -> Result < Self > {
125124 Ok ( Self {
126125 local_log_dir,
127- s3_props : Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ,
126+ s3_props : RwLock :: new ( HashMap :: new ( ) ) ,
128127 } )
129128 }
130129
@@ -175,16 +174,6 @@ impl RemoteLogDownloader {
175174 local_path : & Path ,
176175 s3_props : & HashMap < String , String > ,
177176 ) -> Result < PathBuf > {
178- eprintln ! ( "[DEBUG] download_file called: remote_path={}" , remote_path) ;
179- eprintln ! ( "[DEBUG] s3_props count: {}" , s3_props. len( ) ) ;
180- for ( k, v) in s3_props {
181- if k. contains ( "key" ) || k. contains ( "secret" ) {
182- eprintln ! ( "[DEBUG] {} = {}..." , k, & v[ ..std:: cmp:: min( 8 , v. len( ) ) ] ) ;
183- } else {
184- eprintln ! ( "[DEBUG] {} = {}" , k, v) ;
185- }
186- }
187-
188177 // Handle both URL (e.g., "s3://bucket/path") and local file paths
189178 // If the path doesn't contain "://", treat it as a local file path
190179 let remote_log_tablet_dir_url = if remote_log_tablet_dir. contains ( "://" ) {
@@ -212,46 +201,56 @@ impl RemoteLogDownloader {
212201 // Timeout for remote storage operations (30 seconds)
213202 const REMOTE_OP_TIMEOUT : std:: time:: Duration = std:: time:: Duration :: from_secs ( 30 ) ;
214203
215- eprintln ! ( "[DEBUG] Calling stat on: {}" , relative_path) ;
216204 // Get file metadata to know the size with timeout
217205 let stat_future = op. stat ( relative_path) ;
218206 let meta = tokio:: time:: timeout ( REMOTE_OP_TIMEOUT , stat_future)
219207 . await
220- . map_err ( |_| Error :: Io ( io:: Error :: new (
221- io:: ErrorKind :: TimedOut ,
222- format ! ( "Timeout getting file metadata from remote storage: {}" , remote_path)
223- ) ) ) ??;
208+ . map_err ( |_| {
209+ Error :: Io ( io:: Error :: new (
210+ io:: ErrorKind :: TimedOut ,
211+ format ! (
212+ "Timeout getting file metadata from remote storage: {}" ,
213+ remote_path
214+ ) ,
215+ ) )
216+ } ) ??;
224217 let file_size = meta. content_length ( ) ;
225- eprintln ! ( "[DEBUG] stat succeeded, file_size={}" , file_size) ;
226218
227219 // Create local file for writing
228220 let mut local_file = tokio:: fs:: File :: create ( local_path) . await ?;
229221
230222 // Stream data from remote to local file in chunks
231223 // opendal::Reader::read accepts a range, so we read in chunks
232- const CHUNK_SIZE : u64 = 8 * 1024 * 1024 ; // 8MB chunks for efficient streaming
224+ const CHUNK_SIZE : u64 = 8 * 1024 * 1024 ; // 8MB chunks for efficient reading
233225 let mut offset = 0u64 ;
234226 let mut chunk_count = 0u64 ;
235- let total_chunks = ( file_size + CHUNK_SIZE - 1 ) / CHUNK_SIZE ;
236- eprintln ! ( "[DEBUG] Starting download: {} bytes in {} chunks" , file_size, total_chunks) ;
227+ let total_chunks = file_size. div_ceil ( CHUNK_SIZE ) ;
237228
238229 while offset < file_size {
239230 let end = std:: cmp:: min ( offset + CHUNK_SIZE , file_size) ;
240231 let range = offset..end;
241232 chunk_count += 1 ;
242233
243234 if chunk_count <= 3 || chunk_count % 10 == 0 {
244- eprintln ! ( "[DEBUG] Reading chunk {}/{} (offset {})" , chunk_count, total_chunks, offset) ;
235+ eprintln ! (
236+ "Remote log download: reading chunk {}/{} (offset {})" ,
237+ chunk_count, total_chunks, offset
238+ ) ;
245239 }
246240
247241 // Read chunk from remote storage with timeout
248242 let read_future = op. read_with ( relative_path) . range ( range. clone ( ) ) ;
249243 let chunk = tokio:: time:: timeout ( REMOTE_OP_TIMEOUT , read_future)
250244 . await
251- . map_err ( |_| Error :: Io ( io:: Error :: new (
252- io:: ErrorKind :: TimedOut ,
253- format ! ( "Timeout reading chunk from remote storage: {} at offset {}" , remote_path, offset)
254- ) ) ) ??;
245+ . map_err ( |_| {
246+ Error :: Io ( io:: Error :: new (
247+ io:: ErrorKind :: TimedOut ,
248+ format ! (
249+ "Timeout reading chunk from remote storage: {} at offset {}" ,
250+ remote_path, offset
251+ ) ,
252+ ) )
253+ } ) ??;
255254 let bytes = chunk. to_bytes ( ) ;
256255
257256 // Write chunk to local file
0 commit comments