Copilot commented on code in PR #468:
URL: https://github.com/apache/atlas/pull/468#discussion_r2423372135


##########
repository/src/main/java/org/apache/atlas/util/AtlasMetricsUtil.java:
##########
@@ -473,8 +475,13 @@ public long getProcessedMessageCount() {
             return processedMessageCount;
         }
 
-        public void incrProcessedMessageCount() {
+        public void incrProcessedMessageCount(long timeTakenMs) {
             this.processedMessageCount++;
+            this.totalProcessingTimeMs += timeTakenMs;
+        }

Review Comment:
   The increment operations on `processedMessageCount` and 
`totalProcessingTimeMs` are not atomic, which could lead to inconsistent state 
in multi-threaded environments. Consider using atomic operations or 
synchronization to ensure thread safety.



##########
repository/src/main/java/org/apache/atlas/util/AtlasMetricsUtil.java:
##########
@@ -473,8 +475,13 @@ public long getProcessedMessageCount() {
             return processedMessageCount;
         }
 
-        public void incrProcessedMessageCount() {
+        public void incrProcessedMessageCount(long timeTakenMs) {
             this.processedMessageCount++;
+            this.totalProcessingTimeMs += timeTakenMs;
+        }
+
+        public long getAvgProcessingTime() {
+            return processedMessageCount == 0 ? 0 : (totalProcessingTimeMs / 
processedMessageCount);

Review Comment:
   The division operation could be inconsistent if `processedMessageCount` is 
modified between the zero check and the division. Consider using a local 
snapshot of the values or synchronization to ensure consistent reads.
   ```suggestion
               long processedCountSnapshot = this.processedMessageCount;
               long totalTimeSnapshot = this.totalProcessingTimeMs;
               return processedCountSnapshot == 0 ? 0 : (totalTimeSnapshot / 
processedCountSnapshot);
   ```



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

Reply via email to