Repository navigation
Reject duplicate segment names before batch push #19947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
xiangfu0
wants to merge
4
commits into
apache:master
from
xiangfu0:xiangfu0/codex1/duplicate-segment-validation
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aad1a18
Reject duplicate segment names before batch push
xiangfu0 e988618
Preserve empty refresh replacement and nullable output paths
xiangfu0 de22081
Preserve segment URI when output directory is omitted
xiangfu0 6208e67
Wait for broker routing before offline query tests
xiangfu0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...org/apache/pinot/plugin/ingestion/batch/spark3/SparkSegmentMetadataPushJobRunnerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * 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.plugin.ingestion.batch.spark3; | ||
|
|
||
| import java.net.URI; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.pinot.segment.local.utils.ConsistentDataPushUtils; | ||
| import org.apache.pinot.spi.config.table.TableConfig; | ||
| import org.apache.pinot.spi.config.table.TableType; | ||
| import org.apache.pinot.spi.config.table.ingestion.BatchIngestionConfig; | ||
| import org.apache.pinot.spi.config.table.ingestion.IngestionConfig; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.PushJobSpec; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.TableSpec; | ||
| import org.apache.pinot.spi.utils.builder.TableConfigBuilder; | ||
| import org.mockito.MockedStatic; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.times; | ||
|
|
||
|
|
||
| /// Verifies that empty selections retain consistent REFRESH replacement without starting Spark uploads. | ||
| public class SparkSegmentMetadataPushJobRunnerTest { | ||
| @DataProvider | ||
| public Object[][] emptyPushModes() { | ||
| return new Object[][]{{true, 0}, {true, 1}, {true, 2}, {false, 0}}; | ||
| } | ||
|
|
||
| @Test(dataProvider = "emptyPushModes") | ||
| public void testEmptySelectionHonorsConsistentPush(boolean consistentPush, int parallelism) | ||
| throws Exception { | ||
| Path outputDir = Files.createTempDirectory("empty-metadata-push-"); | ||
| try { | ||
| IngestionConfig ingestion = new IngestionConfig(); | ||
| ingestion.setBatchIngestionConfig(new BatchIngestionConfig(null, "REFRESH", "DAILY", consistentPush)); | ||
| TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName("test") | ||
| .setIngestionConfig(ingestion).build(); | ||
| Path tableConfigFile = outputDir.resolve("table.json"); | ||
| Files.writeString(tableConfigFile, tableConfig.toJsonString()); | ||
| TableSpec tableSpec = new TableSpec(); | ||
| tableSpec.setTableName("test"); | ||
| tableSpec.setTableConfigURI(tableConfigFile.toUri().toString()); | ||
| SegmentGenerationJobSpec spec = new SegmentGenerationJobSpec(); | ||
| spec.setTableSpec(tableSpec); | ||
| spec.setOutputDirURI(outputDir.toUri().toString()); | ||
| spec.setPinotFSSpecs(List.of()); | ||
| PushJobSpec pushSpec = new PushJobSpec(); | ||
| pushSpec.setPushParallelism(parallelism); | ||
| spec.setPushJobSpec(pushSpec); | ||
| Map<URI, String> lineage = Map.of(URI.create("http://localhost:9000"), "lineage"); | ||
| try (MockedStatic<ConsistentDataPushUtils> consistent = mockStatic(ConsistentDataPushUtils.class)) { | ||
| consistent.when(() -> ConsistentDataPushUtils.consistentDataPushEnabled(any())).thenCallRealMethod(); | ||
| consistent.when(() -> ConsistentDataPushUtils.preUpload(spec, List.of())).thenReturn(lineage); | ||
| SparkSegmentMetadataPushJobRunner runner = new SparkSegmentMetadataPushJobRunner(); | ||
| runner.init(spec); | ||
| runner.run(); | ||
| consistent.verify(() -> ConsistentDataPushUtils.preUpload(spec, List.of()), times(consistentPush ? 1 : 0)); | ||
| consistent.verify(() -> ConsistentDataPushUtils.postUpload(spec, lineage), times(consistentPush ? 1 : 0)); | ||
| } | ||
| } finally { | ||
| FileUtils.deleteDirectory(outputDir.toFile()); | ||
| } | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
.../pinot/plugin/ingestion/batch/spark/common/DuplicateSegmentMetadataPushJobRunnerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.plugin.ingestion.batch.spark.common; | ||
|
|
||
| import java.net.URI; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.PinotFSSpec; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.PushJobSpec; | ||
| import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertThrows; | ||
|
|
||
|
|
||
| /// Exercises driver-side filtering with real local files before dispatching segment pushes. | ||
| public class DuplicateSegmentMetadataPushJobRunnerTest { | ||
| @DataProvider | ||
| public Object[][] pushModes() { | ||
| return new Object[][]{{"metadata"}, {"tar"}, {"uri"}}; | ||
| } | ||
|
|
||
| @Test(dataProvider = "pushModes") | ||
| public void testPushPatternFiltersBeforeDuplicateValidation(String mode) | ||
| throws Exception { | ||
| Path outputDir = Files.createTempDirectory("segment-push-% "); | ||
| try { | ||
| Path current = Files.createDirectory(outputDir.resolve("current")); | ||
| Path selected = Files.createFile(current.resolve("segment.tar.gz")); | ||
| Files.createFile(Files.createDirectory(outputDir.resolve("stale")).resolve("segment.tar.gz")); | ||
| SegmentGenerationJobSpec spec = new SegmentGenerationJobSpec(); | ||
| spec.setOutputDirURI(outputDir.toUri().toString()); | ||
| spec.setPinotFSSpecs(List.of()); | ||
| PushJobSpec pushSpec = new PushJobSpec(); | ||
| pushSpec.setPushParallelism(2); | ||
| pushSpec.setPushFileNamePattern("glob:**/current/*.tar.gz"); | ||
| spec.setPushJobSpec(pushSpec); | ||
| List<List<String>> pushed = new ArrayList<>(); | ||
| IngestionJobRunner runner = switch (mode) { | ||
| case "metadata" -> new BaseSparkSegmentMetadataPushJobRunner(spec) { | ||
| @Override | ||
| public void parallelizeMetadataPushJob(List<String> segments, List<PinotFSSpec> fileSystems, | ||
| int parallelism, URI output) { | ||
| pushed.add(List.copyOf(segments)); | ||
| } | ||
| }; | ||
| case "tar" -> new BaseSparkSegmentTarPushJobRunner(spec) { | ||
| @Override | ||
| public void parallelizeTarPushJob(List<PinotFSSpec> fileSystems, List<String> segments, | ||
| int parallelism, URI output) { | ||
| pushed.add(List.copyOf(segments)); | ||
| } | ||
| }; | ||
| case "uri" -> new BaseSparkSegmentUriPushJobRunner(spec) { | ||
| @Override | ||
| public void parallelizeUriPushJob(List<PinotFSSpec> fileSystems, List<String> segments, int parallelism) { | ||
| pushed.add(List.copyOf(segments)); | ||
| } | ||
| }; | ||
| default -> throw new IllegalArgumentException(mode); | ||
| }; | ||
| List<List<String>> selectedPaths = List.of( | ||
| List.of(mode.equals("uri") ? selected.toFile().toURI().toString() : selected.toString())); | ||
| runner.run(); | ||
| assertEquals(pushed, selectedPaths); | ||
| pushSpec.setPushParallelism(0); | ||
| pushSpec.setPushFileNamePattern("glob:**/missing/*"); | ||
| runner.run(); | ||
| assertEquals(pushed, selectedPaths); | ||
| pushSpec.setPushFileNamePattern(null); | ||
| assertThrows(IllegalArgumentException.class, runner::run); | ||
| assertEquals(pushed, selectedPaths); | ||
| } finally { | ||
| FileUtils.deleteDirectory(outputDir.toFile()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.