You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@amoro.apache.org by "guilherme-dsantos (via GitHub)" <gi...@apache.org> on 2024/10/22 14:40:12 UTC

[PR] [AMORO-3286] Fix ConcurrentModificationException in TableRuntime.getQuotaTime() [amoro]

guilherme-dsantos opened a new pull request, #3292:
URL: https://github.com/apache/amoro/pull/3292

   Fix/Resolve #3286
   
   **Changes made:**
   - Added synchronization block in TableRuntime.getQuotaTime() to prevent ConcurrentModificationException
   - The fix synchronizes both removeIf and stream operations to ensure thread safety
   
   **Technical details:**
   - Location: org.apache.amoro.server.table.TableRuntime
   - Method modified: getQuotaTime()
   - Added synchronized block around list operations to prevent concurrent modification
   
   **Testing:**
   - While the original error couldn't be reproduced, the fix ensures thread safety for concurrent access to taskQuotas list
   
   **Code changes:**
   ```java
   public long getQuotaTime() {
       long calculatingEndTime = System.currentTimeMillis();
       long calculatingStartTime = calculatingEndTime - AmoroServiceConstants.QUOTA_LOOK_BACK_TIME;
       long finishedTaskQuotaTime;
       synchronized (taskQuotas) {
           taskQuotas.removeIf(task -> task.checkExpired(calculatingStartTime));
           finishedTaskQuotaTime = taskQuotas.stream()
                   .mapToLong(taskQuota -> taskQuota.getQuotaTime(calculatingStartTime))
                   .sum();
       }
       return optimizingProcess == null
               ? finishedTaskQuotaTime
               : finishedTaskQuotaTime
               + optimizingProcess.getRunningQuotaTime(calculatingStartTime, calculatingEndTime);
   }
   


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3286] Fix ConcurrentModificationException in TableRuntime.getQuotaTime() [amoro]

Posted by "zhongqishang (via GitHub)" <gi...@apache.org>.
zhongqishang commented on code in PR #3292:
URL: https://github.com/apache/amoro/pull/3292#discussion_r1811910801


##########
.idea/icon.svg:
##########


Review Comment:
   We should not need to delete this file.



##########
.idea/vcs.xml:
##########


Review Comment:
   We should not need to delete this file.



##########
amoro-ams/src/main/java/org/apache/amoro/server/table/TableRuntime.java:
##########
@@ -611,11 +611,14 @@ public String toString() {
   public long getQuotaTime() {
     long calculatingEndTime = System.currentTimeMillis();
     long calculatingStartTime = calculatingEndTime - AmoroServiceConstants.QUOTA_LOOK_BACK_TIME;
-    taskQuotas.removeIf(task -> task.checkExpired(calculatingStartTime));
-    long finishedTaskQuotaTime =
-        taskQuotas.stream()
-            .mapToLong(taskQuota -> taskQuota.getQuotaTime(calculatingStartTime))
-            .sum();
+    long finishedTaskQuotaTime;
+    synchronized (taskQuotas) {

Review Comment:
   Can we use a concurrency-safe type instead? like `CopyOnWriteArrayList`?



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3286] Fix ConcurrentModificationException in TableRuntime.getQuotaTime() [amoro]

Posted by "zhongqishang (via GitHub)" <gi...@apache.org>.
zhongqishang merged PR #3292:
URL: https://github.com/apache/amoro/pull/3292


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3286] Fix ConcurrentModificationException in TableRuntime.getQuotaTime() [amoro]

Posted by "guilherme-dsantos (via GitHub)" <gi...@apache.org>.
guilherme-dsantos commented on code in PR #3292:
URL: https://github.com/apache/amoro/pull/3292#discussion_r1812651347


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/TableRuntime.java:
##########
@@ -611,11 +611,14 @@ public String toString() {
   public long getQuotaTime() {
     long calculatingEndTime = System.currentTimeMillis();
     long calculatingStartTime = calculatingEndTime - AmoroServiceConstants.QUOTA_LOOK_BACK_TIME;
-    taskQuotas.removeIf(task -> task.checkExpired(calculatingStartTime));
-    long finishedTaskQuotaTime =
-        taskQuotas.stream()
-            .mapToLong(taskQuota -> taskQuota.getQuotaTime(calculatingStartTime))
-            .sum();
+    long finishedTaskQuotaTime;
+    synchronized (taskQuotas) {

Review Comment:
   Thank you for the opportunity. I've updated the code to use CopyOnWriteArrayList.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org