zhtaoxiang commented on code in PR #13636:
URL: https://github.com/apache/pinot/pull/13636#discussion_r1717587046


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/BasePartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,212 @@
+/**
+ * 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.base.Preconditions;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.common.metrics.ServerTimer;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public abstract class BasePartitionDedupMetadataManager implements 
PartitionDedupMetadataManager {
+  protected final String _tableNameWithType;
+  protected final List<String> _primaryKeyColumns;
+  protected final int _partitionId;
+  protected final ServerMetrics _serverMetrics;
+  protected final HashFunction _hashFunction;
+  protected final double _metadataTTL;
+  protected final String _dedupTimeColumn;
+  protected final Logger _logger;
+
+  // The following variables are always accessed within synchronized block
+  private boolean _stopped;
+  // Initialize with 1 pending operation to indicate the metadata manager can 
take more operations
+  private int _numPendingOperations = 1;
+  private boolean _closed;
+
+  protected BasePartitionDedupMetadataManager(String tableNameWithType, int 
partitionId,
+      DedupContext dedupContext) {
+    _tableNameWithType = tableNameWithType;
+    _partitionId = partitionId;
+    _primaryKeyColumns = dedupContext.getPrimaryKeyColumns();
+    _hashFunction = dedupContext.getHashFunction();
+    _serverMetrics = dedupContext.getServerMetrics();
+    _metadataTTL = dedupContext.getMetadataTTL() >= 0 ? 
dedupContext.getMetadataTTL() : 0;
+    _dedupTimeColumn = dedupContext.getDedupTimeColumn();
+    if (_metadataTTL > 0) {
+      Preconditions.checkArgument(_dedupTimeColumn != null,
+          "When metadataTTL is configured, metadata time column must be 
configured for dedup enabled table: %s",
+          tableNameWithType);
+    }
+    _logger = LoggerFactory.getLogger(tableNameWithType + "-" + partitionId + 
"-" + getClass().getSimpleName());
+  }
+
+  @Override
+  public boolean checkRecordPresentOrUpdate(PrimaryKey pk, IndexSegment 
indexSegment) {
+    throw new 
UnsupportedOperationException("checkRecordPresentOrUpdate(PrimaryKey pk, 
IndexSegment indexSegment) is "
+        + "deprecated!");
+  }
+
+  @Override
+  public void addSegment(IndexSegment segment) {
+    if (!startOperation()) {
+      _logger.info("Skip adding segment: {} because metadata manager is 
already stopped", segment.getSegmentName());
+      return;
+    }
+    try (DedupUtils.DedupRecordInfoReader dedupRecordInfoReader = new 
DedupUtils.DedupRecordInfoReader(segment,
+        _primaryKeyColumns, _dedupTimeColumn)) {
+      Iterator<DedupRecordInfo> dedupRecordInfoIterator =
+          DedupUtils.getDedupRecordInfoIterator(dedupRecordInfoReader, 
segment.getSegmentMetadata().getTotalDocs());
+      doAddSegment(segment, dedupRecordInfoIterator);
+      removeExpiredPrimaryKeys();

Review Comment:
   Thanks for the suggestion! I will remove this call to 
`removeExpiredPrimaryKeys()` to make the behavior consistent.



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