This is an automated email from the ASF dual-hosted git repository.

jt2594838 pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/dev/1.3 by this push:
     new 34d38ef57d5 Fix pipe tablet memory resize admission limit (#18413) 
(#18420)
34d38ef57d5 is described below

commit 34d38ef57d5789a8a6b811fcd6343b3816ba50a7
Author: Caideyipi <[email protected]>
AuthorDate: Fri Aug 7 15:19:46 2026 +0800

    Fix pipe tablet memory resize admission limit (#18413) (#18420)
---
 .../db/pipe/resource/memory/PipeMemoryManager.java | 19 +++++++++++++----
 .../memory/PipeMemoryManagerResizeTest.java        | 24 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManager.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManager.java
index d5297f17b09..5dfff56c52e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManager.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManager.java
@@ -472,12 +472,23 @@ public class PipeMemoryManager {
         && (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;
   }
@@ -705,7 +716,7 @@ public class PipeMemoryManager {
       // 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() - usedMemorySizeInBytes >= 
sizeInBytes) {
         usedMemorySizeInBytes += sizeInBytes;
         if (oldSize == 0) {
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManagerResizeTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManagerResizeTest.java
index be746addc9e..ad183f5e37f 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManagerResizeTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryManagerResizeTest.java
@@ -70,6 +70,30 @@ public class PipeMemoryManagerResizeTest {
         originalTsFileRejectThreshold);
   }
 
+  @Test
+  public void testTabletResizeCannotCrossTabletHardLimit() {
+    final PipeMemoryManager manager = new PipeMemoryManager();
+    final PipeTabletMemoryBlock tablet = 
manager.forceAllocateForTabletWithRetry(0);
+    final long tabletMemorySizeInBytes =
+        (long)
+                (PipeMemoryManager.getTotalNonFloatingMemorySizeInBytes()
+                    * 
(config.getPipeDataStructureTabletMemoryBlockAllocationRejectThreshold()
+                        + 
config.getPipeDataStructureTsFileMemoryBlockAllocationRejectThreshold()
+                            / 2))
+            + 1;
+
+    try {
+      Assert.assertThrows(
+          PipeRuntimeOutOfMemoryCriticalException.class,
+          () -> manager.forceResize(tablet, tabletMemorySizeInBytes));
+      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 = new PipeMemoryManager();

Reply via email to