This is an automated email from the ASF dual-hosted git repository.
spricoder pushed a commit to branch feature/memory_auto
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/feature/memory_auto by this
push:
new 576b3a10866 Add Memory Service
576b3a10866 is described below
commit 576b3a10866abafe2b2c780549d39e69f368051f
Author: spricoder <[email protected]>
AuthorDate: Fri Feb 21 16:12:10 2025 +0800
Add Memory Service
---
.../java/org/apache/iotdb/db/service/DataNode.java | 4 ++
.../apache/iotdb/commons/memory/MemoryManager.java | 14 ++---
.../iotdb/commons/memory/MemoryRuntimeAgent.java | 72 ++++++++++++++++++++++
.../apache/iotdb/commons/service/ServiceType.java | 1 +
4 files changed, 82 insertions(+), 9 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
index 9a2ff29502a..1a05e47844e 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -38,6 +38,7 @@ import org.apache.iotdb.commons.consensus.SchemaRegionId;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.IoTDBException;
import org.apache.iotdb.commons.exception.StartupException;
+import org.apache.iotdb.commons.memory.MemoryRuntimeAgent;
import org.apache.iotdb.commons.pipe.agent.plugin.meta.PipePluginMeta;
import org.apache.iotdb.commons.pipe.config.PipeConfig;
import org.apache.iotdb.commons.service.JMXService;
@@ -248,6 +249,9 @@ public class DataNode extends ServerCommandLine implements
DataNodeMBean {
// Serialize mutable system properties
IoTDBStartCheck.getInstance().serializeMutableSystemPropertiesIfNecessary();
+ // Set memory service
+ registerManager.register(MemoryRuntimeAgent.getInstance());
+
logger.info("IoTDB configuration: {}", config.getConfigMessage());
logger.info("Congratulations, IoTDB DataNode is set up successfully.
Now, enjoy yourself!");
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
index fa088e95dda..47012f40b40 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
@@ -19,8 +19,6 @@
package org.apache.iotdb.commons.memory;
-import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
-import org.apache.iotdb.commons.concurrent.ThreadName;
import org.apache.iotdb.commons.utils.TestOnly;
import org.slf4j.Logger;
@@ -499,15 +497,13 @@ public class MemoryManager {
private static final MemoryManager GLOBAL =
new MemoryManager("GlobalMemoryManager", null,
Runtime.getRuntime().totalMemory());
- private static final MemoryPeriodicalJobExecutor EXECUTOR =
- new MemoryPeriodicalJobExecutor(
- IoTDBThreadPoolFactory.newSingleThreadScheduledExecutor(
- ThreadName.MEMORY_PERIODICAL_JOB_EXECUTOR.getName()),
- 20);
static {
- EXECUTOR.register(
- "GlobalMemoryManager#updateAllocate()",
MemoryManagerHolder.GLOBAL::updateAllocate, 20);
+ MemoryRuntimeAgent.getInstance()
+ .registerPeriodicalJob(
+ "GlobalMemoryManager#updateAllocate()",
+ MemoryManagerHolder.GLOBAL::updateAllocate,
+ 20);
}
private MemoryManagerHolder() {}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryRuntimeAgent.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryRuntimeAgent.java
new file mode 100644
index 00000000000..e8611339759
--- /dev/null
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryRuntimeAgent.java
@@ -0,0 +1,72 @@
+/*
+ * 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.commons.memory;
+
+import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
+import org.apache.iotdb.commons.concurrent.ThreadName;
+import org.apache.iotdb.commons.exception.StartupException;
+import org.apache.iotdb.commons.service.IService;
+import org.apache.iotdb.commons.service.ServiceType;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class MemoryRuntimeAgent implements IService {
+ private final AtomicBoolean isShutdown = new AtomicBoolean(false);
+
+ private static final MemoryPeriodicalJobExecutor memoryPeriodicalJobExecutor
=
+ new MemoryPeriodicalJobExecutor(
+ IoTDBThreadPoolFactory.newSingleThreadScheduledExecutor(
+ ThreadName.MEMORY_PERIODICAL_JOB_EXECUTOR.getName()),
+ 20);
+
+ @Override
+ public void start() throws StartupException {
+ memoryPeriodicalJobExecutor.start();
+
+ isShutdown.set(false);
+ }
+
+ @Override
+ public void stop() {
+ if (isShutdown.get()) {
+ return;
+ }
+ isShutdown.set(true);
+
+ memoryPeriodicalJobExecutor.stop();
+ }
+
+ public void registerPeriodicalJob(String id, Runnable periodicalJob, long
intervalInSeconds) {
+ memoryPeriodicalJobExecutor.register(id, periodicalJob, intervalInSeconds);
+ }
+
+ @Override
+ public ServiceType getID() {
+ return ServiceType.MEMORY_RUNTIME_AGENT;
+ }
+
+ private static class MemoryRuntimeAgentHolder {
+ private static final MemoryRuntimeAgent HANDLE = new MemoryRuntimeAgent();
+ }
+
+ public static MemoryRuntimeAgent getInstance() {
+ return MemoryRuntimeAgentHolder.HANDLE;
+ }
+}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java
index 205cbc4f6a4..7267c79a665 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java
@@ -80,6 +80,7 @@ public enum ServiceType {
PIPE_PLUGIN_CLASSLOADER_MANAGER_SERVICE(
"Pipe Plugin Classloader Manager Service", "PipePluginClassLoader"),
AINode_RPC_SERVICE("Rpc Service for AINode", "AINodeRPCService"),
+ MEMORY_RUNTIME_AGENT("Memory Runtime Agent", "MemoryRuntimeAgent"),
PIPE_RUNTIME_DATA_NODE_AGENT("Pipe Runtime Data Node Agent",
"PipeRuntimeDataNodeAgent"),
PIPE_RUNTIME_CONFIG_NODE_AGENT("Pipe Runtime Config Node Agent",
"PipeRuntimeConfigNodeAgent"),
SUBSCRIPTION_RUNTIME_AGENT("Subscription Runtime Agent",
"SubscriptionRuntimeAgent"),