@@ -108,7 +108,7 @@ pub async fn registry_index(
108
108
Ok ( ( ) )
109
109
}
110
110
111
- #[ tracing:: instrument( skip ( pkg ) ) ]
111
+ #[ tracing:: instrument( level = "debug" , skip_all , fields ( name = krate . name , version = krate . version , rev = %rev . id ) ) ]
112
112
fn sync_git (
113
113
db_dir : & Path ,
114
114
co_dir : & Path ,
@@ -126,7 +126,13 @@ fn sync_git(
126
126
let crate :: git:: GitPackage { db, checkout } = pkg;
127
127
128
128
let unpack_path = db_path. clone ( ) ;
129
- util:: unpack_tar ( db, util:: Encoding :: Zstd , & unpack_path) ?;
129
+ let compressed = db. len ( ) ;
130
+ let uncompressed = util:: unpack_tar ( db, util:: Encoding :: Zstd , & unpack_path) ?;
131
+ debug ! (
132
+ compressed = compressed,
133
+ uncompressed = uncompressed,
134
+ "unpacked db dir"
135
+ ) ;
130
136
131
137
let co_path = co_dir. join ( format ! ( "{}/{}" , krate. local_id( ) , rev. short( ) ) ) ;
132
138
@@ -143,7 +149,13 @@ fn sync_git(
143
149
// otherwise do a checkout
144
150
match checkout {
145
151
Some ( checkout) => {
146
- util:: unpack_tar ( checkout, util:: Encoding :: Zstd , & co_path) ?;
152
+ let compressed = checkout. len ( ) ;
153
+ let uncompressed = util:: unpack_tar ( checkout, util:: Encoding :: Zstd , & co_path) ?;
154
+ debug ! (
155
+ compressed = compressed,
156
+ uncompressed = uncompressed,
157
+ "unpacked checkout dir"
158
+ ) ;
147
159
}
148
160
None => {
149
161
// Do a checkout of the bare clone if we didn't/couldn't unpack the
@@ -158,7 +170,7 @@ fn sync_git(
158
170
Ok ( ( ) )
159
171
}
160
172
161
- #[ tracing:: instrument( level = "debug" , skip ( data ) ) ]
173
+ #[ tracing:: instrument( level = "debug" , skip_all , fields ( name = krate . name , version = krate . version ) ) ]
162
174
fn sync_package (
163
175
cache_dir : & Path ,
164
176
src_dir : & Path ,
@@ -185,7 +197,7 @@ fn sync_package(
185
197
f. write_all ( & pack_data) ?;
186
198
f. sync_all ( ) ?;
187
199
188
- debug ! ( bytes = pack_data. len( ) , path = ?packed_path , "wrote pack file to disk" ) ;
200
+ debug ! ( bytes = pack_data. len( ) , "wrote pack file to disk" ) ;
189
201
Ok ( ( ) )
190
202
} ,
191
203
|| -> anyhow:: Result < ( ) > {
@@ -410,15 +422,71 @@ pub async fn crates(ctx: &crate::Ctx) -> anyhow::Result<Summary> {
410
422
} ) ;
411
423
}
412
424
413
- let summary = std:: sync:: Mutex :: new ( Summary {
425
+ let summary = std:: sync:: Arc :: new ( std :: sync :: Mutex :: new ( Summary {
414
426
total_bytes : 0 ,
415
427
bad : 0 ,
416
428
good : 0 ,
417
- } ) ;
429
+ } ) ) ;
430
+
431
+ let ( tx, rx) = crossbeam_channel:: unbounded :: < ( Krate , Pkg ) > ( ) ;
432
+ let fs_thread = {
433
+ let summary = summary. clone ( ) ;
434
+ let root_dir = root_dir. clone ( ) ;
435
+
436
+ std:: thread:: spawn ( move || {
437
+ let db_dir = & git_db_dir;
438
+ let co_dir = & git_co_dir;
439
+ let root_dir = & root_dir;
440
+ let summary = & summary;
441
+ rayon:: scope ( |s| {
442
+ while let Ok ( ( krate, pkg) ) = rx. recv ( ) {
443
+ s. spawn ( move |_s| {
444
+ let synced = match ( & krate. source , pkg) {
445
+ ( Source :: Registry ( rs) , Pkg :: Registry ( krate_data) ) => {
446
+ let len = krate_data. len ( ) ;
447
+ let ( cache_dir, src_dir) = rs. registry . sync_dirs ( root_dir) ;
448
+ if let Err ( err) = sync_package (
449
+ & cache_dir, & src_dir, & krate, krate_data, & rs. chksum ,
450
+ ) {
451
+ error ! ( krate = %krate, "failed to splat package: {err:#}" ) ;
452
+ None
453
+ } else {
454
+ Some ( len)
455
+ }
456
+ }
457
+ ( Source :: Git ( gs) , Pkg :: Git ( pkg) ) => {
458
+ let mut len = pkg. db . len ( ) ;
459
+
460
+ if let Some ( co) = & pkg. checkout {
461
+ len += co. len ( ) ;
462
+ }
463
+
464
+ match sync_git ( db_dir, co_dir, & krate, pkg, & gs. rev ) {
465
+ Ok ( _) => Some ( len) ,
466
+ Err ( err) => {
467
+ error ! ( krate = %krate, "failed to splat git repo: {err:#}" ) ;
468
+ None
469
+ }
470
+ }
471
+ }
472
+ _ => unreachable ! ( ) ,
473
+ } ;
474
+
475
+ let mut sum = summary. lock ( ) . unwrap ( ) ;
476
+ if let Some ( synced) = synced {
477
+ sum. good += 1 ;
478
+ sum. total_bytes += synced;
479
+ } else {
480
+ sum. bad += 1 ;
481
+ }
482
+ } ) ;
483
+ }
484
+ } ) ;
485
+ } )
486
+ } ;
418
487
419
488
// As each remote I/O op completes, pass it off to the thread pool to do
420
489
// the more CPU intensive work of decompression, etc
421
- let ( tx, rx) = crossbeam_channel:: unbounded ( ) ;
422
490
while let Some ( res) = tasks. join_next ( ) . await {
423
491
let Ok ( res) = res else { continue ; } ;
424
492
@@ -429,59 +497,13 @@ pub async fn crates(ctx: &crate::Ctx) -> anyhow::Result<Summary> {
429
497
}
430
498
}
431
499
432
- // Need to drop the sender otherwise we'll deadlock waiting for the scope
433
- // to finish on the receiver
500
+ // Drop the sender otherwise we'll deadlock
434
501
drop ( tx) ;
435
502
436
- {
437
- let db_dir = & git_db_dir;
438
- let co_dir = & git_co_dir;
439
- let summary = & summary;
440
- rayon:: scope ( |s| {
441
- while let Ok ( ( krate, pkg) ) = rx. recv ( ) {
442
- s. spawn ( move |_s| {
443
- let synced = match ( & krate. source , pkg) {
444
- ( Source :: Registry ( rs) , Pkg :: Registry ( krate_data) ) => {
445
- let len = krate_data. len ( ) ;
446
- let ( cache_dir, src_dir) = rs. registry . sync_dirs ( root_dir) ;
447
- if let Err ( err) =
448
- sync_package ( & cache_dir, & src_dir, & krate, krate_data, & rs. chksum )
449
- {
450
- error ! ( krate = %krate, "failed to splat package: {err:#}" ) ;
451
- None
452
- } else {
453
- Some ( len)
454
- }
455
- }
456
- ( Source :: Git ( gs) , Pkg :: Git ( pkg) ) => {
457
- let mut len = pkg. db . len ( ) ;
458
-
459
- if let Some ( co) = & pkg. checkout {
460
- len += co. len ( ) ;
461
- }
462
-
463
- match sync_git ( db_dir, co_dir, & krate, pkg, & gs. rev ) {
464
- Ok ( _) => Some ( len) ,
465
- Err ( err) => {
466
- error ! ( "failed to splat git repo: {err:#}" ) ;
467
- None
468
- }
469
- }
470
- }
471
- _ => unreachable ! ( ) ,
472
- } ;
473
-
474
- let mut sum = summary. lock ( ) . unwrap ( ) ;
475
- if let Some ( synced) = synced {
476
- sum. good += 1 ;
477
- sum. total_bytes += synced;
478
- } else {
479
- sum. bad += 1 ;
480
- }
481
- } ) ;
482
- }
483
- } ) ;
484
- }
503
+ fs_thread. join ( ) . expect ( "failed to join thread" ) ;
485
504
486
- Ok ( summary. into_inner ( ) . unwrap ( ) )
505
+ Ok ( std:: sync:: Arc :: into_inner ( summary)
506
+ . unwrap ( )
507
+ . into_inner ( )
508
+ . unwrap ( ) )
487
509
}
0 commit comments