github-actions[bot] commented on code in PR #70892:
URL: https://github.com/apache/doris/pull/70892#discussion_r4665743842


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java:
##########
@@ -221,57 +220,72 @@ public void setRowCount(long rowCount) {
         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.
+    /** Under the table write lock, accumulate multiple tablet deltas for the 
same publish version. */
+    public void addChangelogRowsFromPublish(long version, long rows) {
         if (rows > 0) {
-            rowCount = Math.max(0, rowCount) + rows;
+            recordChangelogDelta(version, rows, false);
         }
     }
 
-    /** A publish can report multiple tablet deltas for the same partition 
version. */
-    public void addChangelogRowsFromPublish(long version, long rows) {
-        if (rows > 0 && version > changelogRowCountReportVersion) {
-            addChangelogRows(rows);
-            lastChangelogDeltaVersion = Math.max(lastChangelogDeltaVersion, 
version);
-        }
+    /** Under the table write lock, apply each visible Cloud commit once. */
+    public void addChangelogRows(long version, long rows) {
+        recordChangelogDelta(version, Math.max(0, rows), true);
     }
 
-    /** Apply a visible cloud commit once, without dividing its logical rowset 
count by replicas. */
-    public void addChangelogRows(long version, long rows) {
-        if (version <= changelogRowCountReportVersion) {
+    private void recordChangelogDelta(long version, long rows, boolean 
deduplicate) {
+        if (version <= changelogRowCountMaxReportVersion) {
             return;
         }
-        if (changelogRowCountVersions == null) {
-            changelogRowCountVersions = TreeRangeSet.create();
+        if (changelogRowCountDeltas == null) {
+            changelogRowCountDeltas = new TreeMap<>();
         }
-        // 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)) {
+        Long previous = changelogRowCountDeltas.get(version);
+        // Bound the history of unapplied reports. At capacity, periodic 
counts still include writes
+        // whose deltas were skipped here.
+        if (previous == null && changelogRowCountDeltas.size() >= 
MAX_CHANGELOG_ROW_COUNT_DELTAS

Review Comment:
   [P2] Preserve skipped deltas when the bounded history is full. Both 
`addChangelogRowsFromPublish` and Cloud `addChangelogRows` now hit this guard, 
so after 1,024 consecutive versions the next visible delta is omitted from 
`rowCount` and `lastChangelogDeltaVersion`. If the next complete tablet report 
stops at the last retained version, `setChangelogReportedRowCount` clears the 
map and marks the index reported; the omitted version has no watermark and can 
remain absent from the stream estimate until a later report reaches it. Keep a 
pending/refresh marker for skipped versions or coalesce adjacent versions so a 
report cannot retire the need to refresh past an unaccounted write.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to