OneSizeFitsQuorum commented on code in PR #14597: URL: https://github.com/apache/iotdb/pull/14597#discussion_r1908597748
########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IIoTDBMemoryBlock.java: ########## @@ -0,0 +1,54 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; + +public abstract class IIoTDBMemoryBlock implements AutoCloseable { + protected IoTDBMemoryManager memoryManager; + protected IoTDBMemoryBlockType memoryBlockType; + protected final ReentrantLock lock = new ReentrantLock(); + protected long maxMemorySizeInByte = 0; + protected final AtomicLong memoryUsageInBytes = new AtomicLong(0); + protected volatile boolean isReleased = false; + + public abstract boolean useMemory(final long size); + + public long getMaxMemorySizeInByte() { + return maxMemorySizeInByte; + } + + public long getMemoryUsageInBytes() { + return memoryUsageInBytes.get(); + } + + public void setMaxMemorySizeInByte(final long maxMemorySizeInByte) { Review Comment: mobe to line 39? ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IoTDBRuntimeOutOfMemoryException.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.tsfile.utils.ReadWriteIOUtils; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.Objects; + +public class IoTDBRuntimeOutOfMemoryException extends RuntimeException { Review Comment: This is not actually an OutOfMemoryException, right? Maybe a more reasonable name could be changed ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IoTDBRuntimeOutOfMemoryException.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.tsfile.utils.ReadWriteIOUtils; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.Objects; + +public class IoTDBRuntimeOutOfMemoryException extends RuntimeException { + + private final long timeStamp; Review Comment: use timestamp ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IIoTDBMemoryBlock.java: ########## @@ -0,0 +1,54 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; + +public abstract class IIoTDBMemoryBlock implements AutoCloseable { Review Comment: IMemoryBlock ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IIoTDBMemoryBlock.java: ########## @@ -0,0 +1,54 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; + +public abstract class IIoTDBMemoryBlock implements AutoCloseable { Review Comment: Add some javadoc and description for this basic class ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IIoTDBMemoryBlock.java: ########## @@ -0,0 +1,54 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; + +public abstract class IIoTDBMemoryBlock implements AutoCloseable { + protected IoTDBMemoryManager memoryManager; + protected IoTDBMemoryBlockType memoryBlockType; + protected final ReentrantLock lock = new ReentrantLock(); + protected long maxMemorySizeInByte = 0; + protected final AtomicLong memoryUsageInBytes = new AtomicLong(0); + protected volatile boolean isReleased = false; + + public abstract boolean useMemory(final long size); + + public long getMaxMemorySizeInByte() { + return maxMemorySizeInByte; + } + + public long getMemoryUsageInBytes() { + return memoryUsageInBytes.get(); + } + + public void setMaxMemorySizeInByte(final long maxMemorySizeInByte) { Review Comment: When will this function be called? ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IIoTDBMemoryBlock.java: ########## @@ -0,0 +1,54 @@ +/* + * 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 java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; + +public abstract class IIoTDBMemoryBlock implements AutoCloseable { + protected IoTDBMemoryManager memoryManager; + protected IoTDBMemoryBlockType memoryBlockType; + protected final ReentrantLock lock = new ReentrantLock(); Review Comment: if you use this only in close method, why not directly use method synchronized? ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/metrics/WritingMetrics.java: ########## @@ -515,7 +509,7 @@ public void createDataRegionMemoryCostMetrics(DataRegion dataRegion) { MetricService.getInstance() .createAutoGauge( Metric.DATA_REGION_MEM_COST.toString(), - MetricLevel.IMPORTANT, + MetricLevel.NORMAL, Review Comment: Do not change existing metrics's level to normal? ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IoTDBMemoryBlock.java: ########## @@ -0,0 +1,122 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +public class IoTDBMemoryBlock extends IIoTDBMemoryBlock { + private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBMemoryBlock.class); + + public IoTDBMemoryBlock(final IoTDBMemoryManager memoryManager, final long maxMemorySizeInByte) { + this.memoryManager = memoryManager; + this.maxMemorySizeInByte = maxMemorySizeInByte; + this.memoryBlockType = IoTDBMemoryBlockType.NONE; + } + + public IoTDBMemoryBlock( + final IoTDBMemoryManager memoryManager, + final long maxMemorySizeInByte, + final IoTDBMemoryBlockType memoryBlockType) { + this.memoryManager = memoryManager; + this.maxMemorySizeInByte = maxMemorySizeInByte; + this.memoryBlockType = memoryBlockType; + } + + @Override + public boolean useMemory(final long size) { + if (size <= 0) { + memoryUsageInBytes.addAndGet(-size); Review Comment: when will size be negetive? -- 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]
