@@ -734,3 +734,101 @@ def test_compact_range(self):
734734
735735 self .db .compact_range (column_family = self .cf_b )
736736
737+ def test_flush (self ):
738+ # Check initial state
739+ initial_l0_files = int (self .db .get_property (b'rocksdb.num-files-at-level0' ))
740+
741+ # Write some data
742+ self .db .put (b"a" , b"1" )
743+ self .db .put (b"b" , b"2" )
744+
745+ # Flush with default parameters (all column families, wait=True)
746+ self .db .flush ()
747+
748+ # Verify flush created SST files at level 0
749+ final_l0_files = int (self .db .get_property (b'rocksdb.num-files-at-level0' ))
750+ self .assertGreater (final_l0_files , initial_l0_files )
751+
752+ def test_flush_no_wait (self ):
753+ # Write some data
754+ self .db .put (b"a" , b"1" )
755+
756+ # Flush without waiting - just verify it doesn't raise an exception
757+ self .db .flush (wait = False )
758+
759+ def test_flush_all_column_families (self ):
760+ # Check initial state for each column family
761+ initial_default_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' ))
762+ initial_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
763+ initial_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
764+
765+ # Write to multiple column families
766+ self .db .put (b"default_key" , b"default_value" )
767+ self .db .put ((self .cf_a , b"a_key" ), b"a_value" )
768+ self .db .put ((self .cf_b , b"b_key" ), b"b_value" )
769+
770+ # Flush all column families (default behavior)
771+ self .db .flush ()
772+
773+ # Verify all column families were flushed (SST files created)
774+ final_default_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' ))
775+ final_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
776+ final_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
777+
778+ self .assertGreater (final_default_l0 , initial_default_l0 )
779+ self .assertGreater (final_cf_a_l0 , initial_cf_a_l0 )
780+ self .assertGreater (final_cf_b_l0 , initial_cf_b_l0 )
781+
782+ def test_flush_single_column_family (self ):
783+ # Check initial state
784+ initial_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
785+ initial_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
786+
787+ # Write to multiple column families
788+ self .db .put ((self .cf_a , b"a_key" ), b"a_value" )
789+ self .db .put ((self .cf_b , b"b_key" ), b"b_value" )
790+
791+ # Flush only cf_a
792+ self .db .flush (column_families = self .cf_a )
793+
794+ # Verify only cf_a was flushed (SST files created)
795+ final_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
796+ final_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
797+
798+ self .assertGreater (final_cf_a_l0 , initial_cf_a_l0 )
799+ self .assertEqual (final_cf_b_l0 , initial_cf_b_l0 ) # cf_b should NOT be flushed
800+
801+ def test_flush_multiple_column_families (self ):
802+ # Check initial state
803+ initial_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
804+ initial_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
805+
806+ # Write to multiple column families
807+ self .db .put ((self .cf_a , b"a_key" ), b"a_value" )
808+ self .db .put ((self .cf_b , b"b_key" ), b"b_value" )
809+
810+ # Flush both cf_a and cf_b
811+ self .db .flush (column_families = [self .cf_a , self .cf_b ])
812+
813+ # Verify both were flushed (SST files created)
814+ final_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
815+ final_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
816+
817+ self .assertGreater (final_cf_a_l0 , initial_cf_a_l0 )
818+ self .assertGreater (final_cf_b_l0 , initial_cf_b_l0 )
819+
820+ # Verify both were flushed (SST files created)
821+ final_cf_a_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_a ))
822+ final_cf_b_l0 = int (self .db .get_property (b'rocksdb.num-files-at-level0' , self .cf_b ))
823+
824+ self .assertGreater (final_cf_a_l0 , initial_cf_a_l0 )
825+ self .assertGreater (final_cf_b_l0 , initial_cf_b_l0 )
826+
827+ def test_flush_invalid_column_families (self ):
828+ # Test that passing invalid type raises TypeError
829+ with self .assertRaises (TypeError ):
830+ self .db .flush (column_families = "invalid" )
831+
832+ with self .assertRaises (TypeError ):
833+ self .db .flush (column_families = ["invalid" , self .cf_a ])
834+
0 commit comments