klsince commented on code in PR #13107: URL: https://github.com/apache/pinot/pull/13107#discussion_r1626373676
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/ConcurrentMapPartitionUpsertMetadataManager.java: ########## @@ -158,6 +158,49 @@ protected void addOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutab } } + /** + * <li> When the replacing segment and current segment are of {@link LLCSegmentName} then the PK should resolve to + * row in segment with higher sequence id. + * <li> When the replacing segment and current segment are of {@link UploadedRealtimeSegmentName} then the PK + * should resolve to row in segment with higher creation time followed by sequence id. + * <li> For other cases resolve based on creation time of segment. In case the creation time is same, give + * preference to an uplaoded segment. A segment which is not LLCSegment can be assumed to be uploaded segment and Review Comment: typo: uplaoded ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/ConcurrentMapPartitionUpsertMetadataManager.java: ########## @@ -158,6 +158,49 @@ protected void addOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutab } } + /** + * <li> When the replacing segment and current segment are of {@link LLCSegmentName} then the PK should resolve to + * row in segment with higher sequence id. + * <li> When the replacing segment and current segment are of {@link UploadedRealtimeSegmentName} then the PK + * should resolve to row in segment with higher creation time followed by sequence id. + * <li> For other cases resolve based on creation time of segment. In case the creation time is same, give + * preference to an uplaoded segment. A segment which is not LLCSegment can be assumed to be uploaded segment and + * is given preference. + * + * @param segmentName replacing segment name + * @param currentSegmentName current segment name having the record for the given primary key + * @param segmentCreationTimeMs replacing segment creation time + * @param currentSegmentCreationTimeMs current segment creation time + * @return true if the record in replacing segment should replace the record in current segment + */ + private boolean shouldReplaceOnComparisonTie(String segmentName, String currentSegmentName, + long segmentCreationTimeMs, long currentSegmentCreationTimeMs) { + + LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName); + LLCSegmentName currentLLCSegmentName = LLCSegmentName.of(currentSegmentName); + if (llcSegmentName != null && currentLLCSegmentName != null) { + return llcSegmentName.getSequenceNumber() > currentLLCSegmentName.getSequenceNumber(); + } + + int creationTimeComparisonRes = Long.compare(segmentCreationTimeMs, currentSegmentCreationTimeMs); + + UploadedRealtimeSegmentName uploadedSegmentName = UploadedRealtimeSegmentName.of(segmentName); + UploadedRealtimeSegmentName currentUploadedSegmentName = UploadedRealtimeSegmentName.of(currentSegmentName); + if (uploadedSegmentName != null && currentUploadedSegmentName != null) { + if (creationTimeComparisonRes == 0) { + return uploadedSegmentName.getSequenceId() > currentUploadedSegmentName.getSequenceId(); + } else { + return creationTimeComparisonRes > 0; + } + } + + if (creationTimeComparisonRes == 0) { + return llcSegmentName == null || uploadedSegmentName != null; Review Comment: nit: comment that `uploadedSegmentName != null` is to favor the segment with formatted name ########## pinot-common/src/main/java/org/apache/pinot/common/utils/UploadedRealtimeSegmentName.java: ########## @@ -0,0 +1,199 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.common.utils; + +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.Objects; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + + +/** + * Class to represent segment names like: uploaded__{tableName}__{partitionId}__{sequenceId}__{creationTime}__{ + * optionalSuffix} + * + * <p>This naming convention is adopted to represent a segment uploaded to a realtime table. The naming + * convention has been kept similar to {@LLCSegmentName} to but differentiates between stream generated LLCSegments + * based on the prefix "uploaded" and an optional suffix. + */ +public class UploadedRealtimeSegmentName implements Comparable<UploadedRealtimeSegmentName> { Review Comment: typo: s/uplaoded/uploaded -- 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