-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored SparkSegmentMetadataPushJob
- Loading branch information
Showing
8 changed files
with
153 additions
and
94 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
115 changes: 115 additions & 0 deletions
115
.../pinot/plugin/ingestion/batch/spark/common/AbstractSparkSegmentMetadataPushJobRunner.java
This file contains 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,115 @@ | ||
/** | ||
* 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.io.File; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.apache.pinot.segment.local.utils.SegmentPushUtils; | ||
import org.apache.pinot.spi.env.PinotConfiguration; | ||
import org.apache.pinot.spi.filesystem.PinotFS; | ||
import org.apache.pinot.spi.filesystem.PinotFSFactory; | ||
import org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner; | ||
import org.apache.pinot.spi.ingestion.batch.spec.Constants; | ||
import org.apache.pinot.spi.ingestion.batch.spec.PinotFSSpec; | ||
import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec; | ||
import org.apache.pinot.spi.utils.retry.AttemptsExceededException; | ||
import org.apache.pinot.spi.utils.retry.RetriableOperationException; | ||
|
||
|
||
public abstract class AbstractSparkSegmentMetadataPushJobRunner implements IngestionJobRunner, Serializable { | ||
protected SegmentGenerationJobSpec _spec; | ||
|
||
public AbstractSparkSegmentMetadataPushJobRunner() { | ||
} | ||
|
||
public AbstractSparkSegmentMetadataPushJobRunner(SegmentGenerationJobSpec spec) { | ||
init(spec); | ||
} | ||
|
||
@Override | ||
public void init(SegmentGenerationJobSpec spec) { | ||
_spec = spec; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
//init all file systems | ||
List<PinotFSSpec> pinotFSSpecs = _spec.getPinotFSSpecs(); | ||
for (PinotFSSpec pinotFSSpec : pinotFSSpecs) { | ||
PinotFSFactory.register(pinotFSSpec.getScheme(), pinotFSSpec.getClassName(), new PinotConfiguration(pinotFSSpec)); | ||
} | ||
|
||
//Get outputFS for writing output pinot segments | ||
URI outputDirURI; | ||
try { | ||
outputDirURI = new URI(_spec.getOutputDirURI()); | ||
if (outputDirURI.getScheme() == null) { | ||
outputDirURI = new File(_spec.getOutputDirURI()).toURI(); | ||
} | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException("outputDirURI is not valid - '" + _spec.getOutputDirURI() + "'"); | ||
} | ||
PinotFS outputDirFS = PinotFSFactory.create(outputDirURI.getScheme()); | ||
//Get list of files to process | ||
String[] files; | ||
try { | ||
files = outputDirFS.listFiles(outputDirURI, true); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to list all files under outputDirURI - '" + outputDirURI + "'"); | ||
} | ||
|
||
List<String> segmentsToPush = new ArrayList<>(); | ||
for (String file : files) { | ||
if (file.endsWith(Constants.TAR_GZ_FILE_EXT)) { | ||
segmentsToPush.add(file); | ||
} | ||
} | ||
|
||
int pushParallelism = _spec.getPushJobSpec().getPushParallelism(); | ||
if (pushParallelism < 1) { | ||
pushParallelism = segmentsToPush.size(); | ||
} | ||
if (pushParallelism == 1) { | ||
// Push from driver | ||
try { | ||
SegmentPushUtils.pushSegments(_spec, outputDirFS, segmentsToPush); | ||
} catch (RetriableOperationException | AttemptsExceededException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
parallelizeMetadataPushJob(segmentsToPush, pinotFSSpecs, pushParallelism, outputDirURI); | ||
} | ||
} | ||
|
||
/** | ||
* Parallelizes the metadata push job using Spark to distribute the work across multiple nodes. | ||
* | ||
* @param segmentsToPush the list of segment URIs to be pushed | ||
* @param pinotFSSpecs the list of Pinot file system specifications to be registered | ||
* @param pushParallelism the level of parallelism for the push job | ||
* @param outputDirURI the URI of the output directory containing the segments | ||
*/ | ||
public abstract void parallelizeMetadataPushJob(List<String> segmentsToPush, List<PinotFSSpec> pinotFSSpecs, | ||
int pushParallelism, URI outputDirURI); | ||
} |
This file contains 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 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