XNX02 commented on code in PR #15275: URL: https://github.com/apache/iotdb/pull/15275#discussion_r2063404151
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/statement/PipeStatementInsertionEvent.java: ########## @@ -0,0 +1,219 @@ +/* + * 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.pipe.event.common.statement; + +import org.apache.iotdb.commons.consensus.index.ProgressIndex; +import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta; +import org.apache.iotdb.commons.pipe.datastructure.pattern.TablePattern; +import org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern; +import org.apache.iotdb.commons.pipe.event.EnrichedEvent; +import org.apache.iotdb.commons.pipe.resource.ref.PipePhantomReferenceManager; +import org.apache.iotdb.db.pipe.event.ReferenceTrackableEvent; +import org.apache.iotdb.db.pipe.event.common.PipeInsertionEvent; +import org.apache.iotdb.db.pipe.metric.overview.PipeDataNodeRemainingEventAndTimeMetrics; +import org.apache.iotdb.db.pipe.resource.PipeDataNodeResourceManager; +import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryWeightUtil; +import org.apache.iotdb.db.pipe.resource.memory.PipeTabletMemoryBlock; +import org.apache.iotdb.db.queryengine.plan.statement.Statement; +import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertBaseStatement; + +import org.apache.tsfile.utils.RamUsageEstimator; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +public class PipeStatementInsertionEvent extends PipeInsertionEvent + implements ReferenceTrackableEvent, AutoCloseable { + + // For better calculation + private static final long INSTANCE_SIZE = + RamUsageEstimator.shallowSizeOfInstance(PipeStatementInsertionEvent.class); + private InsertBaseStatement statement; + private boolean needToReport; + private final PipeTabletMemoryBlock allocatedMemoryBlock; + private volatile ProgressIndex progressIndex; + + public PipeStatementInsertionEvent( + String pipeName, + long creationTime, + PipeTaskMeta pipeTaskMeta, + TreePattern treePattern, + TablePattern tablePattern, + String userName, + boolean skipIfNoPrivileges, + Boolean isTableModelEvent, + String databaseNameFromDataRegion, + InsertBaseStatement statement) { + super( + pipeName, + creationTime, + pipeTaskMeta, + treePattern, + tablePattern, + userName, + skipIfNoPrivileges, + Long.MIN_VALUE, + Long.MAX_VALUE, + isTableModelEvent, + databaseNameFromDataRegion, + null, + null); + this.statement = statement; + // Allocate empty memory block, will be resized later. + this.allocatedMemoryBlock = + PipeDataNodeResourceManager.memory().forceAllocateForTabletWithRetry(0); + } + + @Override + public boolean internallyIncreaseResourceReferenceCount(String holderMessage) { + PipeDataNodeResourceManager.memory() + .forceResize( + allocatedMemoryBlock, + PipeMemoryWeightUtil.calculateInsertBaseStatementSizeInBytes(statement) + + INSTANCE_SIZE); + if (Objects.nonNull(pipeName)) { + PipeDataNodeRemainingEventAndTimeMetrics.getInstance() + .increaseTabletEventCount(pipeName, creationTime); + } + return true; + } + + @Override + public boolean internallyDecreaseResourceReferenceCount(String holderMessage) { + if (Objects.nonNull(pipeName)) { + PipeDataNodeRemainingEventAndTimeMetrics.getInstance() + .decreaseTabletEventCount(pipeName, creationTime); + } + allocatedMemoryBlock.close(); + + statement = null; + return true; + } + + @Override + public void bindProgressIndex(final ProgressIndex progressIndex) { Review Comment: It is useless in MQTT Source, but it might be used in other external sources like Kafka? -- 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]
