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


##########
fs_brokers/cdc_client/src/main/java/org/apache/doris/cdcclient/source/reader/mysql/MySqlBinlogLagCalculator.java:
##########
@@ -0,0 +1,77 @@
+// 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.doris.cdcclient.source.reader.mysql;
+
+import java.util.List;
+import java.util.Map;
+
+final class MySqlBinlogLagCalculator {
+    private static final String FILE_KEY = "file";
+    private static final String POSITION_KEY = "pos";
+
+    private MySqlBinlogLagCalculator() {}
+
+    static long calculate(
+            Map<String, String> referenceOffset,
+            Map<String, String> endOffset,
+            List<BinlogFile> binlogFiles) {
+        if (referenceOffset == null || endOffset == null || binlogFiles == 
null) {
+            return -1;
+        }
+        String referenceFile = referenceOffset.get(FILE_KEY);
+        String endFile = endOffset.get(FILE_KEY);
+        String referencePositionValue = referenceOffset.get(POSITION_KEY);
+        if (referenceFile == null || referencePositionValue == null) {
+            // GTID-only startup offsets have no byte position until the 
reader advances.
+            return -1;
+        }
+        long referencePosition = Long.parseLong(referencePositionValue);
+        long endPosition = Long.parseLong(endOffset.get(POSITION_KEY));
+        int referenceIndex = indexOf(binlogFiles, referenceFile);

Review Comment:
   `endOffset.get("pos")` is parsed without a null check. If the end offset map 
lacks the `pos` key (or `file`/`pos` are temporarily unavailable), this will 
throw a NullPointerException and convert a missing observation into an 
unexpected failure rather than returning the documented `-1` (unavailable).



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