@@ -368,33 +368,52 @@ impl RocksDB {
368
368
}
369
369
}
370
370
371
- pub fn compact_range ( & self , start : Option < String > , end : Option < String > , cf_name : Option < String > ) -> PhpResult < ( ) > {
371
+ pub fn compact_range (
372
+ & self ,
373
+ start : Option < String > ,
374
+ end : Option < String > ,
375
+ cf_name : Option < String > ,
376
+ ) -> PhpResult < ( ) > {
372
377
match cf_name {
373
378
Some ( cf_name) => {
374
379
let cf = self
375
380
. db
376
381
. cf_handle ( & cf_name)
377
382
. ok_or ( "Column family not found" ) ?;
378
- self . db
379
- . compact_range_cf ( & cf, start. as_ref ( ) . map ( |s| s. as_bytes ( ) ) , end. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ) ;
383
+ self . db . compact_range_cf (
384
+ & cf,
385
+ start. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ,
386
+ end. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ,
387
+ ) ;
380
388
}
381
389
None => {
382
- self . db
383
- . compact_range ( start. as_ref ( ) . map ( |s| s. as_bytes ( ) ) , end. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ) ;
390
+ self . db . compact_range (
391
+ start. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ,
392
+ end. as_ref ( ) . map ( |s| s. as_bytes ( ) ) ,
393
+ ) ;
384
394
}
385
395
}
386
396
Ok ( ( ) )
387
397
}
388
398
389
-
390
399
pub fn get_live_files ( & self ) -> PhpResult < Vec < String > > {
391
- let live_files = self . db . live_files ( ) . map_err ( |e| PhpException :: from ( e. to_string ( ) ) ) ?;
400
+ let live_files = self
401
+ . db
402
+ . live_files ( )
403
+ . map_err ( |e| PhpException :: from ( e. to_string ( ) ) ) ?;
392
404
let live_file_names = live_files. iter ( ) . map ( |lf| lf. name . clone ( ) ) . collect ( ) ;
393
405
Ok ( live_file_names)
394
406
}
395
407
396
- pub fn set_options ( & self , options : HashMap < String , String > , cf_name : Option < String > ) -> PhpResult < ( ) > {
397
- let options_vec: Vec < ( & str , & str ) > = options. iter ( ) . map ( |( k, v) | ( k. as_str ( ) , v. as_str ( ) ) ) . collect ( ) ;
408
+ pub fn set_options (
409
+ & self ,
410
+ options : HashMap < String , String > ,
411
+ cf_name : Option < String > ,
412
+ ) -> PhpResult < ( ) > {
413
+ let options_vec: Vec < ( & str , & str ) > = options
414
+ . iter ( )
415
+ . map ( |( k, v) | ( k. as_str ( ) , v. as_str ( ) ) )
416
+ . collect ( ) ;
398
417
match cf_name {
399
418
Some ( cf_name) => {
400
419
let cf = self
@@ -410,7 +429,11 @@ impl RocksDB {
410
429
Ok ( ( ) )
411
430
}
412
431
413
- pub fn set_compression ( & self , compression_type : String , cf_name : Option < String > ) -> PhpResult < ( ) > {
432
+ pub fn set_compression (
433
+ & self ,
434
+ compression_type : String ,
435
+ cf_name : Option < String > ,
436
+ ) -> PhpResult < ( ) > {
414
437
let compression = match compression_type. as_str ( ) {
415
438
"none" => rust_rocksdb:: DBCompressionType :: None ,
416
439
"snappy" => rust_rocksdb:: DBCompressionType :: Snappy ,
@@ -425,23 +448,37 @@ impl RocksDB {
425
448
opts. set_compression_type ( compression) ;
426
449
match cf_name {
427
450
Some ( cf_name) => {
428
- let cf = self . db . cf_handle ( & cf_name) . ok_or ( "Column family not found" ) ?;
429
- self . db . set_options_cf ( cf, & [ ( "compression" , compression_type. as_str ( ) ) ] )
451
+ let cf = self
452
+ . db
453
+ . cf_handle ( & cf_name)
454
+ . ok_or ( "Column family not found" ) ?;
455
+ self . db
456
+ . set_options_cf ( cf, & [ ( "compression" , compression_type. as_str ( ) ) ] )
430
457
}
431
- None => self . db . set_options ( & [ ( "compression" , compression_type. as_str ( ) ) ] ) ,
432
- } . map_err ( |e| e. to_string ( ) . into ( ) )
458
+ None => self
459
+ . db
460
+ . set_options ( & [ ( "compression" , compression_type. as_str ( ) ) ] ) ,
461
+ }
462
+ . map_err ( |e| e. to_string ( ) . into ( ) )
433
463
}
434
464
435
465
pub fn set_write_buffer_size ( & self , size : usize , cf_name : Option < String > ) -> PhpResult < ( ) > {
436
466
let mut opts = Options :: default ( ) ;
437
467
opts. set_write_buffer_size ( size) ;
438
468
match cf_name {
439
469
Some ( cf_name) => {
440
- let cf = self . db . cf_handle ( & cf_name) . ok_or ( "Column family not found" ) ?;
441
- self . db . set_options_cf ( cf, & [ ( "write_buffer_size" , size. to_string ( ) . as_str ( ) ) ] )
470
+ let cf = self
471
+ . db
472
+ . cf_handle ( & cf_name)
473
+ . ok_or ( "Column family not found" ) ?;
474
+ self . db
475
+ . set_options_cf ( cf, & [ ( "write_buffer_size" , size. to_string ( ) . as_str ( ) ) ] )
442
476
}
443
- None => self . db . set_options ( & [ ( "write_buffer_size" , size. to_string ( ) . as_str ( ) ) ] ) ,
444
- } . map_err ( |e| e. to_string ( ) . into ( ) )
477
+ None => self
478
+ . db
479
+ . set_options ( & [ ( "write_buffer_size" , size. to_string ( ) . as_str ( ) ) ] ) ,
480
+ }
481
+ . map_err ( |e| e. to_string ( ) . into ( ) )
445
482
}
446
483
447
484
pub fn set_cache_size ( & self , size : usize , cf_name : Option < String > ) -> PhpResult < ( ) > {
@@ -451,11 +488,18 @@ impl RocksDB {
451
488
opts. set_block_based_table_factory ( & cache) ;
452
489
match cf_name {
453
490
Some ( cf_name) => {
454
- let cf = self . db . cf_handle ( & cf_name) . ok_or ( "Column family not found" ) ?;
455
- self . db . set_options_cf ( cf, & [ ( "block_cache" , size. to_string ( ) . as_str ( ) ) ] )
491
+ let cf = self
492
+ . db
493
+ . cf_handle ( & cf_name)
494
+ . ok_or ( "Column family not found" ) ?;
495
+ self . db
496
+ . set_options_cf ( cf, & [ ( "block_cache" , size. to_string ( ) . as_str ( ) ) ] )
456
497
}
457
- None => self . db . set_options ( & [ ( "block_cache" , size. to_string ( ) . as_str ( ) ) ] ) ,
458
- } . map_err ( |e| e. to_string ( ) . into ( ) )
498
+ None => self
499
+ . db
500
+ . set_options ( & [ ( "block_cache" , size. to_string ( ) . as_str ( ) ) ] ) ,
501
+ }
502
+ . map_err ( |e| e. to_string ( ) . into ( ) )
459
503
}
460
504
}
461
505
0 commit comments