@@ -101,7 +101,6 @@ impl RocksdbStorageEngine {
101101
102102 // Initialize column family options.
103103 let mut cf_options = rocksdb:: Options :: default ( ) ;
104- // TODO
105104 cf_options. set_prefix_extractor ( rocksdb:: SliceTransform :: create_fixed_prefix ( 64 ) ) ;
106105 cf_options. set_memtable_prefix_bloom_ratio ( 0.25 ) ;
107106 cf_options. optimize_level_style_compaction ( Self :: DEFAULT_MEMTABLE_MEMORY_BUDGET ) ;
@@ -214,8 +213,6 @@ impl Operations for RocksdbStorageEngine {
214213 prefix : & [ u8 ] ,
215214 ) -> Result < impl Iterator < Item = Result < ( Box < [ u8 ] > , Box < [ u8 ] > ) > > > {
216215 let cf = cf_handle :: < O > ( self ) ?;
217- // prefix should not shorter than `set_prefix_extractor`
218- // assert!(prefix.len() >= 64);
219216 Ok ( self . prefix_iterator_cf ( cf, prefix) . map ( |ele| {
220217 let ( key, value) = ele. or_err ( ErrorType :: StorageError ) ?;
221218 Ok ( ( key, value) )
@@ -645,125 +642,4 @@ mod tests {
645642 assert ! ( format!( "{:?}" , err) . contains( "ColumnFamilyNotFound" ) ) ;
646643 }
647644 }
648-
649- #[ test]
650- /// copied from `test_prefix_iter_raw`
651- fn test_prefix_iter_raw_shorter_key_should_fail ( ) {
652- let engine = create_test_engine ( ) ;
653-
654- // RocksDB prefix extractor is configured with fixed_prefix(64) in the open method.
655- let prefix_a = [ b'a' ; 64 ] ;
656- let prefix_b = [ b'b' ; 64 ] ;
657-
658-
659- // ADD shorter key test
660- let prefix_a_shorter: [ u8 ; 10 ] = prefix_a[ ..10 ] . try_into ( ) . unwrap ( ) ;
661-
662- println ! ( "prefix_a address: {:p}" , & prefix_a) ;
663- println ! ( "prefix_a_shorter address: {:p}" , & prefix_a_shorter) ;
664- println ! ( "shoter(len: {}): {:#?}" , prefix_a_shorter. len( ) , prefix_a_shorter) ;
665- // ADD shorter key test
666-
667- // Create test keys with 64-byte identical prefixes.
668- let key_a1 = [ & prefix_a[ ..] , b"_raw_suffix1" ] . concat ( ) ;
669- let key_a2 = [ & prefix_a[ ..] , b"_raw_suffix2" ] . concat ( ) ;
670-
671- let key_b1 = [ & prefix_b[ ..] , b"_raw_suffix1" ] . concat ( ) ;
672- let key_b2 = [ & prefix_b[ ..] , b"_raw_suffix2" ] . concat ( ) ;
673-
674- let objects_with_prefix_a = vec ! [
675- (
676- key_a1. clone( ) ,
677- Object {
678- id: "raw_prefix_id_a1" . to_string( ) ,
679- value: 100 ,
680- } ,
681- ) ,
682- (
683- key_a2. clone( ) ,
684- Object {
685- id: "raw_prefix_id_a2" . to_string( ) ,
686- value: 200 ,
687- } ,
688- ) ,
689- ] ;
690-
691- let objects_with_prefix_b = vec ! [
692- (
693- key_b1. clone( ) ,
694- Object {
695- id: "raw_prefix_id_b1" . to_string( ) ,
696- value: 300 ,
697- } ,
698- ) ,
699- (
700- key_b2. clone( ) ,
701- Object {
702- id: "raw_prefix_id_b2" . to_string( ) ,
703- value: 400 ,
704- } ,
705- ) ,
706- ] ;
707-
708- for ( key, obj) in & objects_with_prefix_a {
709- engine. put :: < Object > ( key, obj) . unwrap ( ) ;
710- }
711-
712- for ( key, obj) in & objects_with_prefix_b {
713- engine. put :: < Object > ( key, obj) . unwrap ( ) ;
714- }
715-
716- let retrieved_objects = engine
717- // .prefix_iter_raw::<Object>(&prefix_a[..10])
718- // .prefix_iter_raw::<Object>(&prefix_a)
719- . prefix_iter_raw :: < Object > ( & prefix_a_shorter)
720- . unwrap ( )
721- . collect :: < Result < Vec < _ > > > ( )
722- . unwrap ( ) ;
723-
724- // Can not seek value
725- assert_eq ! (
726- retrieved_objects. len( ) ,
727- objects_with_prefix_a. len( ) ,
728- "expected {} raw objects with prefix 'a', but got {}" ,
729- objects_with_prefix_a. len( ) ,
730- retrieved_objects. len( )
731- ) ;
732-
733- // println!("Retrieved objects count: {}", retrieved_objects.len());
734- // for (i, (key, value)) in retrieved_objects.iter().enumerate() {
735- // println!("Object {}: key={:?}, value_len={}", i, key, value.len());
736- // if let Ok(obj) = Object::deserialize_from(value) {
737- // println!(" -> deserialized: id={}, value={}", obj.id, obj.value);
738- // } else {
739- // println!(" -> failed to deserialize");
740- // }
741- // }
742-
743- // // Verify each object with prefix can be deserialized from raw bytes.
744- // for (_, object) in &objects_with_prefix_a {
745- // let found = retrieved_objects
746- // .iter()
747- // .any(|(_, v)| match Object::deserialize_from(v) {
748- // Ok(deserialized) => {
749- // deserialized.id == object.id && deserialized.value == object.value
750- // }
751- // Err(_) => false,
752- // });
753-
754- // assert!(
755- // found,
756- // "could not find or deserialize object with key {:?}",
757- // object.id
758- // );
759- // }
760-
761- // // Verify objects with different prefix are not retrieved.
762- // for (key, _) in &objects_with_prefix_b {
763- // let found = retrieved_objects
764- // .iter()
765- // .any(|(k, _)| k.as_ref() == key.as_slice());
766- // assert!(!found, "found object with different prefix: {:?}", key);
767- // }
768- }
769645}
0 commit comments