Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import org.apache.iotdb.commons.pipe.datastructure.pattern.PipePattern;
import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
import org.apache.iotdb.commons.pipe.event.PipeWritePlanEvent;
import org.apache.iotdb.db.pipe.metric.overview.PipeDataNodeSinglePipeMetrics;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.DeleteDataNode;

import org.apache.tsfile.utils.ReadWriteIOUtils;

Expand Down Expand Up @@ -58,6 +60,29 @@ public PlanNode getPlanNode() {
return planNode;
}

@Override
public boolean isDataRegionEvent() {
return planNode instanceof DeleteDataNode || super.isDataRegionEvent();
}

@Override
public boolean internallyIncreaseResourceReferenceCount(final String holderMessage) {
if (planNode instanceof DeleteDataNode && getPipeName() != null) {
PipeDataNodeSinglePipeMetrics.getInstance()
.increaseDeletionEventCount(getPipeName(), getCreationTime());
}
return super.internallyIncreaseResourceReferenceCount(holderMessage);
}

@Override
public boolean internallyDecreaseResourceReferenceCount(final String holderMessage) {
if (planNode instanceof DeleteDataNode && getPipeName() != null) {
PipeDataNodeSinglePipeMetrics.getInstance()
.decreaseDeletionEventCount(getPipeName(), getCreationTime());
}
return super.internallyDecreaseResourceReferenceCount(holderMessage);
}

@Override
public EnrichedEvent shallowCopySelfAndBindPipeTaskMetaForProgressReport(
final String pipeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class PipeDataNodeRemainingEventAndTimeOperator extends PipeRemainingOper
Collections.newSetFromMap(new ConcurrentHashMap<>());

private final AtomicInteger insertNodeEventCount = new AtomicInteger(0);
private final AtomicInteger deletionEventCount = new AtomicInteger(0);
private final AtomicInteger rawTabletEventCount = new AtomicInteger(0);
private final AtomicInteger tsfileEventCount = new AtomicInteger(0);
private final AtomicInteger heartbeatEventCount = new AtomicInteger(0);
Expand Down Expand Up @@ -80,6 +81,14 @@ void decreaseInsertNodeEventCount() {
insertNodeEventCount.decrementAndGet();
}

void increaseDeletionEventCount() {
deletionEventCount.incrementAndGet();
}

void decreaseDeletionEventCount() {
deletionEventCount.decrementAndGet();
}

void increaseRawTabletEventCount() {
rawTabletEventCount.incrementAndGet();
}
Expand Down Expand Up @@ -109,10 +118,10 @@ public long getRemainingNonHeartbeatEvents() {
tsfileEventCount.get()
+ rawTabletEventCount.get()
+ insertNodeEventCount.get()
+ deletionEventCount.get()
+ dataRegionSources.stream()
.map(IoTDBDataRegionSource::getHistoricalTsFileInsertionEventCount)
.reduce(Integer::sum)
.orElse(0)
.mapToLong(IoTDBDataRegionSource::getHistoricalEventCount)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/metric/overview/PipeDataNodeRemainingEventAndTimeOperator.java:123 — Switching remaining-event source to getHistoricalEventCount breaks existing dev/1.3 test

getRemainingNonHeartbeatEvents() now sums IoTDBDataRegionSource.getHistoricalEventCount(), but PipeDataNodeSinglePipeMetricsTest#testDeregisterClearsOperatorsWhenMetricsAreUnbound (added to dev/1.3 by #19390, kept unchanged here) still stubs only getHistoricalTsFileInsertionEventCount() -> 1 at line 130 and asserts remaining events == 1 at lines 142-143. The mock's getHistoricalEventCount() returns 0, so the assertion becomes expected:<1> but was:<0> and the DataNode test run fails.

Fix: Update that test to stub getHistoricalEventCount() to 1 (as the source commit did for the same test), or stub both getHistoricalEventCount() and getHistoricalTsFileInsertionEventCount().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit c26f88f6494d6a8ceced2858c781c72e5bb9fb34. PipeDataNodeSinglePipeMetricsTest#testDeregisterClearsOperatorsWhenMetricsAreUnbound now stubs getHistoricalEventCount() to 1, matching the accessor used by getRemainingNonHeartbeatEvents(). The focused clean DataNode test run passed: 6 tests, 0 failures, 0 errors, 0 skipped.

.sum()
+ schemaRegionSources.stream()
.map(IoTDBSchemaRegionSource::getUnTransferredEventCount)
.reduce(Long::sum)
Expand Down Expand Up @@ -140,11 +149,24 @@ public double getRemainingTime() {
PipeConfig.getInstance().getPipeRemainingTimeCommitRateAverageTime();

final double invocationValue = collectInvocationHistogram.getMean();
final long pendingHistoricalEventCount =
dataRegionSources.stream().mapToLong(IoTDBDataRegionSource::getHistoricalEventCount).sum();
final long pendingHistoricalTsFileEventCount =
dataRegionSources.stream()
.mapToLong(IoTDBDataRegionSource::getHistoricalTsFileInsertionEventCount)
.sum();
final long pendingHistoricalNonTsFileEventCount =
Math.max(0, pendingHistoricalEventCount - pendingHistoricalTsFileEventCount);
// Do not take heartbeat event into account
final double totalDataRegionWriteEventCount =
tsfileEventCount.get() * Math.max(invocationValue, 1)
+ rawTabletEventCount.get()
+ insertNodeEventCount.get();
calculateTotalDataRegionWriteEventCount(
tsfileEventCount.get(),
pendingHistoricalTsFileEventCount,
pendingHistoricalNonTsFileEventCount,
deletionEventCount.get(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/metric/overview/PipeDataNodeRemainingEventAndTimeOperator.java:166 — Deletion events counted in data-region numerator but delete commits mark the schema-region meter

deletionEventCount is added to totalDataRegionWriteEventCount (line 166), yet in dev/1.3 a delete event is a PipeSchemaRegionWritePlanEvent and EnrichedEvent.isDataRegionEvent() returns false for PipeWritePlanEvents, so PipeDataNodeSinglePipeMetrics.markRegionCommit records delete commits on the schema-region meter. Trigger: a pipe whose only DML is deletions (source.inclusion=data.delete) or any moment with a pending deletion and no data-region commit in the rate window. Result: dataRegionCommitMeter rate is 0, so lines 180-183 yield Double.MAX_VALUE and getRemainingTime() saturates at REMAINING_MAX_SECONDS (1 year) instead of 0/converging (master's PipeDeleteDataNodeEvent is a data-region event, so this mismatch is backport-specific).

Fix: Route DeleteDataNode event commits to the data-region commit meter (e.g., make the delete-plan event report data-region commit rate in PipeEventCommitManager.commit/markRegionCommit), or keep deletionEventCount out of the data-region numerator until a matching deletion rate exists.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. In dev/1.3, DeleteDataNode commits are wrapped in PipeSchemaRegionWritePlanEvent, so they were marked as schema-region commits even though deletion events are included in the data-region remaining-work numerator. I updated the event classification so delete-plan commits use the data-region rate and added a regression assertion. The focused DataNode test passes (4 tests).

rawTabletEventCount.get(),
insertNodeEventCount.get(),
invocationValue);

final Meter dataRegionMeter = dataRegionCommitMeter.get();
if (Objects.nonNull(dataRegionMeter)) {
Expand Down Expand Up @@ -192,6 +214,22 @@ public double getRemainingTime() {
return result >= REMAINING_MAX_SECONDS ? REMAINING_MAX_SECONDS : result;
}

static double calculateTotalDataRegionWriteEventCount(
final long tsFileEventCount,
final long pendingHistoricalTsFileEventCount,
final long pendingHistoricalNonTsFileEventCount,
final long deletionEventCount,
final long rawTabletEventCount,
final long insertNodeEventCount,
final double invocationValue) {
return (tsFileEventCount + (double) pendingHistoricalTsFileEventCount)
* Math.max(invocationValue, 1)
+ pendingHistoricalNonTsFileEventCount
+ deletionEventCount
+ rawTabletEventCount
+ insertNodeEventCount;
}

//////////////////////////// Register & deregister (pipe integration) ////////////////////////////

void register(final IoTDBDataRegionSource source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ public void decreaseInsertNodeEventCount(
}
}

public void increaseDeletionEventCount(final String pipeName, final long creationTime) {
final PipeDataNodeRemainingEventAndTimeOperator operator =
getOrCreateOperatorIfPipeAlive(pipeName, creationTime);
if (Objects.nonNull(operator)) {
operator.increaseDeletionEventCount();
}
}

public void decreaseDeletionEventCount(final String pipeName, final long creationTime) {
final PipeDataNodeRemainingEventAndTimeOperator operator =
remainingEventAndTimeOperatorMap.get(generatePipeID(pipeName, creationTime));
if (Objects.nonNull(operator)) {
operator.decreaseDeletionEventCount();
}
}

public void updateInsertNodeTransferTimer(
final String pipeName, final long creationTime, final long transferTime) {
final PipeDataNodeRemainingEventAndTimeOperator operator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class IoTDBDataRegionSource extends IoTDBSource {
private boolean hasNoExtractionNeed = true;
private boolean shouldExtractDeletion = false;
private final AtomicBoolean completionSourceStarted = new AtomicBoolean(false);
private boolean hasBeenClosed = false;

@Override
public void validate(final PipeParameterValidator validator) throws Exception {
Expand Down Expand Up @@ -344,8 +345,8 @@ public void customize(
}

@Override
public void start() throws Exception {
if (hasNoExtractionNeed || hasBeenStarted.get()) {
public synchronized void start() throws Exception {
if (hasBeenClosed || hasNoExtractionNeed || hasBeenStarted.get()) {
return;
}

Expand Down Expand Up @@ -458,7 +459,11 @@ public Event supply() throws Exception {
}

@Override
public void close() throws Exception {
public synchronized void close() throws Exception {
if (hasBeenClosed) {
return;
}
hasBeenClosed = true;
completionSourceStarted.set(false);
PipeDataNodeSinglePipeMetrics.getInstance().deregister(this);
if (hasNoExtractionNeed || !hasBeenStarted.get()) {
Expand All @@ -485,6 +490,12 @@ public boolean isReadyForCompletion() {
//////////////////////////// APIs provided for metric framework ////////////////////////////

public int getHistoricalTsFileInsertionEventCount() {
return hasBeenStarted.get() && Objects.nonNull(historicalExtractor)
? historicalExtractor.getPendingTsFileInsertionEventCount()
: 0;
}

public int getHistoricalEventCount() {
return hasBeenStarted.get() && Objects.nonNull(historicalExtractor)
? historicalExtractor.getPendingQueueSize()
: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface PipeHistoricalDataRegionSource extends PipeExtractor {
boolean hasConsumedAll();

int getPendingQueueSize();

int getPendingTsFileInsertionEventCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public class PipeHistoricalDataRegionTsFileSource implements PipeHistoricalDataR
private volatile boolean hasBeenStarted = false;

private Queue<TsFileResource> pendingQueue;
private volatile int pendingQueueSize;
private volatile int pendingTsFileInsertionEventCount;
private final Set<TsFileResource> filteredTsFileResources = new HashSet<>();
private final Set<TsFileResource> resourcesWithPinnedModFile = new HashSet<>();
private final Set<TsFileResource> historicalProgressReportResources = new HashSet<>();
Expand Down Expand Up @@ -369,11 +371,13 @@ public synchronized void start() {
pendingHistoricalProgressIndexToReport = null;
shouldReportMaxHistoricalProgressIndex = false;
historicalProgressReportResources.clear();
pendingTsFileInsertionEventCount = 0;

final DataRegion dataRegion =
StorageEngine.getInstance().getDataRegion(new DataRegionId(dataRegionId));
if (Objects.isNull(dataRegion)) {
pendingQueue = new ArrayDeque<>();
pendingQueueSize = 0;
return;
}

Expand Down Expand Up @@ -455,6 +459,9 @@ public synchronized void start() {
prepareProgressReportResourcesForHistoricalTsFileQueryPriorityOrder(originalResourceList);
}
pendingQueue = new ArrayDeque<>(originalResourceList);
pendingQueueSize = pendingQueue.size();
pendingTsFileInsertionEventCount =
countPendingTsFileInsertionEvents(originalResourceList, filteredTsFileResources);
PipeTerminateEvent.initializeHistoricalTransferSummary(
pipeName, creationTime, dataRegionId, filteredTsFileResources.size(), 0);

Expand Down Expand Up @@ -827,8 +834,9 @@ public synchronized Event supply() {
return supplyTerminateEvent();
}

if (!filteredTsFileResources.contains(resource)) {
pendingQueue.poll();
final boolean wasPendingTsFileInsertionCandidate = filteredTsFileResources.contains(resource);
if (!wasPendingTsFileInsertionCandidate) {
pollPendingResource(false);
if (shouldUseHistoricalTsFileQueryPriorityOrder()) {
if (shouldReportHistoricalProgressAfterResource(resource)) {
return supplyHistoricalProgressReportEvent(
Expand All @@ -840,7 +848,7 @@ public synchronized Event supply() {
}

final Event event = supplyTsFileEvent(resource);
pendingQueue.poll();
pollPendingResource(wasPendingTsFileInsertionCandidate);
if (Objects.nonNull(event) && shouldReportHistoricalProgressAfterResource(resource)) {
pendingHistoricalProgressIndexToReport = getHistoricalProgressIndexAfterResource(resource);
}
Expand All @@ -858,6 +866,21 @@ private ProgressIndex getHistoricalProgressIndexAfterResource(final TsFileResour
resource.getTimePartition(), resource.getMaxProgressIndex());
}

static int countPendingTsFileInsertionEvents(
final List<TsFileResource> pendingResources,
final Set<TsFileResource> tsFileInsertionCandidates) {
return (int) pendingResources.stream().filter(tsFileInsertionCandidates::contains).count();
}

private TsFileResource pollPendingResource(final boolean wasPendingTsFileInsertionCandidate) {
final TsFileResource resource = pendingQueue.poll();
pendingQueueSize = pendingQueue.size();
if (resource != null && wasPendingTsFileInsertionCandidate) {
pendingTsFileInsertionEventCount--;
}
return resource;
}

private Event supplyTerminateEvent() {
final PipeTerminateEvent.HistoricalTransferSummary historicalTransferSummary =
PipeTerminateEvent.snapshotHistoricalTransferSummary(pipeName, creationTime, dataRegionId);
Expand Down Expand Up @@ -910,7 +933,7 @@ private Event supplyHistoricalProgressReportEvent(final ProgressIndex progressIn
return supplyProgressReportEvent(progressIndex);
}

private Event supplyTsFileEvent(final TsFileResource resource) {
protected Event supplyTsFileEvent(final TsFileResource resource) {
final PipeTsFileInsertionEvent event =
new PipeTsFileInsertionEvent(
resource,
Expand Down Expand Up @@ -978,7 +1001,12 @@ public synchronized boolean hasConsumedAll() {

@Override
public int getPendingQueueSize() {
return Objects.nonNull(pendingQueue) ? pendingQueue.size() : 0;
return pendingQueueSize;
}

@Override
public int getPendingTsFileInsertionEventCount() {
return pendingTsFileInsertionEventCount;
}

@Override
Expand Down Expand Up @@ -1006,6 +1034,8 @@ public synchronized void close() {
pendingQueue.clear();
pendingQueue = null;
}
pendingQueueSize = 0;
pendingTsFileInsertionEventCount = 0;
resourcesWithPinnedModFile.clear();
historicalProgressReportResources.clear();
pendingHistoricalProgressIndexToReport = null;
Expand Down
Loading
Loading