saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r882509967


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,130 @@
+/**
+ * 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.dedup;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+import org.apache.pinot.segment.local.upsert.PartitionUpsertMetadataManager;
+import org.apache.pinot.segment.local.utils.HashUtils;
+import org.apache.pinot.segment.local.utils.RecordInfo;
+import org.apache.pinot.segment.local.utils.tablestate.TableState;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.spi.config.table.HashFunction;
+import org.apache.pinot.spi.data.readers.PrimaryKey;
+import org.apache.pinot.spi.utils.ByteArray;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PartitionDedupMetadataManager {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PartitionUpsertMetadataManager.class);
+
+  private final String _tableNameWithType;
+  private final TableState _tableState;
+  private final List<String> _primaryKeyColumns;
+  private final int _partitionId;
+  private final ServerMetrics _serverMetrics;
+  private final HashFunction _hashFunction;
+
+  // TODO(saurabh) : We can replace this with a ocncurrent Set
+  @VisibleForTesting
+  final ConcurrentHashMap<Object, Boolean> _primaryKeySet = new 
ConcurrentHashMap<>();
+
+  public PartitionDedupMetadataManager(String tableNameWithType, TableState 
tableState, List<String> primaryKeyColumns,
+      int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) 
{
+    _tableNameWithType = tableNameWithType;
+    _tableState = tableState;
+    _primaryKeyColumns = primaryKeyColumns;
+    _partitionId = partitionId;
+    _serverMetrics = serverMetrics;
+    _hashFunction = hashFunction;
+  }
+
+  public void addSegment(IndexSegment segment) {
+    // Add all PKs to _primaryKeySet
+    Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment);
+    while (recordInfoIterator.hasNext()) {
+      RecordInfo recordInfo = recordInfoIterator.next();
+      _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), 
_hashFunction), true);
+    }
+  }
+
+  public void removeSegment(IndexSegment segment) {

Review Comment:
   Ack. I've handled this scenario by making the SegmentDataManager aware when 
it's been replaced, and eventually when the underlying segment gets destroyed, 
the flag helps in deciding whether or not its keys should be removed from 
dedupMeta. Do have a look. Will discuss more over slack.



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