deepthi912 commented on code in PR #19637: URL: https://github.com/apache/pinot/pull/19637#discussion_r4159664228
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/DocIdsSnapshot.java: ########## @@ -0,0 +1,128 @@ +/** + * 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.segment.local.upsert; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.CRC32; +import javax.annotation.Nullable; +import org.apache.pinot.segment.spi.index.mutable.ThreadSafeMutableRoaringBitmap; +import org.apache.pinot.spi.utils.JsonUtils; +import org.roaringbitmap.IntIterator; +import org.roaringbitmap.buffer.ImmutableRoaringBitmap; +import org.roaringbitmap.buffer.MutableRoaringBitmap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/// A persisted bitmap and its optional capture diagnostics, read from the same file generation. +/// The Roaring bytes remain a prefix readable by existing snapshot readers. A versioned metadata trailer is published +/// with that prefix through the existing temporary-file rename, so a concurrent reader cannot pair different captures. +public record DocIdsSnapshot(MutableRoaringBitmap docIds, @Nullable Metadata metadata) { + private static final Logger LOGGER = LoggerFactory.getLogger(DocIdsSnapshot.class); + private static final int MAGIC = 0x5044534D; // PDSM: Pinot doc ids snapshot metadata + private static final int VERSION = 1; + + /// The consumer startup that triggered a snapshot. consumedUpToOffset is exclusive, the first offset that consumer + /// reads, and is not a partition consistency watermark. + public record Trigger(String consumingSegmentName, String consumedUpToOffset) { + } + + /// Which bitmap a snapshot file holds, so its CRC says what it covers. + public enum DocIdsType { + VALID_DOC_IDS, QUERYABLE_DOC_IDS + } + + // Ignore unknown fields so an older server still reads diagnostics written by a newer one. + @JsonIgnoreProperties(ignoreUnknown = true) + public record Metadata(long docIdsCrc, DocIdsType docIdsType, long snapshotCapturedAtMs, + @Nullable String snapshotConsumingSegmentName, @Nullable String snapshotConsumedUpToOffset) { + public Map<String, Object> toResponse(long nowMs) { + Map<String, Object> response = new HashMap<>(); + response.put("docIdsCrc", docIdsCrc); + response.put("docIdsType", docIdsType.name()); + response.put("snapshotCapturedAtMs", snapshotCapturedAtMs); + // Do not turn clock skew into an apparently fresh snapshot. + if (nowMs >= snapshotCapturedAtMs) { + response.put("snapshotAgeMs", nowMs - snapshotCapturedAtMs); + } + if (snapshotConsumingSegmentName != null && snapshotConsumedUpToOffset != null) { + response.put("snapshotConsumingSegmentName", snapshotConsumingSegmentName); + response.put("snapshotConsumedUpToOffset", snapshotConsumedUpToOffset); Review Comment: The offset gives the same value across all the replicas. Can we somehow capture the actual offset until which each replica consumed as well? Rest of the changes looks good to me! -- 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]
