You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by aarondav <gi...@git.apache.org> on 2014/07/31 04:01:03 UTC

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

GitHub user aarondav opened a pull request:

    https://github.com/apache/spark/pull/1678

    SPARK-2532: Minimal shuffle consolidation fixes

    All changes from this PR are by @mridulm and are drawn from his work in #1609. This patch is intended to fix all major issues related to shuffle file consolidation that @mridulm found, while minimizing changes to the code, with the hope that it may be more easily merged into 1.1.
    
    This patch is **not** intended as a replacement for #1609, which provides many additional benefits, including fixes to ExternalAppendOnlyMap, improvements to DiskBlockObjectWriter's API, and several new unit tests.
    
    If it is feasible to merge #1609 for the 1.1 deadline, that is a preferable option.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aarondav/spark consol

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/1678.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1678
    
----
commit f298ac92f7df30f53636fca874c8bc6ed764af19
Author: Aaron Davidson <aa...@databricks.com>
Date:   2014-07-28T19:02:24Z

    SPARK-2532: Minimal shuffle consolidation fixes
    
    All changes from this PR are by @mridulm and are drawn from his work in #1609.
    This patch is intended to fix all major issues related to shuffle file consolidation
    that @mridulm found, while minimizing changes to the code, with the hope that it may
    be more easily merged into 1.1.
    
    This patch is **not** intended as a replacement for #1609, which provides many
    additional benefits, including fixes to ExternalAppendOnlyMap, improvements to
    DiskBlockObjectWriter's API, and several new unit tests.
    
    If it is feasible to merge #1609 for the 1.1 deadline, that is a preferable option.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2791: Fix committing, reverting and stat...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/1678


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50706164
  
    That's true, this is small enough to add back into branch-1.0 too. We should see if we can do the same for the rest of #1609 too (ideally I would like to merge that whole PR into branch-1.0, but I'm not sure how easy that is).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50705494
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17537/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50718425
  
    Jenkins, retest this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15684100
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
    --- End diff --
    
    Removing close() actually now requires a very minor refactor of ExternalSorter for the `objectsWritten == 0` case -- I'd actually rather not risk it in this PR.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by witgo <gi...@git.apache.org>.
Github user witgo commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50706018
  
    We can also merge it to 1.0 branch.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50704906
  
    QA results for PR 1678:<br>- This patch FAILED unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17535/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50921018
  
    Jenkins, test this please


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50785949
  
    Both prior failures are due to being unable to bind to ports, which sounds like leftover state from other jenkins runs (especially since they were two entirely disjoint sets of failed tests related to port binding).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50930691
  
    @aarondav can you update the name of this PR to reference this sub-task JIRA instead: https://issues.apache.org/jira/browse/SPARK-2791?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50724029
  
    QA results for PR 1678:<br>- This patch FAILED unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17565/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682412
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
         if (initialized) {
           // NOTE: Because Kryo doesn't flush the underlying stream we explicitly flush both the
           //       serializer stream and the lower level stream.
           objOut.flush()
           bs.flush()
    -      val prevPos = lastValidPosition
    -      lastValidPosition = channel.position()
    -      lastValidPosition - prevPos
    -    } else {
    -      // lastValidPosition is zero if stream is uninitialized
    -      lastValidPosition
    +      close()
         }
    +    finalPosition = file.length()
       }
     
    -  override def revertPartialWrites() {
    -    if (initialized) {
    -      // Discard current writes. We do this by flushing the outstanding writes and
    -      // truncate the file to the last valid position.
    -      objOut.flush()
    -      bs.flush()
    -      channel.truncate(lastValidPosition)
    +  // Discard current writes. We do this by flushing the outstanding writes and then
    +  // truncating the file to its initial position.
    +  override def revertPartialWritesAndClose() {
    +    try {
    +      if (initialized) {
    +        objOut.flush()
    +        bs.flush()
    +        close()
    +      }
    +
    +      val truncateStream = new FileOutputStream(file, true)
    +      try {
    +        truncateStream.getChannel.truncate(initialPosition)
    +      } finally {
    +        truncateStream.close()
    +      }
    +    } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while reverting partial writes to file " + file, e)
    --- End diff --
    
    In the use of writers in HashShuffleWriter, it is possible for a closed stream to be reverted (if some other stream's close failed for example).
    In the above, that will leave this file with leftover data - I am not sure what the impact of this would be.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50710747
  
    QA results for PR 1678:<br>- This patch FAILED unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17537/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50793796
  
    QA results for PR 1678:<br>- This patch PASSES unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17585/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2791: Fix committing, reverting and stat...

Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50933685
  
    Alright, going to merge it then. The changes look good to me.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15683224
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
    --- End diff --
    
    When I merged the sort patch, and modified EAOM, it was simply replace close with commitAndClose.
    commitAndClose should be semantically equivalent to close actually.
    It is not equivalent to commit() - but we want to remove that :-)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682389
  
    --- Diff: core/src/main/scala/org/apache/spark/shuffle/hash/HashShuffleWriter.scala ---
    @@ -120,8 +121,7 @@ private[spark] class HashShuffleWriter[K, V](
       private def revertWrites(): Unit = {
         if (shuffle != null && shuffle.writers != null) {
           for (writer <- shuffle.writers) {
    -        writer.revertPartialWrites()
    -        writer.close()
    +        writer.revertPartialWritesAndClose()
    --- End diff --
    
    revert can throw exception : which will cause other writers to not revert.
    We need to wrap it in try/catch, log and continue


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50785966
  
    Jenkins, retest this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15701250
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
         if (initialized) {
           // NOTE: Because Kryo doesn't flush the underlying stream we explicitly flush both the
           //       serializer stream and the lower level stream.
           objOut.flush()
           bs.flush()
    -      val prevPos = lastValidPosition
    -      lastValidPosition = channel.position()
    -      lastValidPosition - prevPos
    -    } else {
    -      // lastValidPosition is zero if stream is uninitialized
    -      lastValidPosition
    +      close()
         }
    +    finalPosition = file.length()
       }
     
    -  override def revertPartialWrites() {
    -    if (initialized) {
    -      // Discard current writes. We do this by flushing the outstanding writes and
    -      // truncate the file to the last valid position.
    -      objOut.flush()
    -      bs.flush()
    -      channel.truncate(lastValidPosition)
    +  // Discard current writes. We do this by flushing the outstanding writes and then
    +  // truncating the file to its initial position.
    +  override def revertPartialWritesAndClose() {
    +    try {
    +      if (initialized) {
    +        objOut.flush()
    +        bs.flush()
    +        close()
    +      }
    +
    +      val truncateStream = new FileOutputStream(file, true)
    +      try {
    +        truncateStream.getChannel.truncate(initialPosition)
    +      } finally {
    +        truncateStream.close()
    +      }
    +    } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while reverting partial writes to file " + file, e)
    --- End diff --
    
    Ah, did not notice that the "if (initialized)" did not include the truncate call !


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2791: Fix committing, reverting and stat...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50932698
  
    Updated title.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50705532
  
    @mridulm Please take a look if possible.
    
    @mateiz This now interacts with the ExternalSorter stuff, and it's possible it partially helps fix a serialization bug (since some serializers apparently write things during a close() after a flush()).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15683958
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
         if (initialized) {
           // NOTE: Because Kryo doesn't flush the underlying stream we explicitly flush both the
           //       serializer stream and the lower level stream.
           objOut.flush()
           bs.flush()
    -      val prevPos = lastValidPosition
    -      lastValidPosition = channel.position()
    -      lastValidPosition - prevPos
    -    } else {
    -      // lastValidPosition is zero if stream is uninitialized
    -      lastValidPosition
    +      close()
         }
    +    finalPosition = file.length()
       }
     
    -  override def revertPartialWrites() {
    -    if (initialized) {
    -      // Discard current writes. We do this by flushing the outstanding writes and
    -      // truncate the file to the last valid position.
    -      objOut.flush()
    -      bs.flush()
    -      channel.truncate(lastValidPosition)
    +  // Discard current writes. We do this by flushing the outstanding writes and then
    +  // truncating the file to its initial position.
    +  override def revertPartialWritesAndClose() {
    +    try {
    +      if (initialized) {
    +        objOut.flush()
    +        bs.flush()
    +        close()
    +      }
    +
    +      val truncateStream = new FileOutputStream(file, true)
    +      try {
    +        truncateStream.getChannel.truncate(initialPosition)
    +      } finally {
    +        truncateStream.close()
    +      }
    +    } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while reverting partial writes to file " + file, e)
    --- End diff --
    
    I'm not certain I understand. The situation I am imagining is that we commit to the first Writer, then the second one fails. In HashShuffleWriter, we will then call revertPartialWritesAndClose() on all Writers, causing us to revert all the changes back to "initialPosition", which should revert even the committed data.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682605
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
    --- End diff --
    
    Absolutely -- I did not do that in this patch because ExternalAppendOnlyMap did a close without a commit, which is a fix outside of the scope of this PR, but definitely one that should be made.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15683205
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
         if (initialized) {
           // NOTE: Because Kryo doesn't flush the underlying stream we explicitly flush both the
           //       serializer stream and the lower level stream.
           objOut.flush()
           bs.flush()
    -      val prevPos = lastValidPosition
    -      lastValidPosition = channel.position()
    -      lastValidPosition - prevPos
    -    } else {
    -      // lastValidPosition is zero if stream is uninitialized
    -      lastValidPosition
    +      close()
         }
    +    finalPosition = file.length()
       }
     
    -  override def revertPartialWrites() {
    -    if (initialized) {
    -      // Discard current writes. We do this by flushing the outstanding writes and
    -      // truncate the file to the last valid position.
    -      objOut.flush()
    -      bs.flush()
    -      channel.truncate(lastValidPosition)
    +  // Discard current writes. We do this by flushing the outstanding writes and then
    +  // truncating the file to its initial position.
    +  override def revertPartialWritesAndClose() {
    +    try {
    +      if (initialized) {
    +        objOut.flush()
    +        bs.flush()
    +        close()
    +      }
    +
    +      val truncateStream = new FileOutputStream(file, true)
    +      try {
    +        truncateStream.getChannel.truncate(initialPosition)
    +      } finally {
    +        truncateStream.close()
    +      }
    +    } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while reverting partial writes to file " + file, e)
    --- End diff --
    
    I meant the former case : close on a writer fails with an exception; while earlier streams succeeded.
    So now we have some writers which have committed data (which is not removed by subsequent revert) while others are reverted.
    
    On the face of it, I agree, it should not cause issues : but then since the expectation from this class is never enforced; and so can silently fail. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50927468
  
    QA results for PR 1678:<br>- This patch PASSES unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17689/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50718818
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17565/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682607
  
    --- Diff: core/src/main/scala/org/apache/spark/shuffle/hash/HashShuffleWriter.scala ---
    @@ -120,8 +121,7 @@ private[spark] class HashShuffleWriter[K, V](
       private def revertWrites(): Unit = {
         if (shuffle != null && shuffle.writers != null) {
           for (writer <- shuffle.writers) {
    -        writer.revertPartialWrites()
    -        writer.close()
    +        writer.revertPartialWritesAndClose()
    --- End diff --
    
    Revert actually doesn't throw, per its (updated) comment.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50704721
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17535/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50718100
  
    QA results for PR 1678:<br>- This patch FAILED unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17553/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50921522
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17689/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by aarondav <gi...@git.apache.org>.
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682590
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
         if (initialized) {
           // NOTE: Because Kryo doesn't flush the underlying stream we explicitly flush both the
           //       serializer stream and the lower level stream.
           objOut.flush()
           bs.flush()
    -      val prevPos = lastValidPosition
    -      lastValidPosition = channel.position()
    -      lastValidPosition - prevPos
    -    } else {
    -      // lastValidPosition is zero if stream is uninitialized
    -      lastValidPosition
    +      close()
         }
    +    finalPosition = file.length()
       }
     
    -  override def revertPartialWrites() {
    -    if (initialized) {
    -      // Discard current writes. We do this by flushing the outstanding writes and
    -      // truncate the file to the last valid position.
    -      objOut.flush()
    -      bs.flush()
    -      channel.truncate(lastValidPosition)
    +  // Discard current writes. We do this by flushing the outstanding writes and then
    +  // truncating the file to its initial position.
    +  override def revertPartialWritesAndClose() {
    +    try {
    +      if (initialized) {
    +        objOut.flush()
    +        bs.flush()
    +        close()
    +      }
    +
    +      val truncateStream = new FileOutputStream(file, true)
    +      try {
    +        truncateStream.getChannel.truncate(initialPosition)
    +      } finally {
    +        truncateStream.close()
    +      }
    +    } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while reverting partial writes to file " + file, e)
    --- End diff --
    
    Closed streams should not inherently throw (since we check `initialized` before flushing and closing). However, we may be left with leftover data, as you said. I don't see a way to prevent the possibility of that occurring, but it should be possible to recover if users only rely on the returned fileSegment().


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50786593
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17585/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1678#issuecomment-50714957
  
    QA tests have started for PR 1678. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17553/consoleFull


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] spark pull request: SPARK-2532: Minimal shuffle consolidation fixe...

Posted by mridulm <gi...@git.apache.org>.
Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1678#discussion_r15682457
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/BlockObjectWriter.scala ---
    @@ -147,28 +147,36 @@ private[spark] class DiskBlockObjectWriter(
     
       override def isOpen: Boolean = objOut != null
     
    -  override def commit(): Long = {
    +  override def commitAndClose(): Unit = {
    --- End diff --
    
    We should remove close from the interface, and make it private to this class btw.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---