JackieTien97 commented on a change in pull request #5317:
URL: https://github.com/apache/iotdb/pull/5317#discussion_r832067228



##########
File path: 
server/src/main/java/org/apache/iotdb/db/mpp/buffer/DataBlockServiceImpl.java
##########
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.iotdb.db.mpp.buffer;
-
-import org.apache.iotdb.mpp.rpc.thrift.DataBlockService;
-import org.apache.iotdb.mpp.rpc.thrift.EndOfDataBlockEvent;
-import org.apache.iotdb.mpp.rpc.thrift.GetDataBlockReqest;
-import org.apache.iotdb.mpp.rpc.thrift.GetDataBlockResponse;
-import org.apache.iotdb.mpp.rpc.thrift.NewDataBlockEvent;
-
-import org.apache.thrift.TException;
-
-public class DataBlockServiceImpl implements DataBlockService.Iface {

Review comment:
       Why we delete this class?

##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/memory/MemoryPool.java
##########
@@ -79,8 +142,37 @@ public synchronized void free(String queryId, long bytes) {
     } else {
       queryMemoryReservations.put(queryId, queryReservedBytes);
     }
-
     reservedBytes -= bytes;
+
+    List<MemoryReservationFuture<Void>> futures =

Review comment:
       In this way, if one query free its memory, it will only notify blocking 
Futures belonging to this query. Other queries won't be notified and still 
waiting. 
   And it seems that one free operation will only notify one blocking Future, 
but what if this freeing operation frees a large memory block which is large 
enough for multiple blocking Futures. 

##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/memory/MemoryPool.java
##########
@@ -19,24 +19,60 @@
 
 package org.apache.iotdb.db.mpp.memory;
 
+import com.google.common.util.concurrent.AbstractFuture;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.Validate;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 /** Manages certain amount of memory. */
 public class MemoryPool {
 
+  private static class MemoryReservationFuture<V> extends AbstractFuture<V> {
+    private final long bytes;
+
+    private MemoryReservationFuture(long bytes) {
+      Validate.isTrue(bytes > 0L, "bytes should be greater than zero.");
+      this.bytes = bytes;
+    }
+
+    public long getBytes() {
+      return bytes;
+    }
+
+    public static <V> MemoryReservationFuture<V> create(long bytes) {
+      return new MemoryReservationFuture<>(bytes);
+    }
+
+    @Override
+    public boolean set(@Nullable V value) {
+      return super.set(value);
+    }
+  }
+
   private final String id;
   private final long maxBytes;
+  private final long maxBytesPerQuery;
 
   private long reservedBytes = 0L;
   private final Map<String, Long> queryMemoryReservations = new HashMap<>();
+  private final Map<String, List<MemoryReservationFuture<Void>>> 
queryIdToFutures = new HashMap<>();

Review comment:
       We have `QueryId` class now, you can use that class to replace `String`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to