rohityadav1993 commented on code in PR #17789:
URL: https://github.com/apache/pinot/pull/17789#discussion_r2885601440


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/OfflineTableDataManager.java:
##########
@@ -57,8 +101,122 @@ protected void doAddOnlineSegment(String segmentName)
     }
   }
 
+  @Override
+  public void addSegment(ImmutableSegment immutableSegment, @Nullable 
SegmentZKMetadata zkMetadata) {
+    String segmentName = immutableSegment.getSegmentName();
+    Preconditions.checkState(!_shutDown,
+        "Table data manager is already shut down, cannot add segment: %s to 
table: %s",
+        segmentName, _tableNameWithType);
+    if (isUpsertEnabled()) {
+      handleUpsert(immutableSegment, zkMetadata);
+      return;
+    }
+    super.addSegment(immutableSegment, zkMetadata);
+  }
+
+  @Override
+  public List<SegmentContext> getSegmentContexts(List<IndexSegment> 
selectedSegments,
+      Map<String, String> queryOptions) {
+    List<SegmentContext> segmentContexts = new 
ArrayList<>(selectedSegments.size());
+    selectedSegments.forEach(s -> segmentContexts.add(new SegmentContext(s)));
+    if (isUpsertEnabled() && !QueryOptionsUtils.isSkipUpsert(queryOptions)) {
+      _tableUpsertMetadataManager.setSegmentContexts(segmentContexts, 
queryOptions);
+    }
+    return segmentContexts;
+  }
+
   @Override
   public void addConsumingSegment(String segmentName) {
     throw new UnsupportedOperationException("Cannot add CONSUMING segment to 
OFFLINE table");
   }
+
+  public boolean isUpsertEnabled() {
+    return _tableUpsertMetadataManager != null;
+  }
+
+  @VisibleForTesting
+  public TableUpsertMetadataManager getTableUpsertMetadataManager() {
+    return _tableUpsertMetadataManager;
+  }
+
+  public Map<Integer, Long> getPartitionToPrimaryKeyCount() {
+    if (isUpsertEnabled()) {
+      return _tableUpsertMetadataManager.getPartitionToPrimaryKeyCount();
+    }
+    return Collections.emptyMap();
+  }
+
+  private void handleUpsert(ImmutableSegment immutableSegment, @Nullable 
SegmentZKMetadata zkMetadata) {
+    String segmentName = immutableSegment.getSegmentName();
+    _logger.info("Adding immutable segment: {} with upsert enabled", 
segmentName);
+
+    // Set the ZK creation time so that same creation time can be used to 
break the comparison ties across replicas,
+    // to ensure data consistency of replica.
+    setZkCreationTimeIfAvailable(immutableSegment, zkMetadata);
+
+    Integer partitionId = SegmentUtils.getSegmentPartitionId(segmentName, 
_tableNameWithType, _helixManager, null);

Review Comment:
   This util only works for LLCSegmentName or UploadedRealtimeSegmentName. 
There can be a check much earlier in the add segment flow to not allow segments 
for which partitionId cannot be derived.



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