Jackie-Jiang commented on code in PR #12976:
URL: https://github.com/apache/pinot/pull/12976#discussion_r1609034975


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/BasePartitionUpsertMetadataManager.java:
##########
@@ -1058,11 +1154,37 @@ protected void removeDocId(IndexSegment segment, int 
docId) {
    * Use the segmentContexts to collect the contexts for selected segments. 
Reuse the segmentContext object if
    * present, to avoid overwriting the contexts specified at the others places.
    */
-  public void setSegmentContexts(List<SegmentContext> segmentContexts) {
+  public void setSegmentContexts(List<SegmentContext> segmentContexts, 
Map<String, String> queryOptions) {
+    if (_consistencyMode == UpsertConfig.ConsistencyMode.NONE) {
+      setSegmentContexts(segmentContexts);
+      return;
+    }
+    if (_consistencyMode == UpsertConfig.ConsistencyMode.SYNC) {
+      _upsertViewLock.readLock().lock();
+      try {
+        setSegmentContexts(segmentContexts);
+        return;
+      } finally {
+        _upsertViewLock.readLock().unlock();
+      }
+    }
+    // If batch refresh is enabled, the copy of bitmaps is kept updated and 
ready to use for a consistent view.
+    // The locking between query threads and upsert threads can be avoided 
when using batch refresh.
+    // Besides, queries can share the copy of bitmaps, w/o cloning the bitmaps 
by every single query.
+    // If query has specified a need for certain freshness, check the view and 
refresh it as needed.
+    // When refreshing the copy of map, we need to take the WLock so only one 
thread is refreshing view.
+    long upsertViewFreshnessMs =
+        Math.min(QueryOptionsUtils.getUpsertViewFreshnessMs(queryOptions), 
_upsertViewRefreshIntervalMs);
+    if (upsertViewFreshnessMs == -1) {

Review Comment:
   More robust
   ```suggestion
       if (upsertViewFreshnessMs < 0) {
   ```



-- 
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-unsubscr...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to