Skip to content

Commit 302864a

Browse files
authored
Load: Add check for reset memory size to 0 in LoadTsFileMemoryManager (#16940)
1 parent ec7fbda commit 302864a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/memory/LoadTsFileMemoryManager.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public synchronized long tryAllocateFromQuery(final long sizeInBytes) {
8282
}
8383

8484
public synchronized void releaseToQuery(final long sizeInBytes) {
85+
if (sizeInBytes <= 0) {
86+
throw new IllegalArgumentException(
87+
String.format("Load: Invalid memory size %d bytes, must be positive", sizeInBytes));
88+
}
8589
if (usedMemorySizeInBytes.get() < sizeInBytes) {
8690
LOGGER.error(
8791
"Load: Attempting to release more memory ({}) than allocated ({})",
@@ -96,6 +100,10 @@ public synchronized void releaseToQuery(final long sizeInBytes) {
96100

97101
public synchronized LoadTsFileMemoryBlock allocateMemoryBlock(long sizeInBytes)
98102
throws LoadRuntimeOutOfMemoryException {
103+
if (sizeInBytes <= 0) {
104+
throw new IllegalArgumentException(
105+
String.format("Load: Invalid memory size %d bytes, must be positive", sizeInBytes));
106+
}
99107
try {
100108
forceAllocateFromQuery(sizeInBytes);
101109
if (LOGGER.isDebugEnabled()) {
@@ -120,7 +128,16 @@ public synchronized LoadTsFileMemoryBlock allocateMemoryBlock(long sizeInBytes)
120128
*/
121129
synchronized void forceResize(LoadTsFileMemoryBlock memoryBlock, long newSizeInBytes)
122130
throws LoadRuntimeOutOfMemoryException {
123-
if (memoryBlock.getTotalMemorySizeInBytes() >= newSizeInBytes) {
131+
if (newSizeInBytes < 0) {
132+
throw new IllegalArgumentException(
133+
String.format(
134+
"Load: Invalid memory size %d bytes, must be non-negative", newSizeInBytes));
135+
}
136+
if (memoryBlock.getTotalMemorySizeInBytes() == newSizeInBytes) {
137+
return;
138+
}
139+
140+
if (memoryBlock.getTotalMemorySizeInBytes() > newSizeInBytes) {
124141

125142
if (memoryBlock.getMemoryUsageInBytes() > newSizeInBytes) {
126143
LOGGER.error(

0 commit comments

Comments
 (0)