Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/9610#discussion_r44745040
--- Diff:
core/src/main/scala/org/apache/spark/shuffle/IndexShuffleBlockResolver.scala ---
@@ -75,13 +81,68 @@ private[spark] class IndexShuffleBlockResolver(conf:
SparkConf) extends ShuffleB
}
/**
+ * Check whether there are index file and data file also they are
matched with each other, returns
+ * the lengths of each block in data file, if there are matched, or
return null.
+ */
+ private def checkIndexAndDataFile(index: File, data: File, blocks: Int):
Array[Long] = {
+ val lengths = new Array[Long](blocks)
+ if (index.length() == (blocks + 1) * 8) {
+ // Read the lengths of blocks
+ val f = try {
+ new FileInputStream(index)
+ } catch {
+ case e: IOException =>
+ return null
+ }
+ val in = new DataInputStream(new BufferedInputStream(f))
+ try {
+ // Convert the offsets into lengths of each block
+ var offset = in.readLong()
+ if (offset != 0L) {
+ return null
+ }
+ var i = 0
+ while (i < blocks) {
+ val off = in.readLong()
+ lengths(i) = off - offset
+ offset = off
+ i += 1
+ }
+ } catch {
+ case e: IOException =>
+ return null
+ } finally {
+ in.close()
+ }
+
+ val size = lengths.reduce(_ + _)
+ // `length` returns 0 if it not exists.
+ if (data.length() == size) {
+ lengths
+ } else {
+ null
+ }
+ } else {
+ null
+ }
+ }
+
+ /**
* Write an index file with the offsets of each block, plus a final
offset at the end for the
* end of the output file. This will be used by getBlockData to figure
out where each block
* begins and ends.
+ *
+ * It will commit the data and index file as an atomic operation, use
the existed ones (lengths of
+ * blocks will be refreshed), or replace them with new ones.
--- End diff --
we should add that this modifies the contents of `lengths` if existing data
and index files exist and are matching.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]