-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-44993][CORE] Add ShuffleChecksumUtils.compareChecksums by reusing ShuffleChecksumTestHelp.compareChecksums
#42707
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
Closed
Changes from all commits
Commits
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
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
core/src/main/scala/org/apache/spark/shuffle/ShuffleChecksumUtils.scala
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,80 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import java.io.{DataInputStream, File, FileInputStream} | ||
| import java.util.zip.CheckedInputStream | ||
|
|
||
| import org.apache.spark.network.shuffle.checksum.ShuffleChecksumHelper | ||
| import org.apache.spark.network.util.LimitedInputStream | ||
|
|
||
| object ShuffleChecksumUtils { | ||
|
|
||
| /** | ||
| * Ensure that the checksum values are consistent with index file and data file. | ||
| */ | ||
| def compareChecksums( | ||
| numPartition: Int, | ||
| algorithm: String, | ||
| checksum: File, | ||
| data: File, | ||
| index: File): Boolean = { | ||
| var checksumIn: DataInputStream = null | ||
| val expectChecksums = Array.ofDim[Long](numPartition) | ||
| try { | ||
| checksumIn = new DataInputStream(new FileInputStream(checksum)) | ||
| (0 until numPartition).foreach(i => expectChecksums(i) = checksumIn.readLong()) | ||
| } finally { | ||
| if (checksumIn != null) { | ||
| checksumIn.close() | ||
| } | ||
| } | ||
|
|
||
| var dataIn: FileInputStream = null | ||
| var indexIn: DataInputStream = null | ||
| var checkedIn: CheckedInputStream = null | ||
| try { | ||
| dataIn = new FileInputStream(data) | ||
| indexIn = new DataInputStream(new FileInputStream(index)) | ||
| var prevOffset = indexIn.readLong | ||
| (0 until numPartition).foreach { i => | ||
| val curOffset = indexIn.readLong | ||
| val limit = (curOffset - prevOffset).toInt | ||
| val bytes = new Array[Byte](limit) | ||
| val checksumCal = ShuffleChecksumHelper.getChecksumByAlgorithm(algorithm) | ||
| checkedIn = new CheckedInputStream( | ||
| new LimitedInputStream(dataIn, curOffset - prevOffset), checksumCal) | ||
| checkedIn.read(bytes, 0, limit) | ||
| prevOffset = curOffset | ||
| // checksum must be consistent at both write and read sides | ||
| if (checkedIn.getChecksum.getValue != expectChecksums(i)) return false | ||
| } | ||
| } finally { | ||
| if (dataIn != null) { | ||
| dataIn.close() | ||
| } | ||
| if (indexIn != null) { | ||
| indexIn.close() | ||
| } | ||
| if (checkedIn != null) { | ||
| checkedIn.close() | ||
| } | ||
| } | ||
| true | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put this into
ShuffleChecksumHelper?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShuffleChecksumHelperistestcode helper undertest/scala/.... So we can not reuse it in the main code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I meant
ShuffleChecksumHelpernotShuffleChecksumTestHelper.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I misread that.
BTW, I also considered that but I decided not to do because it's
Javaclass which means we need to re-implement the whole logic. I guess you also suggested a moving fromScalatoScalacode, notScalatoJava. Or, did you suggest to reimplement withJava?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. No, I didn't realized that
ShuffleChecksumHelperis Java code. Thanks for reply.