You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/05/16 11:26:26 UTC
[GitHub] [pinot] saurabhd336 opened a new pull request, #8708: (WIP) Dedup config
saurabhd336 opened a new pull request, #8708:
URL: https://github.com/apache/pinot/pull/8708
Instructions:
1. The PR has to be tagged with at least one of the following labels (*):
1. `feature`
2. `bugfix`
3. `performance`
4. `ui`
5. `backward-incompat`
6. `release-notes` (**)
2. Remove these instructions before publishing the PR.
(*) Other labels to consider:
- `testing`
- `dependencies`
- `docker`
- `kubernetes`
- `observability`
- `security`
- `code-style`
- `extension-point`
- `refactor`
- `cleanup`
(**) Use `release-notes` label for scenarios like:
- New configuration options
- Deprecation of configurations
- Signature changes to public methods/interfaces
- New plugins added or old plugins removed
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang merged pull request #8708: [Feature] Deduplication
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang merged PR #8708:
URL: https://github.com/apache/pinot/pull/8708
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887555360
##########
pinot-segment-local/src/test/resources/data/test_dedup_data.json:
##########
@@ -0,0 +1,22 @@
+[
+ {
+ "event_id": "aa",
+ "description" : "first",
+ "secondsSinceEpoch": 1567205394
+ },
+ {
+ "event_id": "bb",
+ "description" : "first",
+ "secondsSinceEpoch": 1567205396
+ },
+ {
+ "event_id": "aa",
+ "description" : "second",
+ "secondsSinceEpoch": 1567205397
+ },
+ {
+ "event_id": "bb",
+ "description" : "second",
+ "secondsSinceEpoch": 1567205392
+ }
+]
Review Comment:
Ack
##########
pinot-segment-local/src/test/resources/data/test_dedup_schema.json:
##########
@@ -0,0 +1,21 @@
+{
+ "schemaName": "test_pinot_table",
+ "dimensionFieldSpecs": [
+ {
+ "name": "event_id",
+ "dataType": "STRING"
+ },
+ {
+ "name": "description",
+ "dataType": "STRING"
+ }
+ ],
+ "timeFieldSpec": {
+ "incomingGranularitySpec": {
+ "name": "secondsSinceEpoch",
+ "dataType": "LONG",
+ "timeType": "SECONDS"
+ }
+ },
+ "primaryKeyColumns": ["event_id"]
+}
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r882111038
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
Suggest modeling it as a util class (`TableStateUtils`) and have one static method `public static boolean isAllSegmentsLoaded(HelixManager helixManager, String tableNameWithType)`. The `_allSegmentsLoaded` can still be tracked within the metadata manager. We don't want this util class to track the loaded flag, instead it should always re-calculate the state.
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -538,6 +539,7 @@ private void processStreamEvents(MessageBatch messagesAndOffsets, long idlePipeS
}
for (GenericRow transformedRow : reusedResult.getTransformedRows()) {
try {
+ // TODO(saurabh): we may have dropped the record due to dedup. Should we increment indexedMessageCount?
Review Comment:
IMO it is okay to increase the value since we are just tracking the row count fed into the `index()`. We should use another metrics to track the rows ignored because of the dedup
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -111,7 +116,9 @@ public class RealtimeTableDataManager extends BaseTableDataManager {
private static final int MIN_INTERVAL_BETWEEN_STATS_UPDATES_MINUTES = 30;
private UpsertConfig.Mode _upsertMode;
+ private boolean _isDedupEnabled;
Review Comment:
This flag is redundant, and is implicit on the presence of `_tableDedupMetadataManager`
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/TableConfig.java:
##########
@@ -288,8 +303,8 @@ public void setTierConfigsList(List<TierConfig> tierConfigsList) {
}
@JsonIgnore
- public UpsertConfig.HashFunction getHashFunction() {
- return _upsertConfig == null ? UpsertConfig.HashFunction.NONE : _upsertConfig.getHashFunction();
+ public HashFunction getHashFunction() {
Review Comment:
We should remove this method. The hash function can come from both upsert config and dedup config
##########
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:
(MAJOR) We cannot always remove the PKs for destroyed segment because it can mess up the metadata when a segment is reloaded (we will first add the re-loaded segment, then remove the previous segment). We need to figure out a solution for this.
One solution I can think of is to track the segment reference when `addSegment()` is called, and only remove the PK when the reference is pointing to the segment to be removed
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -1307,6 +1310,7 @@ public LLRealtimeSegmentDataManager(SegmentZKMetadata segmentZKMetadata, TableCo
Set<String> fstIndexColumns = indexLoadingConfig.getFSTIndexColumns();
_fstIndexColumns = new ArrayList<>(fstIndexColumns);
+ boolean dedupEnabled = (tableConfig.getDedupConfig() != null && tableConfig.getDedupConfig().isDedupEnabled());
Review Comment:
This flag is redundant. It is implicit on the presence of `partitionDedupMetadataManager`
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
return;
}
// check table type is realtime
Preconditions
- .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert table is for realtime table only.");
+ .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert/Dedup table is for realtime table only.");
// primary key exists
Preconditions.checkState(CollectionUtils.isNotEmpty(schema.getPrimaryKeyColumns()),
- "Upsert table must have primary key columns in the schema");
+ "Upsert/Dedup table must have primary key columns in the schema");
// consumer type must be low-level
Map<String, String> streamConfigsMap = IngestionConfigUtils.getStreamConfigMap(tableConfig);
StreamConfig streamConfig = new StreamConfig(tableConfig.getTableName(), streamConfigsMap);
Preconditions.checkState(streamConfig.hasLowLevelConsumerType() && !streamConfig.hasHighLevelConsumerType(),
- "Upsert table must use low-level streaming consumer type");
+ "Upsert/Dedup table must use low-level streaming consumer type");
// replica group is configured for routing
Preconditions.checkState(
tableConfig.getRoutingConfig() != null && RoutingConfig.STRICT_REPLICA_GROUP_INSTANCE_SELECTOR_TYPE
.equalsIgnoreCase(tableConfig.getRoutingConfig().getInstanceSelectorType()),
- "Upsert table must use strict replica-group (i.e. strictReplicaGroup) based routing");
- // no startree index
- Preconditions.checkState(
- CollectionUtils.isEmpty(tableConfig.getIndexingConfig().getStarTreeIndexConfigs()) && !tableConfig
- .getIndexingConfig().isEnableDefaultStarTree(), "The upsert table cannot have star-tree index.");
- // comparison column exists
- if (tableConfig.getUpsertConfig().getComparisonColumn() != null) {
- String comparisonCol = tableConfig.getUpsertConfig().getComparisonColumn();
- Preconditions.checkState(schema.hasColumn(comparisonCol), "The comparison column does not exist on schema");
+ "Upsert/Dedup table must use strict replica-group (i.e. strictReplicaGroup) based routing");
Review Comment:
We should also validate that upsert and dedup cannot co-exist
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
return;
}
// check table type is realtime
Preconditions
- .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert table is for realtime table only.");
+ .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert/Dedup table is for realtime table only.");
// primary key exists
Preconditions.checkState(CollectionUtils.isNotEmpty(schema.getPrimaryKeyColumns()),
- "Upsert table must have primary key columns in the schema");
+ "Upsert/Dedup table must have primary key columns in the schema");
// consumer type must be low-level
Map<String, String> streamConfigsMap = IngestionConfigUtils.getStreamConfigMap(tableConfig);
StreamConfig streamConfig = new StreamConfig(tableConfig.getTableName(), streamConfigsMap);
Preconditions.checkState(streamConfig.hasLowLevelConsumerType() && !streamConfig.hasHighLevelConsumerType(),
- "Upsert table must use low-level streaming consumer type");
+ "Upsert/Dedup table must use low-level streaming consumer type");
// replica group is configured for routing
Preconditions.checkState(
tableConfig.getRoutingConfig() != null && RoutingConfig.STRICT_REPLICA_GROUP_INSTANCE_SELECTOR_TYPE
.equalsIgnoreCase(tableConfig.getRoutingConfig().getInstanceSelectorType()),
- "Upsert table must use strict replica-group (i.e. strictReplicaGroup) based routing");
- // no startree index
- Preconditions.checkState(
- CollectionUtils.isEmpty(tableConfig.getIndexingConfig().getStarTreeIndexConfigs()) && !tableConfig
- .getIndexingConfig().isEnableDefaultStarTree(), "The upsert table cannot have star-tree index.");
- // comparison column exists
- if (tableConfig.getUpsertConfig().getComparisonColumn() != null) {
- String comparisonCol = tableConfig.getUpsertConfig().getComparisonColumn();
- Preconditions.checkState(schema.hasColumn(comparisonCol), "The comparison column does not exist on schema");
+ "Upsert/Dedup table must use strict replica-group (i.e. strictReplicaGroup) based routing");
+
+ // specifically for upsert
+ if (tableConfig.getUpsertConfig() != null) {
Review Comment:
Non-null config doesn't mean it is enabled
```suggestion
if (tableConfig.getUpsertMode() != UpsertConfig.Mode.NONE) {
```
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
Review Comment:
Non-null dedup config doesn't mean it is enabled. We either remove the `dedupEnabled` field and treat non-null dedup as dedup-enabled, or check the flag.
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -364,9 +384,27 @@ public void addSegment(ImmutableSegment immutableSegment) {
if (isUpsertEnabled()) {
handleUpsert((ImmutableSegmentImpl) immutableSegment);
}
+
+ if (_isDedupEnabled) {
+ buildDedupeMeta((ImmutableSegmentImpl) immutableSegment);
+ }
super.addSegment(immutableSegment);
}
+ private void buildDedupeMeta(ImmutableSegmentImpl immutableSegment) {
Review Comment:
(nit)
```suggestion
private void buildDedupMeta(ImmutableSegmentImpl immutableSegment) {
```
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -364,9 +384,27 @@ public void addSegment(ImmutableSegment immutableSegment) {
if (isUpsertEnabled()) {
handleUpsert((ImmutableSegmentImpl) immutableSegment);
}
+
+ if (_isDedupEnabled) {
+ buildDedupeMeta((ImmutableSegmentImpl) immutableSegment);
+ }
super.addSegment(immutableSegment);
}
+ private void buildDedupeMeta(ImmutableSegmentImpl immutableSegment) {
+ // TODO(saurabh) refactor commons code with handleUpsert
+ String segmentName = immutableSegment.getSegmentName();
+ Integer partitionGroupId = SegmentUtils
+ .getRealtimeSegmentPartitionId(segmentName, _tableNameWithType, _helixManager, _primaryKeyColumns.get(0));
+ Preconditions.checkNotNull(partitionGroupId, String
+ .format("PartitionGroupId is not available for segment: '%s' (upsert-enabled table: %s)", segmentName,
Review Comment:
```suggestion
.format("PartitionGroupId is not available for segment: '%s' (dedup-enabled table: %s)", segmentName,
```
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/DedupConfig.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.spi.config.table;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.pinot.spi.config.BaseJsonConfig;
+
+public class DedupConfig extends BaseJsonConfig {
+ private final boolean _dedupEnabled;
+ private final HashFunction _hashFunction;
+
+ @JsonCreator
+ public DedupConfig(@JsonProperty(value = "dedupEnabled", required = true) final boolean dedupEnabled,
Review Comment:
(minor) We don't usually put `final` for local variables or parameters
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r885375872
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -1307,6 +1310,7 @@ public LLRealtimeSegmentDataManager(SegmentZKMetadata segmentZKMetadata, TableCo
Set<String> fstIndexColumns = indexLoadingConfig.getFSTIndexColumns();
_fstIndexColumns = new ArrayList<>(fstIndexColumns);
+ boolean dedupEnabled = (tableConfig.getDedupConfig() != null && tableConfig.getDedupConfig().isDedupEnabled());
Review Comment:
Ack
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -111,7 +116,9 @@ public class RealtimeTableDataManager extends BaseTableDataManager {
private static final int MIN_INTERVAL_BETWEEN_STATS_UPDATES_MINUTES = 30;
private UpsertConfig.Mode _upsertMode;
+ private boolean _isDedupEnabled;
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886561566
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
Ack.
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] codecov-commenter commented on pull request #8708: (WIP) Dedup config
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #8708:
URL: https://github.com/apache/pinot/pull/8708#issuecomment-1127957974
# [Codecov](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#8708](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c722833) into [master](https://codecov.io/gh/apache/pinot/commit/d3c97d54d24ab42203c760d1ed5cbef981b13f44?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d3c97d5) will **decrease** coverage by `1.74%`.
> The diff coverage is `53.91%`.
```diff
@@ Coverage Diff @@
## master #8708 +/- ##
============================================
- Coverage 69.67% 67.92% -1.75%
- Complexity 4571 4578 +7
============================================
Files 1722 1727 +5
Lines 89862 89932 +70
Branches 13335 13347 +12
============================================
- Hits 62610 61089 -1521
- Misses 22920 24583 +1663
+ Partials 4332 4260 -72
```
| Flag | Coverage Δ | |
|---|---|---|
| integration1 | `?` | |
| integration2 | `25.42% <9.56%> (+0.22%)` | :arrow_up: |
| unittests1 | `66.11% <49.56%> (-0.05%)` | :arrow_down: |
| unittests2 | `14.32% <0.00%> (-0.01%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ent/local/dedup/PartitionDedupMetadataManager.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9kZWR1cC9QYXJ0aXRpb25EZWR1cE1ldGFkYXRhTWFuYWdlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...segment/local/dedup/TableDedupMetadataManager.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9kZWR1cC9UYWJsZURlZHVwTWV0YWRhdGFNYW5hZ2VyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...org/apache/pinot/spi/config/table/DedupConfig.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL0RlZHVwQ29uZmlnLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...rg/apache/pinot/spi/config/table/UpsertConfig.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL1Vwc2VydENvbmZpZy5qYXZh) | `85.71% <ø> (-1.25%)` | :arrow_down: |
| [...he/pinot/spi/utils/builder/TableConfigBuilder.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdXRpbHMvYnVpbGRlci9UYWJsZUNvbmZpZ0J1aWxkZXIuamF2YQ==) | `81.37% <0.00%> (-1.14%)` | :arrow_down: |
| [...org/apache/pinot/spi/config/table/TableConfig.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL1RhYmxlQ29uZmlnLmphdmE=) | `62.82% <40.00%> (-0.70%)` | :arrow_down: |
| [...he/pinot/common/utils/config/TableConfigUtils.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdXRpbHMvY29uZmlnL1RhYmxlQ29uZmlnVXRpbHMuamF2YQ==) | `81.81% <42.85%> (-2.01%)` | :arrow_down: |
| [...ata/manager/realtime/RealtimeTableDataManager.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL21hbmFnZXIvcmVhbHRpbWUvUmVhbHRpbWVUYWJsZURhdGFNYW5hZ2VyLmphdmE=) | `65.88% <50.00%> (-2.40%)` | :arrow_down: |
| [...local/indexsegment/mutable/MutableSegmentImpl.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9pbmRleHNlZ21lbnQvbXV0YWJsZS9NdXRhYmxlU2VnbWVudEltcGwuamF2YQ==) | `56.95% <50.00%> (-0.51%)` | :arrow_down: |
| [...rg/apache/pinot/segment/local/utils/HashUtils.java](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC91dGlscy9IYXNoVXRpbHMuamF2YQ==) | `71.42% <60.00%> (-28.58%)` | :arrow_down: |
| ... and [153 more](https://codecov.io/gh/apache/pinot/pull/8708/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d3c97d5...c722833](https://codecov.io/gh/apache/pinot/pull/8708?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r884539829
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
Review Comment:
Idea here is, if the config json doesn't have dedupeConfig field, no need to run the validaiton
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886704042
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/TableConfig.java:
##########
@@ -288,8 +303,8 @@ public void setTierConfigsList(List<TierConfig> tierConfigsList) {
}
@JsonIgnore
- public UpsertConfig.HashFunction getHashFunction() {
- return _upsertConfig == null ? UpsertConfig.HashFunction.NONE : _upsertConfig.getHashFunction();
+ public HashFunction getHashFunction() {
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886538200
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887555107
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887554795
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -477,8 +482,22 @@ public boolean index(GenericRow row, @Nullable RowMetadata rowMetadata)
throws IOException {
boolean canTakeMore;
int numDocsIndexed = _numDocsIndexed;
+
+ RecordInfo recordInfo = null;
+
+ if (isDedupEnabled() || isUpsertEnabled()) {
+ recordInfo = getRecordInfo(row, numDocsIndexed);
+ }
+
+ if (isDedupEnabled() && _partitionDedupMetadataManager.checkRecordPresentOrUpdate(recordInfo, this)) {
+ _logger.info("Dropped row {} since its primary key already exists", row);
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r884538144
##########
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:
^ This comment is now outdated.
As discussed over slack, I've added reference to the IndexSegment to which the primay key belongs, in the metdata map.
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887554894
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -477,8 +482,22 @@ public boolean index(GenericRow row, @Nullable RowMetadata rowMetadata)
throws IOException {
boolean canTakeMore;
int numDocsIndexed = _numDocsIndexed;
+
+ RecordInfo recordInfo = null;
+
+ if (isDedupEnabled() || isUpsertEnabled()) {
+ recordInfo = getRecordInfo(row, numDocsIndexed);
+ }
+
+ if (isDedupEnabled() && _partitionDedupMetadataManager.checkRecordPresentOrUpdate(recordInfo, this)) {
+ _logger.info("Dropped row {} since its primary key already exists", row);
+ if (_serverMetrics != null) {
+ _serverMetrics.addMeteredTableValue(_realtimeTableName, ServerMeter.REALTIME_DEDUP_DROPPED, 1);
+ }
+ return numDocsIndexed < _capacity;
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887552243
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
Review Comment:
Ack. Didn't see any big impact of changing the method signature to accept PK, hence made that change too.
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] KKcorps commented on pull request #8708: [Feature] Deduplication
Posted by GitBox <gi...@apache.org>.
KKcorps commented on PR #8708:
URL: https://github.com/apache/pinot/pull/8708#issuecomment-1146049919
@saurabhd336 Please add documentation for this in `Import Data` section. You can create a new page titled `Stream Ingestion with Dedup`
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887554522
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
+ Map<String, PinotSegmentColumnReader> columnToReaderMap = new HashMap<>();
+ for (String primaryKeyColumn : primaryKeyColumns) {
+ columnToReaderMap.put(primaryKeyColumn, new PinotSegmentColumnReader(segment, primaryKeyColumn));
+ }
+ int numTotalDocs = segment.getSegmentMetadata().getTotalDocs();
+ int numPrimaryKeyColumns = primaryKeyColumns.size();
+ return new Iterator<RecordInfo>() {
+ private int _docId = 0;
+
+ @Override
+ public boolean hasNext() {
+ return _docId < numTotalDocs;
+ }
+
+ @Override
+ public RecordInfo next() {
+ Object[] values = new Object[numPrimaryKeyColumns];
+ for (int i = 0; i < numPrimaryKeyColumns; i++) {
+ Object value = columnToReaderMap.get(primaryKeyColumns.get(i)).getValue(_docId);
+ if (value instanceof byte[]) {
+ value = new ByteArray((byte[]) value);
+ }
+ values[i] = value;
+ }
+ PrimaryKey primaryKey = new PrimaryKey(values);
+ return new RecordInfo(primaryKey, _docId++, null);
+ }
+ };
+ }
+
+ private synchronized void waitTillAllSegmentsLoaded() {
+ while (!TableState.isAllSegmentsLoaded(_helixManager, _tableNameWithType)) {
+ LOGGER.info("Sleeping 1 second waiting for all segments loaded for partial-upsert table: {}", _tableNameWithType);
+ try {
+ //noinspection BusyWait
+ Thread.sleep(1000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ _allSegmentsLoaded = true;
+ }
+
+ public boolean checkRecordPresentOrUpdate(RecordInfo recordInfo, IndexSegment indexSegment) {
+ if (!_allSegmentsLoaded) {
Review Comment:
Can you help me understand the thread safety concerns with this? I don't any, single threaded or multi threaded.
Infact, moving this if check inside `waitTillAllSegmentsLoaded()` would lead to unnecessary serialization even when all segments have already been loaded. Even in single threaded env, that's a heavy lock acquisition cost, when `_allSegmentsLoaded` is already true.
To the point where, I think we should reduce the critical section here https://github.com/apache/pinot/blob/master/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/PartialUpsertHandler.java#L74, once `_allSegmentsLoaded` has been set to true, no need to enter a syncronized block.
Do let me know your thoughts
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886539092
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
return;
}
// check table type is realtime
Preconditions
- .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert table is for realtime table only.");
+ .checkState(tableConfig.getTableType() == TableType.REALTIME, "Upsert/Dedup table is for realtime table only.");
// primary key exists
Preconditions.checkState(CollectionUtils.isNotEmpty(schema.getPrimaryKeyColumns()),
- "Upsert table must have primary key columns in the schema");
+ "Upsert/Dedup table must have primary key columns in the schema");
// consumer type must be low-level
Map<String, String> streamConfigsMap = IngestionConfigUtils.getStreamConfigMap(tableConfig);
StreamConfig streamConfig = new StreamConfig(tableConfig.getTableName(), streamConfigsMap);
Preconditions.checkState(streamConfig.hasLowLevelConsumerType() && !streamConfig.hasHighLevelConsumerType(),
- "Upsert table must use low-level streaming consumer type");
+ "Upsert/Dedup table must use low-level streaming consumer type");
// replica group is configured for routing
Preconditions.checkState(
tableConfig.getRoutingConfig() != null && RoutingConfig.STRICT_REPLICA_GROUP_INSTANCE_SELECTOR_TYPE
.equalsIgnoreCase(tableConfig.getRoutingConfig().getInstanceSelectorType()),
- "Upsert table must use strict replica-group (i.e. strictReplicaGroup) based routing");
- // no startree index
- Preconditions.checkState(
- CollectionUtils.isEmpty(tableConfig.getIndexingConfig().getStarTreeIndexConfigs()) && !tableConfig
- .getIndexingConfig().isEnableDefaultStarTree(), "The upsert table cannot have star-tree index.");
- // comparison column exists
- if (tableConfig.getUpsertConfig().getComparisonColumn() != null) {
- String comparisonCol = tableConfig.getUpsertConfig().getComparisonColumn();
- Preconditions.checkState(schema.hasColumn(comparisonCol), "The comparison column does not exist on schema");
+ "Upsert/Dedup table must use strict replica-group (i.e. strictReplicaGroup) based routing");
+
+ // specifically for upsert
+ if (tableConfig.getUpsertConfig() != null) {
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r885379303
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -364,9 +384,27 @@ public void addSegment(ImmutableSegment immutableSegment) {
if (isUpsertEnabled()) {
handleUpsert((ImmutableSegmentImpl) immutableSegment);
}
+
+ if (_isDedupEnabled) {
+ buildDedupeMeta((ImmutableSegmentImpl) immutableSegment);
+ }
super.addSegment(immutableSegment);
}
+ private void buildDedupeMeta(ImmutableSegmentImpl immutableSegment) {
Review Comment:
Ack
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -364,9 +384,27 @@ public void addSegment(ImmutableSegment immutableSegment) {
if (isUpsertEnabled()) {
handleUpsert((ImmutableSegmentImpl) immutableSegment);
}
+
+ if (_isDedupEnabled) {
+ buildDedupeMeta((ImmutableSegmentImpl) immutableSegment);
+ }
super.addSegment(immutableSegment);
}
+ private void buildDedupeMeta(ImmutableSegmentImpl immutableSegment) {
+ // TODO(saurabh) refactor commons code with handleUpsert
+ String segmentName = immutableSegment.getSegmentName();
+ Integer partitionGroupId = SegmentUtils
+ .getRealtimeSegmentPartitionId(segmentName, _tableNameWithType, _helixManager, _primaryKeyColumns.get(0));
+ Preconditions.checkNotNull(partitionGroupId, String
+ .format("PartitionGroupId is not available for segment: '%s' (upsert-enabled table: %s)", segmentName,
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887385795
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
Review Comment:
```suggestion
final ConcurrentHashMap<Object, IndexSegment> _primaryKeyToSegmentMap = new ConcurrentHashMap<>();
```
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
Review Comment:
(minor) Remove this TODO
##########
pinot-segment-local/src/test/resources/data/test_dedup_data.json:
##########
@@ -0,0 +1,22 @@
+[
+ {
+ "event_id": "aa",
+ "description" : "first",
+ "secondsSinceEpoch": 1567205394
+ },
+ {
+ "event_id": "bb",
+ "description" : "first",
+ "secondsSinceEpoch": 1567205396
+ },
+ {
+ "event_id": "aa",
+ "description" : "second",
+ "secondsSinceEpoch": 1567205397
+ },
+ {
+ "event_id": "bb",
+ "description" : "second",
+ "secondsSinceEpoch": 1567205392
+ }
+]
Review Comment:
(nit) empty line
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -538,6 +539,7 @@ private void processStreamEvents(MessageBatch messagesAndOffsets, long idlePipeS
}
for (GenericRow transformedRow : reusedResult.getTransformedRows()) {
try {
+ // TODO(saurabh): we may have dropped the record due to dedup. Should we increment indexedMessageCount?
Review Comment:
(minor) Since we already track the dropped records, we can remove this TODO and consider changing it to a comment
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -477,8 +482,22 @@ public boolean index(GenericRow row, @Nullable RowMetadata rowMetadata)
throws IOException {
boolean canTakeMore;
int numDocsIndexed = _numDocsIndexed;
+
+ RecordInfo recordInfo = null;
+
+ if (isDedupEnabled() || isUpsertEnabled()) {
+ recordInfo = getRecordInfo(row, numDocsIndexed);
+ }
+
+ if (isDedupEnabled() && _partitionDedupMetadataManager.checkRecordPresentOrUpdate(recordInfo, this)) {
+ _logger.info("Dropped row {} since its primary key already exists", row);
+ if (_serverMetrics != null) {
+ _serverMetrics.addMeteredTableValue(_realtimeTableName, ServerMeter.REALTIME_DEDUP_DROPPED, 1);
+ }
+ return numDocsIndexed < _capacity;
Review Comment:
(minor)
```suggestion
return true;
```
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
Review Comment:
Suggest returning an iterator of `PrimaryKey`. For dedup, we don't need the docId and comparisonValue information from the `RecordInfo`. Similar for the `checkRecordPresentOrUpdate()` which can just take the `PrimaryKey` object. This is not a blocker, so maybe put a TODO and address it later
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -477,8 +482,22 @@ public boolean index(GenericRow row, @Nullable RowMetadata rowMetadata)
throws IOException {
boolean canTakeMore;
int numDocsIndexed = _numDocsIndexed;
+
+ RecordInfo recordInfo = null;
+
+ if (isDedupEnabled() || isUpsertEnabled()) {
+ recordInfo = getRecordInfo(row, numDocsIndexed);
+ }
+
+ if (isDedupEnabled() && _partitionDedupMetadataManager.checkRecordPresentOrUpdate(recordInfo, this)) {
+ _logger.info("Dropped row {} since its primary key already exists", row);
Review Comment:
Don't log anything here, it can flood the log
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
(minor) Let's rename it to `TableStateUtils`
##########
pinot-segment-local/src/test/resources/data/test_dedup_schema.json:
##########
@@ -0,0 +1,21 @@
+{
+ "schemaName": "test_pinot_table",
+ "dimensionFieldSpecs": [
+ {
+ "name": "event_id",
+ "dataType": "STRING"
+ },
+ {
+ "name": "description",
+ "dataType": "STRING"
+ }
+ ],
+ "timeFieldSpec": {
+ "incomingGranularitySpec": {
+ "name": "secondsSinceEpoch",
+ "dataType": "LONG",
+ "timeType": "SECONDS"
+ }
+ },
+ "primaryKeyColumns": ["event_id"]
+}
Review Comment:
(nit) empty line
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
+ Map<String, PinotSegmentColumnReader> columnToReaderMap = new HashMap<>();
+ for (String primaryKeyColumn : primaryKeyColumns) {
+ columnToReaderMap.put(primaryKeyColumn, new PinotSegmentColumnReader(segment, primaryKeyColumn));
+ }
+ int numTotalDocs = segment.getSegmentMetadata().getTotalDocs();
+ int numPrimaryKeyColumns = primaryKeyColumns.size();
+ return new Iterator<RecordInfo>() {
+ private int _docId = 0;
+
+ @Override
+ public boolean hasNext() {
+ return _docId < numTotalDocs;
+ }
+
+ @Override
+ public RecordInfo next() {
+ Object[] values = new Object[numPrimaryKeyColumns];
+ for (int i = 0; i < numPrimaryKeyColumns; i++) {
+ Object value = columnToReaderMap.get(primaryKeyColumns.get(i)).getValue(_docId);
+ if (value instanceof byte[]) {
+ value = new ByteArray((byte[]) value);
+ }
+ values[i] = value;
+ }
+ PrimaryKey primaryKey = new PrimaryKey(values);
+ return new RecordInfo(primaryKey, _docId++, null);
+ }
+ };
+ }
+
+ private synchronized void waitTillAllSegmentsLoaded() {
+ while (!TableState.isAllSegmentsLoaded(_helixManager, _tableNameWithType)) {
+ LOGGER.info("Sleeping 1 second waiting for all segments loaded for partial-upsert table: {}", _tableNameWithType);
+ try {
+ //noinspection BusyWait
+ Thread.sleep(1000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ _allSegmentsLoaded = true;
+ }
+
+ public boolean checkRecordPresentOrUpdate(RecordInfo recordInfo, IndexSegment indexSegment) {
+ if (!_allSegmentsLoaded) {
Review Comment:
Let's move the if check into the `waitTillAllSegmentsLoaded()` for thread safety. It is single threaded now, but in case that changes
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887549081
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r888173695
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
+ Map<String, PinotSegmentColumnReader> columnToReaderMap = new HashMap<>();
+ for (String primaryKeyColumn : primaryKeyColumns) {
+ columnToReaderMap.put(primaryKeyColumn, new PinotSegmentColumnReader(segment, primaryKeyColumn));
+ }
+ int numTotalDocs = segment.getSegmentMetadata().getTotalDocs();
+ int numPrimaryKeyColumns = primaryKeyColumns.size();
+ return new Iterator<RecordInfo>() {
+ private int _docId = 0;
+
+ @Override
+ public boolean hasNext() {
+ return _docId < numTotalDocs;
+ }
+
+ @Override
+ public RecordInfo next() {
+ Object[] values = new Object[numPrimaryKeyColumns];
+ for (int i = 0; i < numPrimaryKeyColumns; i++) {
+ Object value = columnToReaderMap.get(primaryKeyColumns.get(i)).getValue(_docId);
+ if (value instanceof byte[]) {
+ value = new ByteArray((byte[]) value);
+ }
+ values[i] = value;
+ }
+ PrimaryKey primaryKey = new PrimaryKey(values);
+ return new RecordInfo(primaryKey, _docId++, null);
+ }
+ };
+ }
+
+ private synchronized void waitTillAllSegmentsLoaded() {
+ while (!TableState.isAllSegmentsLoaded(_helixManager, _tableNameWithType)) {
+ LOGGER.info("Sleeping 1 second waiting for all segments loaded for partial-upsert table: {}", _tableNameWithType);
+ try {
+ //noinspection BusyWait
+ Thread.sleep(1000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ _allSegmentsLoaded = true;
+ }
+
+ public boolean checkRecordPresentOrUpdate(RecordInfo recordInfo, IndexSegment indexSegment) {
+ if (!_allSegmentsLoaded) {
Review Comment:
I misused the word thread-safety. I was suggesting adding an extra if check in the synchronized block to avoid potential unnecessary checks when multiple threads invoke `waitTillAllSegmentsLoaded()`.
Good point on reducing the critical section in `PartialUpsertHandler`. We should first check the flag, then enter the critical section
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887547896
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -538,6 +539,7 @@ private void processStreamEvents(MessageBatch messagesAndOffsets, long idlePipeS
}
for (GenericRow transformedRow : reusedResult.getTransformedRows()) {
try {
+ // TODO(saurabh): we may have dropped the record due to dedup. Should we increment indexedMessageCount?
Review Comment:
Ack. I think with the metric added, this is no longer needed
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887548470
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
Review Comment:
Ack
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886121748
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java:
##########
@@ -505,34 +505,40 @@ static void validateTaskConfigs(TableConfig tableConfig, Schema schema) {
* - comparison column exists
*/
@VisibleForTesting
- static void validateUpsertConfig(TableConfig tableConfig, Schema schema) {
- if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE) {
+ static void validateUpsertAndDedupConfig(TableConfig tableConfig, Schema schema) {
+ if (tableConfig.getUpsertMode() == UpsertConfig.Mode.NONE && tableConfig.getDedupConfig() == null) {
Review Comment:
Understood. We should also skip the validation when `DedupConfig` is available, but dedup is not enabled
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
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 gets destroyed, the flag helps is deciding whether or not its keys must 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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r886120646
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
The reason why I suggest modeling this class as a util and not tracking `_allSegmentsLoaded` within this class is because we may reuse this util method for other features, and we don't want to couple this "check once then always true" semantic into this util method/class
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r885381577
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.utils.tablestate;
+
+import java.util.Map;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.LiveInstance;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TableState {
Review Comment:
_allSegmentsLoaded will need to present in both upsert and dedupe metadata classes separately. Here its with just one instance of this class. Is that okay?
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [pinot] saurabhd336 commented on a diff in pull request #8708: Dedup config
Posted by GitBox <gi...@apache.org>.
saurabhd336 commented on code in PR #8708:
URL: https://github.com/apache/pinot/pull/8708#discussion_r887554522
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/PartitionDedupMetadataManager.java:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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.helix.HelixManager;
+import org.apache.pinot.common.metrics.ServerGauge;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader;
+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(PartitionDedupMetadataManager.class);
+
+ private final HelixManager _helixManager;
+ private final String _tableNameWithType;
+ private final List<String> _primaryKeyColumns;
+ private final int _partitionId;
+ private final ServerMetrics _serverMetrics;
+ private final HashFunction _hashFunction;
+ private boolean _allSegmentsLoaded;
+
+ // TODO(saurabh) : We can replace this with a ocncurrent Set
+ @VisibleForTesting
+ final ConcurrentHashMap<Object, IndexSegment> _primaryKeySet = new ConcurrentHashMap<>();
+
+ public PartitionDedupMetadataManager(HelixManager helixManager, String tableNameWithType,
+ List<String> primaryKeyColumns, int partitionId, ServerMetrics serverMetrics, HashFunction hashFunction) {
+ _helixManager = helixManager;
+ _tableNameWithType = tableNameWithType;
+ _primaryKeyColumns = primaryKeyColumns;
+ _partitionId = partitionId;
+ _serverMetrics = serverMetrics;
+ _hashFunction = hashFunction;
+ }
+
+ public void addSegment(IndexSegment segment) {
+ // Add all PKs to _primaryKeySet
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.put(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction), segment);
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ public void removeSegment(IndexSegment segment) {
+ // TODO(saurabh): Explain reload scenario here
+ Iterator<RecordInfo> recordInfoIterator = getRecordInfoIterator(segment, _primaryKeyColumns);
+ while (recordInfoIterator.hasNext()) {
+ RecordInfo recordInfo = recordInfoIterator.next();
+ _primaryKeySet.compute(HashUtils.hashPrimaryKey(recordInfo.getPrimaryKey(), _hashFunction),
+ (primaryKey, currentSegment) -> {
+ if (currentSegment == segment) {
+ return null;
+ } else {
+ return currentSegment;
+ }
+ });
+ }
+ _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, ServerGauge.DEDUP_PRIMARY_KEYS_COUNT,
+ _primaryKeySet.size());
+ }
+
+ @VisibleForTesting
+ public static Iterator<RecordInfo> getRecordInfoIterator(IndexSegment segment, List<String> primaryKeyColumns) {
+ Map<String, PinotSegmentColumnReader> columnToReaderMap = new HashMap<>();
+ for (String primaryKeyColumn : primaryKeyColumns) {
+ columnToReaderMap.put(primaryKeyColumn, new PinotSegmentColumnReader(segment, primaryKeyColumn));
+ }
+ int numTotalDocs = segment.getSegmentMetadata().getTotalDocs();
+ int numPrimaryKeyColumns = primaryKeyColumns.size();
+ return new Iterator<RecordInfo>() {
+ private int _docId = 0;
+
+ @Override
+ public boolean hasNext() {
+ return _docId < numTotalDocs;
+ }
+
+ @Override
+ public RecordInfo next() {
+ Object[] values = new Object[numPrimaryKeyColumns];
+ for (int i = 0; i < numPrimaryKeyColumns; i++) {
+ Object value = columnToReaderMap.get(primaryKeyColumns.get(i)).getValue(_docId);
+ if (value instanceof byte[]) {
+ value = new ByteArray((byte[]) value);
+ }
+ values[i] = value;
+ }
+ PrimaryKey primaryKey = new PrimaryKey(values);
+ return new RecordInfo(primaryKey, _docId++, null);
+ }
+ };
+ }
+
+ private synchronized void waitTillAllSegmentsLoaded() {
+ while (!TableState.isAllSegmentsLoaded(_helixManager, _tableNameWithType)) {
+ LOGGER.info("Sleeping 1 second waiting for all segments loaded for partial-upsert table: {}", _tableNameWithType);
+ try {
+ //noinspection BusyWait
+ Thread.sleep(1000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ _allSegmentsLoaded = true;
+ }
+
+ public boolean checkRecordPresentOrUpdate(RecordInfo recordInfo, IndexSegment indexSegment) {
+ if (!_allSegmentsLoaded) {
Review Comment:
Could you help me understand the thread safety concerns with this? I don't any, single threaded or multi threaded.
Infact, moving this if check inside `waitTillAllSegmentsLoaded()` would lead to unnecessary serialization even when all segments have already been loaded. Even in single threaded env, that's a heavy lock acquisition cost, when `_allSegmentsLoaded` is already true.
To the point where, I think we should reduce the critical section here https://github.com/apache/pinot/blob/master/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/PartialUpsertHandler.java#L74, once `_allSegmentsLoaded` has been set to true, no need to enter a syncronized block.
Do let me know your thoughts
--
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-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org