peterxcli commented on PR #8157:
URL: https://github.com/apache/ozone/pull/8157#issuecomment-2829494108

   > agreed this section is prone to race conditions.
   Semaphore would be a more appropriate solution, but it will be require a 
larger rewrite.
   
   > Agreed, this section is prone to race conditions.  
   A semaphore would be a more appropriate solution, but it would require a 
larger rewrite.
   
   @jojochuang I have refactored that section by putting it into a synchronized 
block. I think it now has the same effect as a `Semaphore`:
   
   ```java
   synchronized (inFlightSnapshotCount) {
     int currentCount = inFlightSnapshotCount.get();
     if (currentSnapshotNum + currentCount >= fsSnapshotMaxLimit) {
       throw new OMException(
           String.format("Snapshot limit of %d reached. Cannot create more 
snapshots. " +
               "Current snapshots: %d, In-flight creations: %d",
               fsSnapshotMaxLimit, currentSnapshotNum, currentCount) +
               " If you have already deleted some snapshots, " +
               "please wait for the background service to complete the 
cleanup.",
           OMException.ResultCodes.TOO_MANY_SNAPSHOTS);
     }
     inFlightSnapshotCount.set(currentCount + 1);
   }
   ```


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