SpriCoder commented on code in PR #14710: URL: https://github.com/apache/iotdb/pull/14710#discussion_r1978619563
########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java: ########## @@ -0,0 +1,523 @@ +/* + * 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.utils.TestOnly; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.LongUnaryOperator; + +public class MemoryManager { + private static final Logger LOGGER = LoggerFactory.getLogger(MemoryManager.class); + + /** The max retry times for memory allocation */ + private static final int MEMORY_ALLOCATE_MAX_RETRIES = 3; + + /** The retry interval for memory allocation */ + private static final long MEMORY_ALLOCATE_RETRY_INTERVAL_IN_MS = 1000; + + /** The min memory size to allocate */ + private static final long MEMORY_ALLOCATE_MIN_SIZE_IN_BYTES = 32; + + /** The name of memory manager */ + private final String name; + + /** Whether memory management is enabled */ + private final boolean enable; + + /** The total memory size in byte of memory manager */ + private long totalMemorySizeInBytes; + + /** The allocated memory size */ + private long allocatedMemorySizeInBytes = 0L; + + /** The parent memory manager */ + private final MemoryManager parentMemoryManager; + + /** The child memory manager */ + private final Map<String, MemoryManager> children = new ConcurrentHashMap<>(); + + /** The allocated memory blocks of this memory manager */ + private final Map<String, IMemoryBlock> allocatedMemoryBlocks = new ConcurrentHashMap<>(); + + @TestOnly + public MemoryManager(long totalMemorySizeInBytes) { + this.name = "Test"; + this.parentMemoryManager = null; + this.totalMemorySizeInBytes = totalMemorySizeInBytes; + this.enable = false; + } + + private MemoryManager( + String name, MemoryManager parentMemoryManager, long totalMemorySizeInBytes) { + this.name = name; + this.parentMemoryManager = parentMemoryManager; + this.totalMemorySizeInBytes = totalMemorySizeInBytes; + this.enable = false; + } + + private MemoryManager( + String name, MemoryManager parentMemoryManager, long totalMemorySizeInBytes, boolean enable) { + this.name = name; + this.parentMemoryManager = parentMemoryManager; + this.totalMemorySizeInBytes = totalMemorySizeInBytes; + this.enable = enable; + } + + // region The Methods Of IMemoryBlock Management + + /** + * Try to force allocate memory block with specified size in bytes Review Comment: Fixed ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java: ########## @@ -0,0 +1,523 @@ +/* + * 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.utils.TestOnly; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.LongUnaryOperator; + +public class MemoryManager { + private static final Logger LOGGER = LoggerFactory.getLogger(MemoryManager.class); + + /** The max retry times for memory allocation */ + private static final int MEMORY_ALLOCATE_MAX_RETRIES = 3; + + /** The retry interval for memory allocation */ + private static final long MEMORY_ALLOCATE_RETRY_INTERVAL_IN_MS = 1000; + + /** The min memory size to allocate */ + private static final long MEMORY_ALLOCATE_MIN_SIZE_IN_BYTES = 32; + + /** The name of memory manager */ + private final String name; + + /** Whether memory management is enabled */ + private final boolean enable; 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
