@@ -602,7 +602,7 @@ func TestStreamWriterWithLargeValue(t *testing.T) {
602602}
603603
604604func TestStreamWriterIncremental (t * testing.T ) {
605- addIncremtal := func (t * testing.T , db * DB , keys [][]byte ) {
605+ addIncremental := func (t * testing.T , db * DB , keys [][]byte ) {
606606 buf := z .NewBuffer (10 << 20 , "test" )
607607 defer func () { require .NoError (t , buf .Release ()) }()
608608 for _ , key := range keys {
@@ -633,7 +633,7 @@ func TestStreamWriterIncremental(t *testing.T) {
633633 require .NoError (t , sw .Write (buf ), "sw.Write() failed" )
634634 require .NoError (t , sw .Flush (), "sw.Flush() failed" )
635635
636- addIncremtal (t , db , [][]byte {[]byte ("key-2" )})
636+ addIncremental (t , db , [][]byte {[]byte ("key-2" )})
637637
638638 txn := db .NewTransaction (false )
639639 defer txn .Discard ()
@@ -646,7 +646,7 @@ func TestStreamWriterIncremental(t *testing.T) {
646646
647647 t .Run ("incremental on empty DB" , func (t * testing.T ) {
648648 runBadgerTest (t , nil , func (t * testing.T , db * DB ) {
649- addIncremtal (t , db , [][]byte {[]byte ("key-1" )})
649+ addIncremental (t , db , [][]byte {[]byte ("key-1" )})
650650 txn := db .NewTransaction (false )
651651 defer txn .Discard ()
652652 _ , err := txn .Get ([]byte ("key-1" ))
@@ -656,9 +656,9 @@ func TestStreamWriterIncremental(t *testing.T) {
656656
657657 t .Run ("multiple incremental" , func (t * testing.T ) {
658658 runBadgerTest (t , nil , func (t * testing.T , db * DB ) {
659- addIncremtal (t , db , [][]byte {[]byte ("a1" ), []byte ("c1" )})
660- addIncremtal (t , db , [][]byte {[]byte ("a2" ), []byte ("c2" )})
661- addIncremtal (t , db , [][]byte {[]byte ("a3" ), []byte ("c3" )})
659+ addIncremental (t , db , [][]byte {[]byte ("a1" ), []byte ("c1" )})
660+ addIncremental (t , db , [][]byte {[]byte ("a2" ), []byte ("c2" )})
661+ addIncremental (t , db , [][]byte {[]byte ("a3" ), []byte ("c3" )})
662662 txn := db .NewTransaction (false )
663663 defer txn .Discard ()
664664 _ , err := txn .Get ([]byte ("a1" ))
@@ -675,4 +675,79 @@ func TestStreamWriterIncremental(t *testing.T) {
675675 require .NoError (t , err )
676676 })
677677 })
678+
679+ t .Run ("write between incremental writes" , func (t * testing.T ) {
680+ runBadgerTest (t , nil , func (t * testing.T , db * DB ) {
681+ addIncremental (t , db , [][]byte {[]byte ("a1" ), []byte ("c1" )})
682+ require .NoError (t , db .Update (func (txn * Txn ) error {
683+ return txn .Set ([]byte ("a3" ), []byte ("c3" ))
684+ }))
685+
686+ sw := db .NewStreamWriter ()
687+ defer sw .Cancel ()
688+ require .EqualError (t , sw .PrepareIncremental (), "Unable to do incremental writes because MemTable has data" )
689+
690+ txn := db .NewTransaction (false )
691+ defer txn .Discard ()
692+ _ , err := txn .Get ([]byte ("a1" ))
693+ require .NoError (t , err )
694+ _ , err = txn .Get ([]byte ("c1" ))
695+ require .NoError (t , err )
696+ _ , err = txn .Get ([]byte ("a3" ))
697+ require .NoError (t , err )
698+ })
699+ })
700+
701+ t .Run ("incremental writes > #levels" , func (t * testing.T ) {
702+ runBadgerTest (t , nil , func (t * testing.T , db * DB ) {
703+ addIncremental (t , db , [][]byte {[]byte ("a1" ), []byte ("c1" )})
704+ addIncremental (t , db , [][]byte {[]byte ("a2" ), []byte ("c2" )})
705+ addIncremental (t , db , [][]byte {[]byte ("a3" ), []byte ("c3" )})
706+ addIncremental (t , db , [][]byte {[]byte ("a4" ), []byte ("c4" )})
707+ addIncremental (t , db , [][]byte {[]byte ("a5" ), []byte ("c5" )})
708+ addIncremental (t , db , [][]byte {[]byte ("a6" ), []byte ("c6" )})
709+ addIncremental (t , db , [][]byte {[]byte ("a7" ), []byte ("c7" )})
710+ addIncremental (t , db , [][]byte {[]byte ("a8" ), []byte ("c8" )})
711+ addIncremental (t , db , [][]byte {[]byte ("a9" ), []byte ("c9" )})
712+
713+ txn := db .NewTransaction (false )
714+ defer txn .Discard ()
715+ _ , err := txn .Get ([]byte ("a1" ))
716+ require .NoError (t , err )
717+ _ , err = txn .Get ([]byte ("c1" ))
718+ require .NoError (t , err )
719+ _ , err = txn .Get ([]byte ("a2" ))
720+ require .NoError (t , err )
721+ _ , err = txn .Get ([]byte ("c2" ))
722+ require .NoError (t , err )
723+ _ , err = txn .Get ([]byte ("a3" ))
724+ require .NoError (t , err )
725+ _ , err = txn .Get ([]byte ("c3" ))
726+ require .NoError (t , err )
727+ _ , err = txn .Get ([]byte ("a4" ))
728+ require .NoError (t , err )
729+ _ , err = txn .Get ([]byte ("c4" ))
730+ require .NoError (t , err )
731+ _ , err = txn .Get ([]byte ("a5" ))
732+ require .NoError (t , err )
733+ _ , err = txn .Get ([]byte ("c5" ))
734+ require .NoError (t , err )
735+ _ , err = txn .Get ([]byte ("a6" ))
736+ require .NoError (t , err )
737+ _ , err = txn .Get ([]byte ("c6" ))
738+ require .NoError (t , err )
739+ _ , err = txn .Get ([]byte ("a7" ))
740+ require .NoError (t , err )
741+ _ , err = txn .Get ([]byte ("c7" ))
742+ require .NoError (t , err )
743+ _ , err = txn .Get ([]byte ("a8" ))
744+ require .NoError (t , err )
745+ _ , err = txn .Get ([]byte ("c8" ))
746+ require .NoError (t , err )
747+ _ , err = txn .Get ([]byte ("a9" ))
748+ require .NoError (t , err )
749+ _ , err = txn .Get ([]byte ("c9" ))
750+ require .NoError (t , err )
751+ })
752+ })
678753}
0 commit comments