From 734515a8e993de4daeaf18a7b1b8a84e1d179403 Mon Sep 17 00:00:00 2001 From: Igor Matsak Date: Tue, 21 Mar 2023 23:26:33 +0300 Subject: [PATCH] Fix #2300 issue with big collection sort --- LiteDB/Engine/Sort/SortDisk.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LiteDB/Engine/Sort/SortDisk.cs b/LiteDB/Engine/Sort/SortDisk.cs index 501b93d76..7641259d9 100644 --- a/LiteDB/Engine/Sort/SortDisk.cs +++ b/LiteDB/Engine/Sort/SortDisk.cs @@ -88,8 +88,11 @@ public void Write(long position, BufferSlice buffer) // there is only a single writer instance, must be lock to ensure only 1 single thread are writing lock(writer) { - writer.Position = position; - writer.Write(buffer.Array, buffer.Offset, _containerSize); + for (var i = 0; i < _containerSize / PAGE_SIZE; ++i) + { + writer.Position = position + i * PAGE_SIZE; + writer.Write(buffer.Array, buffer.Offset + i * PAGE_SIZE, PAGE_SIZE); + } } }