mychaow commented on a change in pull request #1524: URL: https://github.com/apache/incubator-iotdb/pull/1524#discussion_r478809396
########## File path: server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorInfo.java ########## @@ -0,0 +1,103 @@ +/* + * 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.engine.storagegroup; + +import org.apache.iotdb.db.conf.IoTDBDescriptor; + +/** + * The TsFileProcessorInfo records the memory cost of this TsFileProcessor. + */ +public class TsFileProcessorInfo { + + /** + * Once tspInfo updated, report to storageGroupInfo that this TSP belongs to. + */ + private StorageGroupInfo storageGroupInfo; + + /** + * The memory cost of the unsealed TsFileResources of this TSP + */ + private long unsealedResourceMemCost; + + /** + * The memory cost of TEXT data of this TSP + */ + private long bytesMemCost; + + /** + * The memory cost of ChunkMetadata of this TSP + */ + private long chunkMetadataMemCost; + + /** + * The memory cost of WAL of this TSP + */ + private long walMemCost; + + public TsFileProcessorInfo(StorageGroupInfo storageGroupInfo) { + this.storageGroupInfo = storageGroupInfo; + this.unsealedResourceMemCost = 0; + this.bytesMemCost = 0; + this.chunkMetadataMemCost = 0; + this.walMemCost = IoTDBDescriptor.getInstance().getConfig().getWalBufferSize(); + } + + public void addUnsealedResourceMemCost(long cost) { + unsealedResourceMemCost += cost; + storageGroupInfo.addUnsealedResourceMemCost(cost); + } + + public void addChunkMetadataMemCost(long cost) { + chunkMetadataMemCost += cost; + storageGroupInfo.addChunkMetadataMemCost(cost); + } + + public void addBytesMemCost(long cost) { + bytesMemCost += cost; + storageGroupInfo.addBytesMemCost(cost); + } + + /** + * call this method when closing TSP + */ + public void clear() { + storageGroupInfo.resetUnsealedResourceMemCost(unsealedResourceMemCost); + storageGroupInfo.resetChunkMetadataMemCost(chunkMetadataMemCost); + storageGroupInfo.resetWalMemCost(walMemCost); Review comment: yes, one tsp clear is called only be one thread, but if two TSPs are called clear(), the storageGroupInfo.resetWalMemCost() maybe called by tow threads? and storageGroupInfo.resetWalMemCost is not thread safe. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org