jihoonson opened a new pull request #8114: Fix race between canHandle() and 
addSegment() in StorageLocation
URL: https://github.com/apache/incubator-druid/pull/8114
 
 
   ### Description
   
   Historicals can use multiple threads to load segments in parallel from deep 
storage now (https://github.com/apache/incubator-druid/pull/7088, 
https://github.com/apache/incubator-druid/pull/4966). This could lead an 
incorrect computation of remaining space in `StorageLocation`.
   
   The current pattern to use `StorageLocation` is:
   
   ```java
   if (location.canHandle(segment)) {
     // load segment files into the location
     location.addSegment(segment);
   }
   ```
   
   Even though each of `canHandle()` and `addSegment()` is synchronized, they 
are not atomically executed which could lead a wrong estimation of the 
available space.
   
   This PR fixes this problem to add a new method, `reserve()`, to 
`StorageLocation`. `reserve()` basically does what `canHandle()` and 
`addSegment()` atomically. If some error occurs after `reserve()`, the caller 
should call `remove(segment)` to release the reserved space.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added unit tests or modified existing tests to cover new code paths.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to