diff --git a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/MemoryBasedStateMachineTests.cs b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/MemoryBasedStateMachineTests.cs index e788f5932..79cfbf283 100644 --- a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/MemoryBasedStateMachineTests.cs +++ b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/MemoryBasedStateMachineTests.cs @@ -728,8 +728,8 @@ public static async Task BackgroundCompaction(bool useCaching) await state.ForceCompactionAsync(1L, CancellationToken.None); checker = static (readResult, snapshotIndex, token) => { - Equal(3, readResult.Count); - Equal(4, snapshotIndex); + Equal(4, readResult.Count); + Equal(3, snapshotIndex); True(readResult[0].IsSnapshot); False(readResult[1].IsSnapshot); False(readResult[2].IsSnapshot); @@ -738,8 +738,8 @@ public static async Task BackgroundCompaction(bool useCaching) await state.As().ReadAsync(new LogEntryConsumer(checker), 1, 6, CancellationToken.None); checker = static (readResult, snapshotIndex, token) => { - Equal(6, readResult.Count); - Equal(4, snapshotIndex); + Equal(7, readResult.Count); + Equal(3, snapshotIndex); True(readResult[0].IsSnapshot); False(readResult[1].IsSnapshot); False(readResult[2].IsSnapshot); @@ -753,7 +753,7 @@ public static async Task BackgroundCompaction(bool useCaching) { checker = static (readResult, snapshotIndex, token) => { - Equal(3, readResult.Count); + Equal(4, readResult.Count); NotNull(snapshotIndex); return default; }; @@ -761,8 +761,8 @@ public static async Task BackgroundCompaction(bool useCaching) Equal(0L, state.Value); checker = static (readResult, snapshotIndex, token) => { - Equal(6, readResult.Count); - Equal(4, snapshotIndex); + Equal(7, readResult.Count); + Equal(3, snapshotIndex); True(readResult[0].IsSnapshot); False(readResult[1].IsSnapshot); False(readResult[2].IsSnapshot); diff --git a/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/MemoryBasedStateMachine.cs b/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/MemoryBasedStateMachine.cs index 69b08f1b9..3c4f6bac5 100644 --- a/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/MemoryBasedStateMachine.cs +++ b/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/MemoryBasedStateMachine.cs @@ -684,11 +684,10 @@ private async ValueTask ForceBackgroundCompactionAsync(long count, CancellationT DeletePartitions(removedHead); - [MethodImpl(MethodImplOptions.AggressiveInlining)] long ComputeUpperBoundIndex(ref long count) { count = Math.Min(count, GetBackgroundCompactionCount(out var snapshotIndex)); - return checked((recordsPerPartition * count) + snapshotIndex); + return count * recordsPerPartition + snapshotIndex - Unsafe.BitCast(snapshotIndex is 0L); } }