Copilot commented on code in PR #62084:
URL: https://github.com/apache/doris/pull/62084#discussion_r3031342636


##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -594,6 +583,22 @@ public long getIdx() {
         return idx;
     }
 
+    public long getLastGetTabletStatsTime() {
+        return packedStatsState & TIMESTAMP_MASK;
+    }
+
+    public void setLastGetTabletStatsTime(long time) {

Review Comment:
   setLastGetTabletStatsTime() silently truncates the provided time to 60 bits 
via masking. If a caller ever passes a negative value or a value beyond the 
supported range, this will wrap into a large positive timestamp and can delay 
stats refresh unexpectedly. Consider validating `time >= 0` (and optionally 
`time <= TIMESTAMP_MASK`) and either clamping to 0 / max or throwing an 
IllegalArgumentException to make misuse fail fast.
   ```suggestion
       public void setLastGetTabletStatsTime(long time) {
           if (time < 0 || time > TIMESTAMP_MASK) {
               throw new IllegalArgumentException(
                       "time must be between 0 and " + TIMESTAMP_MASK + ": " + 
time);
           }
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -594,6 +583,22 @@ public long getIdx() {
         return idx;
     }
 
+    public long getLastGetTabletStatsTime() {
+        return packedStatsState & TIMESTAMP_MASK;
+    }
+
+    public void setLastGetTabletStatsTime(long time) {
+        packedStatsState = (packedStatsState & INTERVAL_MASK) | (time & 
TIMESTAMP_MASK);
+    }
+
+    public int getStatsIntervalIndex() {
+        return (int) (packedStatsState >>> INTERVAL_SHIFT);
+    }
+
+    public void setStatsIntervalIndex(int index) {
+        packedStatsState = ((long) index << INTERVAL_SHIFT) | 
(packedStatsState & TIMESTAMP_MASK);

Review Comment:
   The new packedStatsState bit-packing is subtle and easy to regress (e.g., 
setting the timestamp accidentally affecting the interval bits). Please add a 
small unit test that verifies (1) setting time preserves interval, (2) setting 
interval preserves time, and (3) out-of-range inputs are handled as intended 
(mask/clamp/exception).
   ```suggestion
           packedStatsState = ((((long) index) << INTERVAL_SHIFT) & 
INTERVAL_MASK)
                   | (packedStatsState & TIMESTAMP_MASK);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -594,6 +583,22 @@ public long getIdx() {
         return idx;
     }
 
+    public long getLastGetTabletStatsTime() {
+        return packedStatsState & TIMESTAMP_MASK;
+    }
+
+    public void setLastGetTabletStatsTime(long time) {
+        packedStatsState = (packedStatsState & INTERVAL_MASK) | (time & 
TIMESTAMP_MASK);
+    }
+
+    public int getStatsIntervalIndex() {
+        return (int) (packedStatsState >>> INTERVAL_SHIFT);
+    }
+
+    public void setStatsIntervalIndex(int index) {
+        packedStatsState = ((long) index << INTERVAL_SHIFT) | 
(packedStatsState & TIMESTAMP_MASK);
+    }

Review Comment:
   setStatsIntervalIndex() currently shifts `index` into the top 4 bits without 
any explicit range checking/masking. Values outside the expected range 
(0..DEFAULT_INTERVAL_LADDER_MS.length-1) will silently wrap/truncate and can 
end up as 15, which CloudTabletStatMgr treats as out-of-range and effectively 
clamps to the last (infinite) interval. Consider explicitly masking to 0xF and 
validating/clamping to the supported ladder range to avoid hard-to-debug 
refresh stalls if a bad value is ever passed.



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -69,22 +67,13 @@ public class CloudReplica extends Replica implements 
GsonPostProcessable {
     private long indexId = -1;
     @SerializedName(value = "idx")
     private long idx = -1;
-    // last time to get tablet stats
-    @Getter
-    @Setter
-    @SerializedName(value = "gst")
-    long lastGetTabletStatsTime = 0;
-    /**
-     * The index of {@link 
org.apache.doris.catalog.CloudTabletStatMgr#DEFAULT_INTERVAL_LADDER_MS} array.
-     * Used to control the interval of getting tablet stats.
-     * When get tablet stats:
-     * if the stats is unchanged, will update this index to next value to get 
stats less frequently;
-     * if the stats is changed, will update this index to 0 to get stats more 
frequently.
-     */
-    @Getter
-    @Setter
-    @SerializedName(value = "sii")
-    int statsIntervalIndex = 0;
+    // Packed: bottom 60 bits = lastGetTabletStatsTime, top 4 bits = 
statsIntervalIndex.
+    // Transient: stats timing state resets to 0 on restart, which is 
acceptable since
+    // runAfterCatalogReady() handles the empty-stats case with a full refresh.

Review Comment:
   The rationale comment for the transient packed stats state references 
`runAfterCatalogReady()` handling the "empty-stats" case, but the interval 
ladder filter will also treat `lastGetTabletStatsTime==0` as "needs refresh" 
even when table stats are present. Consider rewording to describe the actual 
behavior (restart resets timing so a full/near-full refresh may occur on the 
next stat cycle) to avoid misleading future readers.
   ```suggestion
       // Transient: stats timing state resets to 0 on restart, which is 
acceptable because
       // the next stats cycle treats that timing as needing refresh and may 
trigger a
       // full or near-full refresh.
   ```



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