abhishekagarwal87 commented on a change in pull request #11398:
URL: https://github.com/apache/druid/pull/11398#discussion_r674498267
##########
File path:
server/src/main/java/org/apache/druid/segment/loading/SegmentCacheManager.java
##########
@@ -40,6 +40,34 @@
*/
File getSegmentFiles(DataSegment segment) throws SegmentLoadingException;
+ /**
+ * Tries to reserve the space for a segment on any location. When the space
has been reserved,
+ * {@link #getSegmentFiles(DataSegment)} should download the segment on the
reserved location or
+ * fail otherwise.
+ *
+ * This function is useful for custom extensions. Extensions can try to
reserve the space first and
+ * if not successful, make some space by cleaning up other segments, etc.
There is also improved
+ * concurrency for extensions with this function. Since reserve is a cheaper
operation to invoke
+ * till the space has been reserved. Hence it can be put inside a lock if
required by the extensions. getSegment
+ * can't be put inside a lock since it is a time-consuming operation, on
account of downloading the files.
+ *
+ * @param segment - Segment to reserve
+ * @return True if enough space found to store the segment, false otherwise
+ */
+ /*
+ * We only return a boolean result instead of a pointer to
+ * {@link StorageLocation} since we don't want callers to operate on {@code
StorageLocation} directly outside {@code SegmentLoader}.
+ * {@link SegmentLoader} operates on the {@code StorageLocation} objects in
a thread-safe manner.
+ */
+ boolean reserve(DataSegment segment);
+
+ /**
+ * Reverts the effects of {@link #reserve(DataSegment)} (DataSegment)} by
releasing the location reserved for this segment.
+ * @param segment - Segment to release the location for.
+ * @return - True if any location was reserved and released, false otherwise.
+ */
+ boolean release(DataSegment segment);
Review comment:
Sure. if `reserve` is not called, `getSegmentFiles` will `reserve` the
space. I will document this.
--
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]