PrachiKhobragade commented on code in PR #10679: URL: https://github.com/apache/pinot/pull/10679#discussion_r1179533843
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -241,12 +248,25 @@ public String load(String instanceId) { for (int i = 0; i < _tableUpdaterLocks.length; i++) { _tableUpdaterLocks[i] = new Object(); } + _lineageManager = lineageManager; } public PinotHelixResourceManager(ControllerConf controllerConf) { this(controllerConf.getZkStr(), controllerConf.getHelixClusterName(), controllerConf.getDataDir(), controllerConf.tenantIsolationEnabled(), controllerConf.getEnableBatchMessageMode(), - controllerConf.getHLCTablesAllowed(), controllerConf.getDeletedSegmentsRetentionInDays()); + controllerConf.getHLCTablesAllowed(), controllerConf.getDeletedSegmentsRetentionInDays(), + getLineageManager(controllerConf)); + } + + public static LineageManager getLineageManager(ControllerConf controllerConf) { + String lineageManagerClassName = controllerConf.getLineageManagerClass(); + try { + return (LineageManager) Class.forName(lineageManagerClassName).getConstructor(ControllerConf.class) + .newInstance(controllerConf); + } catch (Exception e) { + LOGGER.error("LinageModifier not found: {}", lineageManagerClassName); Review Comment: Spell check, LineageManager ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/lineage/DefaultLineageManager.java: ########## @@ -0,0 +1,125 @@ +/** + * 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.controller.api.lineage; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.lineage.LineageEntry; +import org.apache.pinot.common.lineage.LineageEntryState; +import org.apache.pinot.common.lineage.SegmentLineage; +import org.apache.pinot.controller.ControllerConf; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.utils.IngestionConfigUtils; + + +public class DefaultLineageManager implements LineageManager { + private static final long REPLACED_SEGMENTS_RETENTION_IN_MILLIS = TimeUnit.DAYS.toMillis(1L); // 1 day + private static final long LINEAGE_ENTRY_CLEANUP_RETENTION_IN_MILLIS = TimeUnit.DAYS.toMillis(1L); // 1 day + + protected ControllerConf _controllerConf; + + public DefaultLineageManager(ControllerConf controllerConf) { + _controllerConf = controllerConf; + } + + @Override + public void updateLineageForStartReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForEndReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForRevertReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForRetention(TableConfig tableConfig, SegmentLineage lineage, List<String> allSegments, + List<String> segmentsToDelete, Set<String> consumingSegments) { + // 1. The original segments can be deleted once the merged segments are successfully uploaded + // 2. The zombie lineage entry & merged segments should be deleted if the segment replacement failed in + // the middle + Set<String> segmentsForTable = new HashSet<>(allSegments); + Iterator<LineageEntry> lineageEntryIterator = lineage.getLineageEntries().values().iterator(); + while (lineageEntryIterator.hasNext()) { + LineageEntry lineageEntry = lineageEntryIterator.next(); + if (lineageEntry.getState() == LineageEntryState.COMPLETED) { + Set<String> sourceSegments = new HashSet<>(lineageEntry.getSegmentsFrom()); + sourceSegments.retainAll(segmentsForTable); + if (sourceSegments.isEmpty()) { + // If the lineage state is 'COMPLETED' and segmentFrom are removed, it is safe clean up the lineage entry + lineageEntryIterator.remove(); + } else { + // If the lineage state is 'COMPLETED' and we already preserved the original segments for the required + // retention, it is safe to delete all segments from 'segmentsFrom' + if (shouldDeleteReplacedSegments(tableConfig, lineageEntry)) { + segmentsToDelete.addAll(sourceSegments); + } + } + } else if (lineageEntry.getState() == LineageEntryState.REVERTED || ( + lineageEntry.getState() == LineageEntryState.IN_PROGRESS && lineageEntry.getTimestamp() + < System.currentTimeMillis() - LINEAGE_ENTRY_CLEANUP_RETENTION_IN_MILLIS)) { + // If the lineage state is 'IN_PROGRESS' or 'REVERTED', we need to clean up the zombie lineage + // entry and its segments + Set<String> destinationSegments = new HashSet<>(lineageEntry.getSegmentsTo()); + destinationSegments.retainAll(segmentsForTable); + if (destinationSegments.isEmpty()) { + // If the lineage state is 'IN_PROGRESS or REVERTED' and source segments are already removed, it is safe + // to clean up the lineage entry. Deleting lineage will allow the task scheduler to re-schedule the source Review Comment: Is it source segments or destinations segments in the comments here? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/lineage/DefaultLineageManager.java: ########## @@ -0,0 +1,125 @@ +/** + * 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.controller.api.lineage; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.lineage.LineageEntry; +import org.apache.pinot.common.lineage.LineageEntryState; +import org.apache.pinot.common.lineage.SegmentLineage; +import org.apache.pinot.controller.ControllerConf; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.utils.IngestionConfigUtils; + + +public class DefaultLineageManager implements LineageManager { + private static final long REPLACED_SEGMENTS_RETENTION_IN_MILLIS = TimeUnit.DAYS.toMillis(1L); // 1 day + private static final long LINEAGE_ENTRY_CLEANUP_RETENTION_IN_MILLIS = TimeUnit.DAYS.toMillis(1L); // 1 day + + protected ControllerConf _controllerConf; + + public DefaultLineageManager(ControllerConf controllerConf) { + _controllerConf = controllerConf; + } + + @Override + public void updateLineageForStartReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForEndReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForRevertReplaceSegments(TableConfig tableConfig, String lineageEntryId, + Map<String, String> customMap, SegmentLineage lineage) { + } + + @Override + public void updateLineageForRetention(TableConfig tableConfig, SegmentLineage lineage, List<String> allSegments, Review Comment: This method is doing more than one task, hence it was difficult to follow, generally it should do one task, but I don't know a better way to break this up maybe comments about the things it does will help 1) it updates lineage, or cleans up lineage entries 2) It finds all the segments that could be deleted ########## pinot-common/src/main/java/org/apache/pinot/common/restlet/resources/RevertReplaceSegmentsRequest.java: ########## @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.common.restlet.resources; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Map; +import javax.annotation.Nullable; + + +public class RevertReplaceSegmentsRequest { Review Comment: A javadoc for when this class will be used will be helpful -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org