Skip to content

Commit fe29310

Browse files
committed
fix UT and perfect
Signed-off-by: Weihao Li <18110526956@163.com>
1 parent 8b90369 commit fe29310

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/memory/NotThreadSafeMemoryReservationManager.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import javax.annotation.concurrent.NotThreadSafe;
3030

31+
import static com.google.common.base.Preconditions.checkState;
32+
3133
@NotThreadSafe
3234
public class NotThreadSafeMemoryReservationManager implements MemoryReservationManager {
3335
// To avoid reserving memory too frequently, we choose to do it in batches. This is the lower
@@ -151,23 +153,20 @@ private long deductReleaseAccounting(final long size) {
151153
remaining -= fallbackBytesInTotal;
152154
fallbackBytesInTotal = 0;
153155

154-
long poolBytes = Math.min(remaining, reservedBytesInTotal);
155-
reservedBytesInTotal -= poolBytes;
156-
return poolBytes;
156+
reservedBytesInTotal -= remaining;
157+
checkState(reservedBytesInTotal >= 0, "Released bytes has been larger than reserved!");
158+
return remaining;
157159
}
158160

159161
@Override
160162
public void releaseAllReservedMemory() {
161-
if (bytesToBeReleased != 0) {
162-
releaseBytesImmediately(bytesToBeReleased);
163-
bytesToBeReleased = 0;
164-
}
165-
if (reservedBytesInTotal > 0) {
163+
if (reservedBytesInTotal != 0) {
166164
LOCAL_EXECUTION_PLANNER.releaseToFreeMemoryForOperators(reservedBytesInTotal);
165+
reservedBytesInTotal = 0;
167166
}
168-
reservedBytesInTotal = 0;
169167
fallbackBytesInTotal = 0;
170168
bytesToBeReserved = 0;
169+
bytesToBeReleased = 0;
171170
}
172171

173172
@Override

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/CteScanOperatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testMultipleCteScanOperators() throws Exception {
177177
new CteScanOperator(operatorContext, planNodeId, cteDataStore, queryId);
178178
assertEquals(2, cteDataStore.getCount());
179179

180-
assertEquals(896, cteDataStore.ramBytesUsed());
180+
assertEquals(904, cteDataStore.ramBytesUsed());
181181

182182
// Both operators should be able to read data
183183
assertTrue(operator1.hasNext());

0 commit comments

Comments
 (0)