Skip to content

Commit

Permalink
Fixed background compaction scope
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jul 8, 2024
1 parent 2f20c30 commit e746506
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -738,8 +738,8 @@ public static async Task BackgroundCompaction(bool useCaching)
await state.As<IRaftLog>().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);
Expand All @@ -753,16 +753,16 @@ public static async Task BackgroundCompaction(bool useCaching)
{
checker = static (readResult, snapshotIndex, token) =>
{
Equal(3, readResult.Count);
Equal(4, readResult.Count);
NotNull(snapshotIndex);
return default;
};
await state.As<IRaftLog>().ReadAsync(new LogEntryConsumer(checker), 1, 6, CancellationToken.None);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, byte>(snapshotIndex is 0L);
}
}

Expand Down

0 comments on commit e746506

Please sign in to comment.