You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Cpaulyz (via GitHub)" <gi...@apache.org> on 2023/02/02 09:36:14 UTC

[GitHub] [iotdb] Cpaulyz opened a new pull request, #8966: [IOTDB-5459] Memory control cross SchemaRegion

Cpaulyz opened a new pull request, #8966:
URL: https://github.com/apache/iotdb/pull/8966

   ## Description
   
   The shortcoming of the current implementation is that a schemaRegion can only trigger the release of its own occupied memory and cannot affect other schemaRegions, lacking global memory control. It may lead to an incorrect SeriesOverflowException
   
   For example, if there is a SchemaRegion1 and a SchemaRegion2, the IMnode of schemaRegion1 needs to be considered if writes to schema region2 cause the total memory to exceed the release threshold and trigger an internal/external memory swap. 
   
   Therefore, a global CacheMemoryManager needs to be introduced for memory control.
   
   https://apache-iotdb.feishu.cn/docx/IVtgdbJNPoIjpdxlQTocOuTTnLh


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1096666666


##########
node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java:
##########
@@ -61,8 +61,9 @@ public enum ThreadName {
   ASYNC_DATANODE_HEARTBEAT_CLIENT_POOL("AsyncDataNodeHeartbeatServiceClientPool"),
   ASYNC_CONFIGNODE_CLIENT_POOL("AsyncConfigNodeIServiceClientPool"),
   ASYNC_DATANODE_MPP_DATA_EXCHANGE_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool"),
-
-  ASYNC_DATANODE_IOT_CONSENSUS_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool");
+  ASYNC_DATANODE_IOT_CONSENSUS_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool"),
+  MTREE_FLUSH_THREAD_POOL("MTree-flush-task"),
+  MTREE_RELEASE_THREAD_POOL_NAME("MTree-release-task");

Review Comment:
   done



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1095409550


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk merged pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk merged PR #8966:
URL: https://github.com/apache/iotdb/pull/8966


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1094602168


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;

Review Comment:
   This method should be synchronized or use a thread-safe list, in case of concurrent creating SchemaRegion.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1094630471


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);
+  }
+
+  /**
+   * Execute cache eviction until the memory status is under safe mode or no node could be evicted.
+   * If the memory status is still full, which means the nodes in memory are all volatile nodes, new
+   * added or updated, fire flush task.
+   */
+  private void tryExecuteMemoryRelease() {
+    for (CachedMTreeStore store : storeList) {
+      store.getLock().threadReadLock();
+      try {
+        store.executeMemoryRelease();
+      } finally {
+        store.getLock().threadReadUnlock();
+      }
+      if (!memManager.isExceedReleaseThreshold() || memManager.isEmpty()) {
+        break;
+      }
+    }
+    releaseCount++;
+    hasReleaseTask = false;
+    if (memManager.isExceedFlushThreshold() && !hasFlushTask) {
+      registerFlushTask();
+    }
+  }
+
+  private synchronized void registerFlushTask() {
+    if (hasFlushTask) {
+      return;
+    }
+    hasFlushTask = true;
+    flushTaskManager.submit(this::tryFlushVolatileNodes);

Review Comment:
   Same problem as release task. Maybe these two boolean field should be attributes of store rather than a global unique attribute.



##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);

Review Comment:
   It seems there won' be more than two release tasks being executed concurrently. The efficiency is not much high enough, and it's a waste to prepare an independent thread pool for such tasks.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1096657342


##########
node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java:
##########
@@ -61,8 +61,9 @@ public enum ThreadName {
   ASYNC_DATANODE_HEARTBEAT_CLIENT_POOL("AsyncDataNodeHeartbeatServiceClientPool"),
   ASYNC_CONFIGNODE_CLIENT_POOL("AsyncConfigNodeIServiceClientPool"),
   ASYNC_DATANODE_MPP_DATA_EXCHANGE_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool"),
-
-  ASYNC_DATANODE_IOT_CONSENSUS_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool");
+  ASYNC_DATANODE_IOT_CONSENSUS_CLIENT_POOL("AsyncDataNodeMPPDataExchangeServiceClientPool"),
+  MTREE_FLUSH_THREAD_POOL("MTree-flush-task"),
+  MTREE_RELEASE_THREAD_POOL_NAME("MTree-release-task");

Review Comment:
   Rename to ```SchemaRegion-Flush-Task``` and ```SchemaRegion-Release-Task```.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1095422124


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);
+  }
+
+  /**
+   * Execute cache eviction until the memory status is under safe mode or no node could be evicted.
+   * If the memory status is still full, which means the nodes in memory are all volatile nodes, new
+   * added or updated, fire flush task.
+   */
+  private void tryExecuteMemoryRelease() {
+    for (CachedMTreeStore store : storeList) {
+      store.getLock().threadReadLock();
+      try {
+        store.executeMemoryRelease();
+      } finally {
+        store.getLock().threadReadUnlock();
+      }
+      if (!memManager.isExceedReleaseThreshold() || memManager.isEmpty()) {
+        break;
+      }
+    }
+    releaseCount++;
+    hasReleaseTask = false;
+    if (memManager.isExceedFlushThreshold() && !hasFlushTask) {
+      registerFlushTask();
+    }
+  }
+
+  private synchronized void registerFlushTask() {
+    if (hasFlushTask) {
+      return;
+    }
+    hasFlushTask = true;
+    flushTaskManager.submit(this::tryFlushVolatileNodes);

Review Comment:
   I think the two global boolean variables are used to avoid duplicate release/flush requests during the release/flush process, which is needed since the release/flush thread is currently globally unique. When hasFlushTask is false, all store's hasFlushTask is also false, so there seems to be no need to migrate to store?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1095413785


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);

Review Comment:
   replaced by SingleThreadExecutor



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1096666781


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);

Review Comment:
   Use CompleteFuture to release and flush concurrently.



##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);
+  }
+
+  /**
+   * Execute cache eviction until the memory status is under safe mode or no node could be evicted.
+   * If the memory status is still full, which means the nodes in memory are all volatile nodes, new
+   * added or updated, fire flush task.
+   */
+  private void tryExecuteMemoryRelease() {
+    for (CachedMTreeStore store : storeList) {
+      store.getLock().threadReadLock();
+      try {
+        store.executeMemoryRelease();
+      } finally {
+        store.getLock().threadReadUnlock();
+      }
+      if (!memManager.isExceedReleaseThreshold() || memManager.isEmpty()) {
+        break;
+      }
+    }
+    releaseCount++;
+    hasReleaseTask = false;
+    if (memManager.isExceedFlushThreshold() && !hasFlushTask) {
+      registerFlushTask();
+    }
+  }
+
+  private synchronized void registerFlushTask() {
+    if (hasFlushTask) {
+      return;
+    }
+    hasFlushTask = true;
+    flushTaskManager.submit(this::tryFlushVolatileNodes);

Review Comment:
   Use CompleteFuture to release and flush concurrently.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #8966: [IOTDB-5459] Memory control cross SchemaRegion

Posted by "Cpaulyz (via GitHub)" <gi...@apache.org>.
Cpaulyz commented on code in PR #8966:
URL: https://github.com/apache/iotdb/pull/8966#discussion_r1095413785


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.metadata.mtree.store.disk.cache;
+
+import org.apache.iotdb.db.metadata.mtree.store.CachedMTreeStore;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeFlushTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.MTreeReleaseTaskManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.IMemManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.MemManagerHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CacheMemoryManager {
+
+  private final List<CachedMTreeStore> storeList = new ArrayList<>();
+
+  private final IMemManager memManager = MemManagerHolder.getMemManagerInstance();
+
+  private final MTreeFlushTaskManager flushTaskManager = MTreeFlushTaskManager.getInstance();
+  private int flushCount = 0;
+  private volatile boolean hasFlushTask;
+
+  private final MTreeReleaseTaskManager releaseTaskManager = MTreeReleaseTaskManager.getInstance();
+  private volatile boolean hasReleaseTask;
+  private int releaseCount = 0;
+
+  public ICacheManager createLRUCacheManager(CachedMTreeStore store) {
+    ICacheManager cacheManager = new LRUCacheManager();
+    storeList.add(store);
+    return cacheManager;
+  }
+
+  public void ensureMemoryStatus() {
+    if (memManager.isExceedFlushThreshold() && !hasReleaseTask) {
+      registerReleaseTask();
+    }
+  }
+
+  private synchronized void registerReleaseTask() {
+    if (hasReleaseTask) {
+      return;
+    }
+    hasReleaseTask = true;
+    releaseTaskManager.submit(this::tryExecuteMemoryRelease);

Review Comment:
   replaced by SingleThreadExecutor



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org