@@ -80,7 +80,7 @@ public override ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToke
80
80
=> writer . WriteAsync ( snapshot , token ) ;
81
81
}
82
82
83
- internal PersistentStateWithSnapshot ( string path , bool useCaching , CompactionMode compactionMode = default )
83
+ internal PersistentStateWithSnapshot ( string path , bool useCaching , CompactionMode compactionMode = CompactionMode . Sequential )
84
84
: base ( path , RecordsPerPartition , new Options { UseCaching = useCaching , CompactionMode = compactionMode , IntegrityCheck = true , WriteMode = WriteMode . AutoFlush } )
85
85
{
86
86
}
@@ -625,16 +625,20 @@ public static async Task ClearLog()
625
625
}
626
626
627
627
[ Theory ]
628
- [ InlineData ( MemoryBasedStateMachine . CompactionMode . Background ) ]
629
- [ InlineData ( MemoryBasedStateMachine . CompactionMode . Foreground ) ]
630
- [ InlineData ( MemoryBasedStateMachine . CompactionMode . Sequential ) ]
631
- [ InlineData ( MemoryBasedStateMachine . CompactionMode . Incremental ) ]
632
- public static async Task AppendAndCommitAsync ( MemoryBasedStateMachine . CompactionMode compaction )
628
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Background , false ) ]
629
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Foreground , false ) ]
630
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Sequential , false ) ]
631
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Incremental , false ) ]
632
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Background , true ) ]
633
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Foreground , true ) ]
634
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Sequential , true ) ]
635
+ [ InlineData ( MemoryBasedStateMachine . CompactionMode . Incremental , true ) ]
636
+ public static async Task AppendAndCommitAsync ( MemoryBasedStateMachine . CompactionMode compaction , bool caching )
633
637
{
634
638
var entries = new Int64LogEntry [ RecordsPerPartition * 2 + 1 ] ;
635
639
entries . AsSpan ( ) . ForEach ( ( ref Int64LogEntry entry , int index ) => entry = new Int64LogEntry { Content = 42L + index , Term = index } ) ;
636
640
var dir = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
637
- using var state = new PersistentStateWithSnapshot ( dir , true , compaction ) ;
641
+ using var state = new PersistentStateWithSnapshot ( dir , caching , compaction ) ;
638
642
Equal ( 0L , await state . As < IRaftLog > ( ) . AppendAndCommitAsync ( new LogEntryList ( entries ) , 1L , false , 0L ) ) ;
639
643
Equal ( 0L , state . LastCommittedEntryIndex ) ;
640
644
Equal ( 9L , state . LastEntryIndex ) ;
@@ -1079,4 +1083,15 @@ public static async Task EnsureMetadataPersistence()
1079
1083
await state . As < IRaftLog > ( ) . ReadAsync ( new LogEntryConsumer ( checker ) , 1L ) ;
1080
1084
}
1081
1085
}
1086
+
1087
+ [ Fact ]
1088
+ public static async Task RegressionIssue244 ( )
1089
+ {
1090
+ var entries = new Int64LogEntry [ RecordsPerPartition + 1 ] ;
1091
+ entries . AsSpan ( ) . ForEach ( ( ref Int64LogEntry entry , int index ) => entry = new Int64LogEntry { Content = 42L + index , Term = index } ) ;
1092
+ var dir = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
1093
+ using var state = new PersistentStateWithSnapshot ( dir , true ) ;
1094
+ Equal ( 0L , await state . As < IRaftLog > ( ) . AppendAndCommitAsync ( new LogEntryList ( entries ) , 1L , false , entries . Length + 1L ) ) ;
1095
+ Equal ( 0L , state . LastCommittedEntryIndex ) ;
1096
+ }
1082
1097
}
0 commit comments