This is an automated email from the ASF dual-hosted git repository.
yujun777 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 7d457d52b82 [fix](stream) Calibrate changelog row counts with lagging
reports (#70892)
7d457d52b82 is described below
commit 7d457d52b823c15c3af2ff6b48f6330394d272a2
Author: yujun <[email protected]>
AuthorDate: Thu Nov 26 18:11:17 2026 +0800
[fix](stream) Calibrate changelog row counts with lagging reports (#70892)
### Background
Stream planning estimates retained changelog rows using periodic tablet
statistics and visible write notifications. Periodic statistics reflect
row removal from TTL cleanup, while write notifications keep the
estimate responsive between reports. Tablets are sampled independently,
so a complete set of samples can lag the latest write.
### What problem does this PR solve?
Issue Number: None
Related PR: #69896 (introduced the report-version guard)
PR Type: Bugfix
Problem Summary:
Continuous writes can keep every complete report one version behind,
preventing FE from removing expired rows from its estimate. FE now uses
each complete report with nondecreasing coverage to reset the estimate.
In a five-round test with 100 retained rows and a 10-row write ahead of
every report, the original estimate grows from 110 to 150. With the fix,
it returns to 100 after each report.
### Details
- **Change map:** FE catalog (89 additions, 69 deletions) updates report
aggregation and limits immediate estimates. FE unit tests (131
additions, 44 deletions) exercise both storage modes, capacity, retries,
and Cloud polling.
- **Frequency:** Always in the deterministic case where each complete
report lags a counted write. TTL cleanup makes the stale estimate
diverge from retained rows.
- **Root cause:** The tablet statistics managers and MaterializedIndex
required periodic coverage to reach the latest applied write. A complete
but lagging report could never correct the estimate during continuous
writes.
- **Why existing tests missed it:** The FE unit tests covered an
eventual up-to-date report. The immediate-count and Cloud subtransaction
suites pause periodic publication to check write estimates. Neither
exercised repeated lagging reports.
- **Fix:** Replace the estimate with the complete report sum and begin a
new window with a 128-write-version budget per changelog index. Tablet
counts can include writes newer than their reported version, so
replaying prior deltas can double count. Preserve a version boundary to
suppress already observed writes after a reset. Advance Cloud's refresh
watermark even when the estimate is at capacity.
- **Other paths and branches:** Covers shared-nothing publish and Cloud
commit notifications. The guard from #69896 is absent from the checked
upstream 3.1, 4.0, 4.1, and 4.2 branches.
- **Behavior change:** The estimate can temporarily omit recently
written rows when a report lags or the budget is exhausted. A first
notification that arrives after a sample already included its rows can
briefly inflate the estimate. A later complete report recalibrates it.
---
.../apache/doris/catalog/CloudTabletStatMgr.java | 20 +--
.../apache/doris/catalog/MaterializedIndex.java | 104 +++++++++-------
.../org/apache/doris/catalog/TabletStatMgr.java | 24 ++--
.../doris/catalog/MaterializedIndexTest.java | 136 +++++++++++++++------
.../apache/doris/catalog/TabletStatMgrTest.java | 37 +++++-
.../transaction/CloudGlobalTransactionMgrTest.java | 2 +-
6 files changed, 215 insertions(+), 108 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
index d4ad4cf965b..33378808e14 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
@@ -149,7 +149,7 @@ public class CloudTabletStatMgr extends MasterDaemon {
// at the infinite interval must fetch a valid count before
backoff can apply again.
RowCountReport report = cloudReplica.getRowCountReport();
if (report == null || materializedIndex.isChangelog()
- && report.version() <
materializedIndex.getRequiredChangelogReportVersion()) {
+ && report.version() <
materializedIndex.getChangelogStatsRefreshVersion()) {
return true;
}
int index = cloudReplica.getStatsIntervalIndex();
@@ -378,7 +378,8 @@ public class CloudTabletStatMgr extends MasterDaemon {
:
partition.getMaterializedIndices(IndexExtState.VISIBLE, true)) {
long indexRowCount = 0L;
long indexReportVersion = Long.MAX_VALUE;
- long requiredReportVersion =
index.getRequiredChangelogReportVersion();
+ long maxReportVersion = -1;
+ long requiredReportVersion =
index.getChangelogRowCountReportVersion();
boolean indexReported = true;
boolean anyTabletReported = false;
List<Tablet> tablets = index.getTablets();
@@ -414,7 +415,9 @@ public class CloudTabletStatMgr extends MasterDaemon {
tabletRowCount =
Math.max(tabletRowCount, replica.getRowCount());
tabletReported |= report != null;
} else if (report != null &&
report.version() >= requiredReportVersion
- && (!tabletReported ||
report.rows() > tabletRowCount)) {
+ && (!tabletReported ||
report.version() > tabletReportVersion
+ || report.version() ==
tabletReportVersion
+ && report.rows() >
tabletRowCount)) {
tabletRowCount = Math.max(0,
report.rows());
tabletReportVersion = report.version();
tabletReported = true;
@@ -442,6 +445,7 @@ public class CloudTabletStatMgr extends MasterDaemon {
indexRowCount += tabletRowCount;
indexReportVersion =
Math.min(indexReportVersion, tabletReportVersion);
+ maxReportVersion = Math.max(maxReportVersion,
tabletReportVersion);
indexReported &= tabletReported;
anyTabletReported |= tabletReported;
if (!index.isChangelog()) {
@@ -457,11 +461,11 @@ public class CloudTabletStatMgr extends MasterDaemon {
}
// A failed/absent MS fetch must not overwrite a
positive immediate
// changelog estimate with the replica's initial
zero.
- if (!index.isChangelog() || anyTabletReported ||
indexReported) {
- index.setReportedRowCount(indexRowCount,
indexReported,
- index.isChangelog() &&
!tablets.isEmpty() ? indexReportVersion : -1);
- } else {
- index.setRowCountReported(false);
+ if (!index.isChangelog()) {
+ index.setReportedRowCount(indexRowCount,
indexReported);
+ } else if (anyTabletReported || indexReported) {
+
index.setChangelogReportedRowCount(indexRowCount, indexReported,
+ tablets.isEmpty() ? -1 :
indexReportVersion, maxReportVersion);
}
} // end for indices
if (maxPartitionSize.second <= partitionDataSize) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
index d0d6a63d37d..0482cf91fc9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
@@ -19,23 +19,22 @@ package org.apache.doris.catalog;
import org.apache.doris.persist.gson.GsonPostProcessable;
-import com.google.common.collect.Range;
-import com.google.common.collect.RangeSet;
-import com.google.common.collect.TreeRangeSet;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* The OlapTraditional table is a materialized table which stored as
rowcolumnar file or columnar file
*/
public class MaterializedIndex extends MetaObject implements
GsonPostProcessable {
- private static final int MAX_CHANGELOG_ROW_COUNT_RANGES = 1_024;
+ private static final int MAX_CHANGELOG_ROW_COUNT_VERSIONS = 128;
public enum IndexState {
NORMAL,
@@ -89,13 +88,12 @@ public class MaterializedIndex extends MetaObject
implements GsonPostProcessable
private boolean rowCountReported = false;
- // Local estimates need no replay. Consecutive partition versions coalesce
into a single range;
- // a complete periodic report retires the versions it supersedes. Unlike a
last-version check,
- // this also counts distinct commit responses delivered out of order, e.g.
version 4 before 3.
- private transient RangeSet<Long> changelogRowCountVersions;
+ // Track only the versions counted since the last complete periodic report.
+ private transient Set<Long> countedChangelogVersions;
private transient long changelogRowCountReportVersion = -1;
- // A retained count can replace the estimate only when it covers the last
additive update.
- private transient long lastChangelogDeltaVersion = -1;
+ private transient long changelogRowCountMaxReportVersion = -1;
+ private transient long latestChangelogWriteVersion = -1;
+ private transient long changelogWriteVersionAtLastReport = -1;
public MaterializedIndex() {
this.state = IndexState.NORMAL;
@@ -154,9 +152,11 @@ public class MaterializedIndex extends MetaObject
implements GsonPostProcessable
idToTablets = new HashMap<>();
rowCount = -1;
rowCountReported = false;
- changelogRowCountVersions = null;
+ countedChangelogVersions = null;
changelogRowCountReportVersion = -1;
- lastChangelogDeltaVersion = -1;
+ changelogRowCountMaxReportVersion = -1;
+ latestChangelogWriteVersion = -1;
+ changelogWriteVersionAtLastReport = -1;
}
public void addTablet(Tablet tablet, TabletMeta tabletMeta) {
@@ -221,57 +221,67 @@ public class MaterializedIndex extends MetaObject
implements GsonPostProcessable
this.rowCount = rowCount;
}
- /** Caller holds the owning table's write lock, as for periodic
statistics. */
- public void addChangelogRows(long rows) {
- // Empty writes (including a replica-normalized zero) cannot turn
unknown into known zero.
- if (rows > 0) {
- rowCount = Math.max(0, rowCount) + rows;
- }
- }
-
- /** A publish can report multiple tablet deltas for the same partition
version. */
+ /** Under the table write lock, accumulate multiple tablet deltas for the
same publish version. */
public void addChangelogRowsFromPublish(long version, long rows) {
- if (rows > 0 && version > changelogRowCountReportVersion) {
- addChangelogRows(rows);
- lastChangelogDeltaVersion = Math.max(lastChangelogDeltaVersion,
version);
- }
+ recordChangelogDelta(version, rows, false);
}
- /** Apply a visible cloud commit once, without dividing its logical rowset
count by replicas. */
+ /** Under the table write lock, apply each visible Cloud commit once. */
public void addChangelogRows(long version, long rows) {
- if (version <= changelogRowCountReportVersion) {
+ recordChangelogDelta(version, rows, true);
+ }
+
+ private void recordChangelogDelta(long version, long rows, boolean
deduplicate) {
+ // An empty write cannot turn unknown into a known zero.
+ if (rows <= 0) {
+ return;
+ }
+ // Cloud polling must still see newer writes when the estimate is at
capacity.
+ latestChangelogWriteVersion = Math.max(latestChangelogWriteVersion,
version);
+ if (version <= changelogWriteVersionAtLastReport) {
return;
}
- if (changelogRowCountVersions == null) {
- changelogRowCountVersions = TreeRangeSet.create();
+ if (countedChangelogVersions == null) {
+ countedChangelogVersions = new HashSet<>();
+ }
+ if (countedChangelogVersions.size() >= MAX_CHANGELOG_ROW_COUNT_VERSIONS
+ && !countedChangelogVersions.contains(version)) {
+ return;
}
- // At capacity, wait for a complete report to free ranges without
losing deduplication history.
- if (changelogRowCountVersions.asRanges().size() >=
MAX_CHANGELOG_ROW_COUNT_RANGES
- || changelogRowCountVersions.contains(version)) {
+ if (!countedChangelogVersions.add(version) && deduplicate) {
return;
}
- changelogRowCountVersions.add(Range.closedOpen(version, version + 1));
- addChangelogRowsFromPublish(version, rows);
+ rowCount = Math.max(0, rowCount) + rows;
}
- public long getRequiredChangelogReportVersion() {
- return Math.max(changelogRowCountReportVersion,
lastChangelogDeltaVersion);
+ long getChangelogStatsRefreshVersion() {
+ return Math.max(changelogRowCountReportVersion,
latestChangelogWriteVersion);
}
- /** Replace retained stock (which can decrease after TTL), preserving
partial-report semantics. */
- public void setReportedRowCount(long rows, boolean reported, long version)
{
- long requiredVersion = getRequiredChangelogReportVersion();
- if (version < requiredVersion || !reported && requiredVersion >= 0) {
- return;
- }
+ long getChangelogRowCountReportVersion() {
+ return changelogRowCountReportVersion;
+ }
+
+ void setReportedRowCount(long rows, boolean reported) {
rowCount = rows;
rowCountReported = reported;
- if (reported && version > changelogRowCountReportVersion) {
- changelogRowCountReportVersion = version;
- if (changelogRowCountVersions != null) {
- changelogRowCountVersions.remove(Range.lessThan(version + 1));
- }
+ }
+
+ /** Replace the estimate with a complete, non-regressing retained row
count. */
+ public void setChangelogReportedRowCount(long rows, boolean reported, long
minVersion, long maxVersion) {
+ if (minVersion < changelogRowCountReportVersion || maxVersion <
changelogRowCountMaxReportVersion
+ || ((!reported || minVersion < 0) &&
getChangelogStatsRefreshVersion() >= 0)) {
+ return;
+ }
+ if (reported && minVersion >= 0) {
+ changelogRowCountReportVersion = minVersion;
+ changelogRowCountMaxReportVersion = maxVersion;
+ // Reported rows may overlap deltas above the reported version.
Start a new estimate
+ // window and suppress retries of versions already seen, even when
the report lags.
+ changelogWriteVersionAtLastReport = Math.max(maxVersion,
latestChangelogWriteVersion);
+ countedChangelogVersions = null;
}
+ setReportedRowCount(rows, reported);
}
public void setRollupIndexInfo(long rollupIndexId, long
rollupFinishedVersion) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
index 1bc2cf1527e..f957000daf5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
@@ -193,7 +193,8 @@ public class TabletStatMgr extends MasterDaemon {
:
partition.getMaterializedIndices(IndexExtState.VISIBLE, true)) {
long indexRowCount = 0L;
long indexReportVersion = Long.MAX_VALUE;
- long requiredReportVersion =
index.getRequiredChangelogReportVersion();
+ long maxReportVersion = -1;
+ long requiredReportVersion =
index.getChangelogRowCountReportVersion();
boolean indexReported = true;
boolean anyTabletReported = false;
List<Tablet> tablets = index.getTablets();
@@ -225,10 +226,14 @@ public class TabletStatMgr extends MasterDaemon {
? report.rows() :
replica.getRowCount();
// An unreported changelog replica still
has the default zero. Choosing it
// over a reported replica would erase a
useful positive estimate.
+ boolean selectReplica = index.isChangelog()
+ ? replicaReported && reportVersion
>= requiredReportVersion
+ && (!tabletReported ||
reportVersion > tabletReportVersion
+ || reportVersion
== tabletReportVersion
+ &&
replicaRows < tabletRowCount)
+ : replicaRows < tabletRowCount;
if (replica.checkVersionCatchUp(version,
false)
- && (!index.isChangelog()
- || replicaReported &&
reportVersion >= requiredReportVersion)
- && replicaRows >= 0 && replicaRows
< tabletRowCount) {
+ && replicaRows >= 0 &&
selectReplica) {
tabletReported = replicaReported;
tabletRowCount = replicaRows;
tabletReportVersion = reportVersion;
@@ -274,6 +279,7 @@ public class TabletStatMgr extends MasterDaemon {
}
indexRowCount += tabletRowCount;
indexReportVersion =
Math.min(indexReportVersion, tabletReportVersion);
+ maxReportVersion = Math.max(maxReportVersion,
tabletReportVersion);
if (!index.isChangelog()) {
tableRowCount += tabletRowCount;
}
@@ -290,11 +296,11 @@ public class TabletStatMgr extends MasterDaemon {
}
// No report is different from an empty report:
keep immediate changelog
// estimates until at least one tablet has
supplied a valid retained count.
- if (!index.isChangelog() || anyTabletReported ||
indexReported) {
- index.setReportedRowCount(indexRowCount,
indexReported,
- index.isChangelog() &&
!tablets.isEmpty() ? indexReportVersion : -1);
- } else {
- index.setRowCountReported(false);
+ if (!index.isChangelog()) {
+ index.setReportedRowCount(indexRowCount,
indexReported);
+ } else if (anyTabletReported || indexReported) {
+
index.setChangelogReportedRowCount(indexRowCount, indexReported,
+ tablets.isEmpty() ? -1 :
indexReportVersion, maxReportVersion);
}
LOG.debug("Table {} index {} all tablets
reported[{}], row count {}",
olapTable.getName(),
olapTable.getIndexNameById(index.getId()),
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
index 642ef7d2606..166a5579a69 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
@@ -82,17 +82,17 @@ public class MaterializedIndexTest {
@Test
public void testChangelogPartialCountsAndVisibleCommitIdempotence() {
Assertions.assertEquals(-1, index.getRowCount());
- index.addChangelogRows(0);
+ index.addChangelogRows(2, 0);
Assertions.assertEquals(-1, index.getRowCount());
index.addChangelogRows(4, 7);
index.addChangelogRows(3, 5);
index.addChangelogRows(4, 7);
Assertions.assertEquals(12, index.getRowCount());
Assertions.assertFalse(index.getRowCountReported());
- index.setReportedRowCount(2, false, 4);
+ index.setChangelogReportedRowCount(2, false, 4, 4);
index.addChangelogRows(3, 5);
Assertions.assertEquals(12, index.getRowCount());
- index.setReportedRowCount(0, true, 4);
+ index.setChangelogReportedRowCount(0, true, 4, 4);
index.addChangelogRows(3, 5);
Assertions.assertEquals(0, index.getRowCount());
index.addChangelogRows(5, 3);
@@ -110,54 +110,114 @@ public class MaterializedIndexTest {
}
@Test
- public void testStaleReportPreservesVisibleChangelogDelta() {
+ public void
testIncompleteOrRegressingReportPreservesVisibleChangelogDelta() {
index.setIsChangelog(true);
- index.setReportedRowCount(0, true, 3);
+ index.setChangelogReportedRowCount(2, true, 2, 3);
index.addChangelogRows(4, 10);
- index.setReportedRowCount(0, true, 3);
- Assertions.assertEquals(10, index.getRowCount());
- index.setReportedRowCount(0, false, 4);
- Assertions.assertEquals(10, index.getRowCount());
+ index.setChangelogReportedRowCount(0, false, 4, 4);
+ index.setChangelogReportedRowCount(0, true, -1, -1);
+ index.setChangelogReportedRowCount(0, true, 1, 3);
+ index.setChangelogReportedRowCount(0, true, 2, 2);
+ index.addChangelogRows(4, 10);
+ Assertions.assertEquals(12, index.getRowCount());
- index.setReportedRowCount(8, true, 4);
+ index.setChangelogReportedRowCount(1, true, 2, 3);
index.addChangelogRows(4, 10);
- index.setReportedRowCount(0, true, 3);
- Assertions.assertEquals(8, index.getRowCount());
+ Assertions.assertEquals(1, index.getRowCount());
+ Assertions.assertTrue(index.getRowCountReported());
}
@Test
- public void testChangelogRangeLimitPausesUntilCompleteReport() {
- int rangeLimit = 1_024;
- long nextVersion = 2L * rangeLimit + 2;
- for (long version = 2; version < nextVersion; version += 2) {
- index.addChangelogRows(version, 1);
+ public void testLaggingChangelogReportsKeepCalibratingDuringWrites() {
+ for (boolean cloud : new boolean[] {false, true}) {
+ MaterializedIndex changelog = new MaterializedIndex(1L,
IndexState.NORMAL);
+ changelog.setIsChangelog(true);
+ changelog.setChangelogReportedRowCount(100, true, 100, 100);
+ for (long version = 101; version <= 105; version++) {
+ if (cloud) {
+ changelog.addChangelogRows(version, 10);
+ changelog.addChangelogRows(version, 10);
+ } else {
+ changelog.addChangelogRowsFromPublish(version, 6);
+ changelog.addChangelogRowsFromPublish(version, 4);
+ }
+ Assertions.assertEquals(110L, changelog.getRowCount(),
"cloud=" + cloud + ", version=" + version);
+ changelog.setChangelogReportedRowCount(100, true, version - 1,
version - 1);
+ Assertions.assertEquals(100L, changelog.getRowCount(),
"cloud=" + cloud + ", version=" + version);
+ }
}
- Assertions.assertEquals(rangeLimit, index.getRowCount());
-
- index.addChangelogRows(3, 10);
- index.addChangelogRows(nextVersion, 10);
- Assertions.assertEquals(rangeLimit, index.getRowCount());
-
- index.setReportedRowCount(rangeLimit, false, nextVersion);
- index.addChangelogRows(nextVersion, 10);
- Assertions.assertEquals(rangeLimit, index.getRowCount());
-
- index.setReportedRowCount(rangeLimit, true, nextVersion - 2);
- index.addChangelogRows(2, 10);
- index.addChangelogRows(4, 10);
- Assertions.assertEquals(rangeLimit, index.getRowCount());
- index.addChangelogRows(nextVersion, 1);
- Assertions.assertEquals(rangeLimit + 1, index.getRowCount());
- index.addChangelogRows(nextVersion + 2, 10);
- Assertions.assertEquals(rangeLimit + 11, index.getRowCount());
}
@Test
- public void testConsecutiveChangelogVersionsFitInOneRange() {
- for (long version = 2; version <= 1_026; version++) {
+ public void testChangelogDeltaLimitPausesUntilCompleteReport() {
+ for (long version = 2; version <= 128; version++) {
index.addChangelogRows(version, 1);
}
- Assertions.assertEquals(1_025, index.getRowCount());
+ Assertions.assertEquals(127, index.getRowCount());
+ index.addChangelogRows(129, 1);
+ Assertions.assertEquals(128, index.getRowCount());
+ index.addChangelogRows(130, 10);
+ Assertions.assertEquals(128, index.getRowCount());
+ Assertions.assertEquals(130, index.getChangelogStatsRefreshVersion());
+
+ index.setChangelogReportedRowCount(5, false, 129, 129);
+ index.addChangelogRows(131, 1);
+ Assertions.assertEquals(128, index.getRowCount());
+ index.setChangelogReportedRowCount(50, true, 128, 128);
+ Assertions.assertEquals(50, index.getRowCount());
+ Assertions.assertEquals(131, index.getChangelogStatsRefreshVersion());
+
+ // Both the counted write and the write skipped at capacity may be
retried.
+ index.addChangelogRows(129, 1);
+ index.addChangelogRows(130, 10);
+ Assertions.assertEquals(50, index.getRowCount());
+ index.addChangelogRows(133, 3);
+ index.addChangelogRows(132, 2);
+ index.addChangelogRows(133, 3);
+ Assertions.assertEquals(55, index.getRowCount());
+ }
+
+ @Test
+ public void
testConsecutivePublishVersionsAreBoundedAndResumeAfterLaggingReport() {
+ for (long version = 2; version <= 129; version++) {
+ index.addChangelogRowsFromPublish(version, 1);
+ }
+ index.addChangelogRowsFromPublish(129, 4);
+ index.addChangelogRowsFromPublish(130, 10);
+ Assertions.assertEquals(132, index.getRowCount());
+
+ index.setChangelogReportedRowCount(50, true, 128, 128);
+ index.addChangelogRowsFromPublish(129, 4);
+ Assertions.assertEquals(50, index.getRowCount());
+ index.addChangelogRowsFromPublish(131, 1);
+ Assertions.assertEquals(51, index.getRowCount());
+ }
+
+ @Test
+ public void testChangelogReportSupersedesOverlappingPublishDeltas() {
+ // A mixed report already includes part of a subtransaction's
aggregated publish delta.
+ index.addChangelogRowsFromPublish(5, 5);
+ index.setChangelogReportedRowCount(12, true, 3, 4);
+ Assertions.assertEquals(12, index.getRowCount());
+ index.addChangelogRowsFromPublish(5, 5);
+ Assertions.assertEquals(12, index.getRowCount());
+
+ // Shared-nothing tablet rows can include rowsets above the contiguous
report version.
+ index.clearTabletsForRestore();
+ index.addChangelogRowsFromPublish(5, 10);
+ index.addChangelogRowsFromPublish(4, 10);
+ index.setChangelogReportedRowCount(110, true, 3, 3);
+ Assertions.assertEquals(110, index.getRowCount());
+ index.setChangelogReportedRowCount(120, true, 5, 5);
+ Assertions.assertEquals(120, index.getRowCount());
+
+ // Cloud tablet rows can already include a lazy commit above the
sampled partition version.
+ index.clearTabletsForRestore();
+ index.addChangelogRows(4, 10);
+ index.setChangelogReportedRowCount(110, true, 3, 3);
+ Assertions.assertEquals(110, index.getRowCount());
+ index.addChangelogRows(4, 10);
+ Assertions.assertEquals(110, index.getRowCount());
}
@Test
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletStatMgrTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletStatMgrTest.java
index 08ef13ff110..8b190e26b3b 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletStatMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletStatMgrTest.java
@@ -98,11 +98,14 @@ public class TabletStatMgrTest {
defaultReplica.updateVersion(3L);
otherTabletReplica.updateVersion(3L);
changelog.addChangelogRowsFromPublish(3L, 10L);
- manager.runAfterCatalogReady();
Assertions.assertEquals(17L, changelog.getRowCount());
+ manager.runAfterCatalogReady();
+ Assertions.assertEquals(7L, changelog.getRowCount());
reportedReplica.updateRowCountReport(8L, 3L);
manager.runAfterCatalogReady();
- Assertions.assertEquals(17L, changelog.getRowCount());
+ // Select the freshest report for the first tablet. Its version-3
rows already
+ // include part of the publish, so the mixed aggregate cannot add
that delta again.
+ Assertions.assertEquals(12L, changelog.getRowCount());
// A later retained count can decrease after TTL, including a
known empty index.
reportedReplica.updateRowCountReport(0L, 3L);
@@ -111,6 +114,12 @@ public class TabletStatMgrTest {
manager.runAfterCatalogReady();
Assertions.assertEquals(0L, changelog.getRowCount());
Assertions.assertTrue(changelog.getRowCountReported());
+
+ // No replica currently qualifies after the partition version
advances.
+ table.getPartition(30L).setVisibleVersionAndTime(4L, 300L);
+ manager.runAfterCatalogReady();
+ Assertions.assertEquals(0L, changelog.getRowCount());
+ Assertions.assertTrue(changelog.getRowCountReported());
}
}
@@ -169,13 +178,14 @@ public class TabletStatMgrTest {
Assertions.assertTrue(changelog.getRowCountReported());
changelog.addChangelogRows(4L, 10L);
+ Assertions.assertEquals(22L, changelog.getRowCount());
update.invoke(manager, cloudRows(200L, 0L, 3L), false);
update.invoke(manager, cloudRows(300L, 0L, 3L), false);
aggregate.invoke(manager, Collections.singletonList(10L));
- Assertions.assertEquals(22L, changelog.getRowCount());
+ Assertions.assertEquals(0L, changelog.getRowCount());
update.invoke(manager, cloudRows(200L, 0L, 4L), false);
aggregate.invoke(manager, Collections.singletonList(10L));
- Assertions.assertEquals(22L, changelog.getRowCount());
+ Assertions.assertEquals(0L, changelog.getRowCount());
update.invoke(manager, cloudRows(300L, 0L, 4L), false);
aggregate.invoke(manager, Collections.singletonList(10L));
Assertions.assertEquals(0L, changelog.getRowCount());
@@ -218,7 +228,7 @@ public class TabletStatMgrTest {
}
@Test
- public void testCloudModeTwoRevalidatesRestoredRowsBeforePollingBackoff()
throws Exception {
+ public void
testCloudModeTwoBypassesPollingBackoffForRestoredRowsAndNewWrites() throws
Exception {
InternalCatalog catalog = new InternalCatalog();
MaterializedIndex changelog = createTable(catalog);
OlapTable table = (OlapTable)
catalog.getDbNullable(10L).getTableNullable(20L);
@@ -272,6 +282,8 @@ public class TabletStatMgrTest {
.addAllTabletStats(cloudRows(200L,
13L).getTabletStatsList()).build(), false);
} else if (requests.size() == 3) {
update.invoke(manager, cloudRows(200L, 18L, 3L), false);
+ } else if (requests.size() == 4) {
+ update.invoke(manager, cloudRows(200L, 200L, 132L), false);
}
return CompletableFuture.completedFuture(null);
}).when(manager).submitGetTabletStatsTask(Mockito.any(),
Mockito.anyBoolean());
@@ -302,6 +314,21 @@ public class TabletStatMgrTest {
Assertions.assertEquals(List.of(200L),
requests.get(2).getTabletIdsWithRowCountVersionList());
Assertions.assertEquals(18L, changelog.getRowCount());
Assertions.assertTrue(changelog.getRowCountReported());
+
+ for (long version = 4; version <= 131; version++) {
+ changelog.addChangelogRows(version, 1L);
+ }
+ // The replica has a sample through the last counted write, but
the FE has
+ // not aggregated that sample. The skipped write still needs a
fresh sample.
+ restoredChangelog.updateRowCountReport(146L, 131L);
+ restoredChangelog.setStatsIntervalIndex(8);
+ changelog.addChangelogRows(132L, 1L);
+ Assertions.assertEquals(146L, changelog.getRowCount());
+ manager.runAfterCatalogReady();
+ Assertions.assertEquals(4, requests.size());
+ Assertions.assertEquals(1, requests.get(3).getTabletIdxCount());
+ Assertions.assertEquals(List.of(200L),
requests.get(3).getTabletIdsWithRowCountVersionList());
+ Assertions.assertEquals(200L, changelog.getRowCount());
} finally {
Config.cloud_get_tablet_stats_version = oldStatsVersion;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgrTest.java
b/fe/fe-core/src/test/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgrTest.java
index 5c3b2fc9372..ad334b83cfe 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgrTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgrTest.java
@@ -1058,7 +1058,7 @@ public class CloudGlobalTransactionMgrTest {
((CloudGlobalTransactionMgr)
masterTransMgr).updateChangelogRowCounts(response.toBuilder()
.clearChangelogStats().addChangelogStats(changelogStats(first,
firstIndex, 4, 2)).build());
Assertions.assertEquals(15, firstIndex.getRowCount());
- firstIndex.setReportedRowCount(1, true, 5);
+ firstIndex.setChangelogReportedRowCount(1, true, 5, 5);
masterTransMgr.afterCommitTxnResp(response, null, List.of());
Assertions.assertEquals(1, firstIndex.getRowCount());
// The changelog path never creates base-table analysis statistics.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]