Skip to content

Commit

Permalink
fix: ThreadLocal issue in LongListDisk when multiple lists are used (#…
Browse files Browse the repository at this point in the history
…16962)

Signed-off-by: Nikita Lebedev <[email protected]>
  • Loading branch information
thenswan authored Dec 11, 2024
1 parent 117c7b1 commit 0665700
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,53 @@ void testReuseOfChunks_maxValidIndex() throws IOException {
checkData(longListDisk, 0, SAMPLE_SIZE);
}

@Test
void testReallocateThreadLocalBufferWhenMemoryChunkSizeChanges() throws IOException {
// Create two long lists with different memory chunk sizes
var largeMemoryChunkList = new LongListDisk(100, SAMPLE_SIZE * 2, 0, CONFIGURATION);
var smallMemoryChunkList = new LongListDisk(10, SAMPLE_SIZE * 2, 0, CONFIGURATION);

// Populate both long lists with sample data and validate
populateList(largeMemoryChunkList);
checkData(largeMemoryChunkList, 0, SAMPLE_SIZE);
populateList(smallMemoryChunkList);
checkData(smallMemoryChunkList, 0, SAMPLE_SIZE);

// Capture the original file channel sizes before closing chunks
final long originalLargeListChannelSize =
largeMemoryChunkList.getCurrentFileChannel().size();
final long originalSmallListChannelSize =
smallMemoryChunkList.getCurrentFileChannel().size();

// Close all chunks in long lists
for (int i = 0; i < largeMemoryChunkList.chunkList.length(); i++) {
final Long chunk = largeMemoryChunkList.chunkList.get(i);
if (chunk != null) {
largeMemoryChunkList.closeChunk(chunk);
}
}
for (int i = 0; i < smallMemoryChunkList.chunkList.length(); i++) {
final Long chunk = smallMemoryChunkList.chunkList.get(i);
if (chunk != null) {
smallMemoryChunkList.closeChunk(chunk);
}
}

// Ensure that file channel sizes have not inadvertently grown
assertEquals(
originalLargeListChannelSize,
largeMemoryChunkList.getCurrentFileChannel().size());
assertEquals(
originalSmallListChannelSize,
smallMemoryChunkList.getCurrentFileChannel().size());

// Tear down
largeMemoryChunkList.close();
largeMemoryChunkList.resetTransferBuffer();
smallMemoryChunkList.close();
smallMemoryChunkList.resetTransferBuffer();
}

@Test
void testBigIndex() throws IOException {
try (LongListDisk list = new LongListDisk(CONFIGURATION)) {
Expand Down

0 comments on commit 0665700

Please sign in to comment.