forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-35276][CORE] Calculate checksum for shuffle data and write as …
…checksum file This is the initial work of add checksum support of shuffle. This is a piece of apache#32385. And this PR only adds checksum functionality at the shuffle writer side. Basically, the idea is to wrap a `MutableCheckedOutputStream`* upon the `FileOutputStream` while the shuffle writer generating the shuffle data. But the specific wrapping places are a bit different among the shuffle writers due to their different implementation: * `BypassMergeSortShuffleWriter` - wrap on each partition file * `UnsafeShuffleWriter` - wrap on each spill files directly since they doesn't require aggregation, sorting * `SortShuffleWriter` - wrap on the `ShufflePartitionPairsWriter` after merged spill files since they might require aggregation, sorting \* `MutableCheckedOutputStream` is a variant of `java.util.zip.CheckedOutputStream` which can change the checksum calculator at runtime. And we use the `Adler32`, which uses the CRC-32 algorithm but much faster, to calculate the checksum as the same as `Broadcast`'s checksum. Yes, added a new conf: `spark.shuffle.checksum`. Added unit tests. Closes apache#32401 from Ngone51/add-checksum-files. Authored-by: yi.wu <yi.wu@databricks.com> Signed-off-by: Mridul Muralidharan <mridul<at>gmail.com> (cherry picked from commit 4783fb7) Signed-off-by: Mridul Muralidharan <mridulatgmail.com>
- Loading branch information
Showing
25 changed files
with
785 additions
and
106 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
100 changes: 100 additions & 0 deletions
100
core/src/main/java/org/apache/spark/shuffle/checksum/ShuffleChecksumHelper.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,100 @@ | ||
/* | ||
* 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.spark.shuffle.checksum; | ||
|
||
import java.util.zip.Adler32; | ||
import java.util.zip.CRC32; | ||
import java.util.zip.Checksum; | ||
|
||
import org.apache.spark.SparkConf; | ||
import org.apache.spark.SparkException; | ||
import org.apache.spark.annotation.Private; | ||
import org.apache.spark.internal.config.package$; | ||
import org.apache.spark.storage.ShuffleChecksumBlockId; | ||
|
||
/** | ||
* A set of utility functions for the shuffle checksum. | ||
*/ | ||
@Private | ||
public class ShuffleChecksumHelper { | ||
|
||
/** Used when the checksum is disabled for shuffle. */ | ||
private static final Checksum[] EMPTY_CHECKSUM = new Checksum[0]; | ||
public static final long[] EMPTY_CHECKSUM_VALUE = new long[0]; | ||
|
||
public static boolean isShuffleChecksumEnabled(SparkConf conf) { | ||
return (boolean) conf.get(package$.MODULE$.SHUFFLE_CHECKSUM_ENABLED()); | ||
} | ||
|
||
public static Checksum[] createPartitionChecksumsIfEnabled(int numPartitions, SparkConf conf) | ||
throws SparkException { | ||
if (!isShuffleChecksumEnabled(conf)) { | ||
return EMPTY_CHECKSUM; | ||
} | ||
|
||
String checksumAlgo = shuffleChecksumAlgorithm(conf); | ||
return getChecksumByAlgorithm(numPartitions, checksumAlgo); | ||
} | ||
|
||
private static Checksum[] getChecksumByAlgorithm(int num, String algorithm) | ||
throws SparkException { | ||
Checksum[] checksums; | ||
switch (algorithm) { | ||
case "ADLER32": | ||
checksums = new Adler32[num]; | ||
for (int i = 0; i < num; i ++) { | ||
checksums[i] = new Adler32(); | ||
} | ||
return checksums; | ||
|
||
case "CRC32": | ||
checksums = new CRC32[num]; | ||
for (int i = 0; i < num; i ++) { | ||
checksums[i] = new CRC32(); | ||
} | ||
return checksums; | ||
|
||
default: | ||
throw new SparkException("Unsupported shuffle checksum algorithm: " + algorithm); | ||
} | ||
} | ||
|
||
public static long[] getChecksumValues(Checksum[] partitionChecksums) { | ||
int numPartitions = partitionChecksums.length; | ||
long[] checksumValues = new long[numPartitions]; | ||
for (int i = 0; i < numPartitions; i ++) { | ||
checksumValues[i] = partitionChecksums[i].getValue(); | ||
} | ||
return checksumValues; | ||
} | ||
|
||
public static String shuffleChecksumAlgorithm(SparkConf conf) { | ||
return conf.get(package$.MODULE$.SHUFFLE_CHECKSUM_ALGORITHM()); | ||
} | ||
|
||
public static Checksum getChecksumByFileExtension(String fileName) throws SparkException { | ||
int index = fileName.lastIndexOf("."); | ||
String algorithm = fileName.substring(index + 1); | ||
return getChecksumByAlgorithm(1, algorithm)[0]; | ||
} | ||
|
||
public static String getChecksumFileName(ShuffleChecksumBlockId blockId, SparkConf conf) { | ||
// append the shuffle checksum algorithm as the file extension | ||
return String.format("%s.%s", blockId.name(), shuffleChecksumAlgorithm(conf)); | ||
} | ||
} |
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
Oops, something went wrong.