Skip to content
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

[ADAM-1164] Add parallel file merger. #1441

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 44 additions & 24 deletions adam-core/src/main/scala/org/bdgenomics/adam/rdd/FileMerger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import htsjdk.samtools.cram.common.CramVersions
import java.io.{ InputStream, OutputStream }
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{ FileSystem, Path }
import org.apache.spark.SparkContext
import org.bdgenomics.utils.misc.Logging
import scala.annotation.tailrec

/**
* Helper object to merge sharded files together.
*
* @see ParallelFileMerger
*/
object FileMerger extends Logging {
private[adam] object FileMerger extends Logging {

/**
* The config entry for the buffer size in bytes.
Expand All @@ -39,6 +42,9 @@ object FileMerger extends Logging {
/**
* Merges together sharded files, while preserving partition ordering.
*
* Automatically checks to see if the filesystem is HDFS, and if so, uses the
* parallel file merging implementation to concatenate files.
*
* @param fs The file system implementation to use.
* @param outputPath The location to write the merged file at.
* @param tailPath The location where the sharded files have been written.
Expand All @@ -53,20 +59,34 @@ object FileMerger extends Logging {
*
* @see mergeFilesAcrossFilesystems
*/
private[adam] def mergeFiles(conf: Configuration,
fs: FileSystem,
outputPath: Path,
tailPath: Path,
optHeaderPath: Option[Path] = None,
writeEmptyGzipBlock: Boolean = false,
writeCramEOF: Boolean = false,
optBufferSize: Option[Int] = None) {
mergeFilesAcrossFilesystems(conf,
fs, fs,
outputPath, tailPath, optHeaderPath = optHeaderPath,
writeEmptyGzipBlock = writeEmptyGzipBlock,
writeCramEOF = writeCramEOF,
optBufferSize = optBufferSize)
def mergeFiles(sc: SparkContext,
fs: FileSystem,
outputPath: Path,
tailPath: Path,
optHeaderPath: Option[Path] = None,
writeEmptyGzipBlock: Boolean = false,
writeCramEOF: Boolean = false,
optBufferSize: Option[Int] = None) {

// if our file system is an hdfs mount, we can use the parallel merger
if (fs.getScheme == "hdfs") {
ParallelFileMerger.mergeFiles(sc,
outputPath,
tailPath,
optHeaderPath = optHeaderPath,
writeEmptyGzipBlock = writeEmptyGzipBlock,
writeCramEOF = writeCramEOF,
optBufferSize = optBufferSize)
} else {
mergeFilesAcrossFilesystems(sc.hadoopConfiguration,
fs, fs,
outputPath,
tailPath,
optHeaderPath = optHeaderPath,
writeEmptyGzipBlock = writeEmptyGzipBlock,
writeCramEOF = writeCramEOF,
optBufferSize = optBufferSize)
}
}

/**
Expand All @@ -87,15 +107,15 @@ object FileMerger extends Logging {
* not set, we check the config for this value. If that is not set, we
* default to 4MB.
*/
private[adam] def mergeFilesAcrossFilesystems(conf: Configuration,
fsIn: FileSystem,
fsOut: FileSystem,
outputPath: Path,
tailPath: Path,
optHeaderPath: Option[Path] = None,
writeEmptyGzipBlock: Boolean = false,
writeCramEOF: Boolean = false,
optBufferSize: Option[Int] = None) {
def mergeFilesAcrossFilesystems(conf: Configuration,
fsIn: FileSystem,
fsOut: FileSystem,
outputPath: Path,
tailPath: Path,
optHeaderPath: Option[Path] = None,
writeEmptyGzipBlock: Boolean = false,
writeCramEOF: Boolean = false,
optBufferSize: Option[Int] = None) {

// check for buffer size in option, if not in option, check hadoop conf,
// if not in hadoop conf, fall back on 4MB
Expand Down
Loading