@@ -321,6 +321,11 @@ impl<'handle> BatchWriter<'handle> {
321
321
}
322
322
323
323
fn commit_inner ( mut self , before_write : impl Fn ( ) ) -> Result < WriteCommitResult > {
324
+ if flocking ( ) {
325
+ for ef in & mut self . exclusive_files {
326
+ assert ! ( ef. downgrade_lock( ) ?) ;
327
+ }
328
+ }
324
329
let mut transaction: OwnedTx = self . handle . start_immediate_transaction ( ) ?;
325
330
let mut write_commit_res = WriteCommitResult { count : 0 } ;
326
331
for pw in self . pending_writes . drain ( ..) {
@@ -343,28 +348,32 @@ impl<'handle> BatchWriter<'handle> {
343
348
344
349
/// Flush Writer's exclusive files and return them to the Handle pool.
345
350
fn flush_exclusive_files ( & mut self ) {
346
- let mut handle_exclusive_files = self . handle . exclusive_files . lock ( ) . unwrap ( ) ;
347
- for mut ef in self . exclusive_files . drain ( ..) {
351
+ for ef in & mut self . exclusive_files {
348
352
ef. committed ( ) . unwrap ( ) ;
349
- // When we're flocking, we can't have writers and readers at the same time and still be
350
- // able to punch values asynchronously.
351
- if flocking ( ) {
352
- debug ! ( "returning exclusive file {} to handle" , ef. id) ;
353
- assert ! ( handle_exclusive_files. insert( ef. id. clone( ) , ef) . is_none( ) ) ;
354
- }
355
353
}
354
+ self . return_exclusive_files_to_handle ( )
356
355
}
357
- }
358
356
359
- impl Drop for BatchWriter < ' _ > {
360
- fn drop ( & mut self ) {
357
+ fn return_exclusive_files_to_handle ( & mut self ) {
358
+ // When we're flocking, we can't have writers and readers at the same time and still be
359
+ // able to punch values asynchronously.
360
+ if flocking ( ) {
361
+ return ;
362
+ }
361
363
let mut handle_exclusive_files = self . handle . exclusive_files . lock ( ) . unwrap ( ) ;
362
364
for ef in self . exclusive_files . drain ( ..) {
365
+ debug ! ( "returning exclusive file {} to handle" , ef. id) ;
363
366
assert ! ( handle_exclusive_files. insert( ef. id. clone( ) , ef) . is_none( ) ) ;
364
367
}
365
368
}
366
369
}
367
370
371
+ impl Drop for BatchWriter < ' _ > {
372
+ fn drop ( & mut self ) {
373
+ self . return_exclusive_files_to_handle ( )
374
+ }
375
+ }
376
+
368
377
type ValueLength = u64 ;
369
378
370
379
#[ derive( Debug , Clone , PartialEq ) ]
@@ -543,7 +552,7 @@ where
543
552
let file_offset = file_offset + pos;
544
553
// Getting lazy: Using positioned-io's ReadAt because it works on Windows.
545
554
let res = file. read_at ( file_offset, buf) ;
546
- debug ! ( ?file, ?file_offset, len=? buf, ?res, "snapshot value read_at" ) ;
555
+ debug ! ( ?file, ?file_offset, len=buf. len ( ) , ?res, "snapshot value read_at" ) ;
547
556
res
548
557
}
549
558
}
@@ -593,7 +602,7 @@ where
593
602
let file = & mut file_clone. file ;
594
603
file. seek ( Start ( file_offset) ) ?;
595
604
let res = file. read ( buf) ;
596
- debug ! ( ?file, ?file_offset, len=? buf, ?res, "snapshot value read" ) ;
605
+ debug ! ( ?file, ?file_offset, len=buf. len ( ) , ?res, "snapshot value read" ) ;
597
606
res. map_err ( Into :: into)
598
607
}
599
608
}
0 commit comments