Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,23 @@ < allowedMaxMemorySizeInBytesOfTabletsAndTsFiles()
&& (double) usedMemorySizeInBytesOfTsFiles < allowedMaxMemorySizeInBytesOfTsTiles();
}

private boolean isHardEnoughForResizing(final PipeMemoryBlock block) {
private boolean isHardEnoughForResizing(
final PipeMemoryBlock block, final long extraMemoryInBytes) {
if (block instanceof PipeTabletMemoryBlock) {
return isHardEnough4TabletParsing();
return (double) usedMemorySizeInBytesOfTablets
+ (double) extraMemoryInBytes
+ (double) usedMemorySizeInBytesOfTsFiles
< allowedMaxMemorySizeInBytesOfTabletsAndTsFiles()
&& (double) usedMemorySizeInBytesOfTablets + (double) extraMemoryInBytes
< allowedMaxMemorySizeInBytesOfTablets();
}
if (block instanceof PipeTsFileMemoryBlock) {
return isHardEnough4TsFileSlicing();
return (double) usedMemorySizeInBytesOfTablets
+ (double) usedMemorySizeInBytesOfTsFiles
+ (double) extraMemoryInBytes
< allowedMaxMemorySizeInBytesOfTabletsAndTsFiles()
&& (double) usedMemorySizeInBytesOfTsFiles + (double) extraMemoryInBytes
< allowedMaxMemorySizeInBytesOfTsTiles();
}
return true;
}
Expand Down Expand Up @@ -710,7 +721,7 @@ public synchronized void resize(
// Dynamically resized data-structure blocks must obey the same admission thresholds as
// blocks allocated with a non-zero initial size. Otherwise they can exhaust the pool and
// prevent downstream consumers from allocating the memory needed to release them.
if (isHardEnoughForResizing(block)
if (isHardEnoughForResizing(block, sizeInBytes)
&& getTotalNonFloatingMemorySizeInBytes() - memoryBlock.getUsedMemoryInBytes()
>= sizeInBytes) {
memoryBlock.forceAllocateWithoutLimitation(sizeInBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ public void tearDown() {
originalTsFileRejectThreshold);
}

@Test
public void testTabletResizeCannotCrossTabletHardLimit() {
final PipeMemoryManager manager =
new PipeMemoryManager(
new AtomicLongMemoryBlock(
"PipeMemoryManagerResizeTest",
null,
TOTAL_MEMORY_SIZE_IN_BYTES,
MemoryBlockType.DYNAMIC));
final PipeTabletMemoryBlock tablet = manager.forceAllocateForTabletWithRetry(0);

try {
Assert.assertThrows(
PipeRuntimeOutOfMemoryCriticalException.class,
() -> manager.forceResize(tablet, TABLET_MEMORY_SIZE_IN_BYTES));
Assert.assertEquals(0, tablet.getMemoryUsageInBytes());
Assert.assertEquals(0, manager.getUsedMemorySizeInBytes());
Assert.assertEquals(0, manager.getUsedMemorySizeInBytesOfTablets());
} finally {
manager.release(tablet);
}
}

@Test
public void testTabletResizeLeavesMemoryForSinkForwardProgress() {
final PipeMemoryManager manager =
Expand Down