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

[SPARK-12887] Do not expose var's in TaskMetrics #10815

Closed
wants to merge 13 commits into from

Conversation

andrewor14
Copy link
Contributor

This is a step in implementing SPARK-10620, which migrates TaskMetrics to accumulators.

TaskMetrics has a bunch of var's, some are fully public, some are private[spark]. This is bad coding style that makes it easy to accidentally overwrite previously set metrics. This has happened a few times in the past and caused bugs that were difficult to debug.

Instead, we should have get-or-create semantics, which are more readily understandable. This makes sense in the case of TaskMetrics because these are just aggregated metrics that we want to collect throughout the task, so it doesn't matter who's incrementing them.

Parent PR: #10717

Andrew Or added 5 commits January 18, 2016 11:54
Note: there's one remaining place, which is JsonProtocol.
JsonProtocol remains the only place where we still call set
on each of the *Metrics classes.
This commit collapsed 10 methods into 2. The 8 that were inlined
were only used in 1 place each, and the body of each was quite
small. The additional level of abstraction did not add much value
and made the code verbose.
@JoshRosen
Copy link
Contributor

This is going to conflict with #10776, so I'd like to merge my patch first.

…etrics

Conflicts:
	core/src/main/scala/org/apache/spark/CacheManager.scala
	core/src/main/scala/org/apache/spark/memory/StorageMemoryPool.scala
	core/src/test/scala/org/apache/spark/CacheManagerSuite.scala
@andrewor14
Copy link
Contributor Author

retest this please

// that one. Otherwise, if the read method is different from the one previously seen by
// this task, we return a new dummy one to avoid clobbering the values of the old metrics.
// In the future we should try to store input metrics from all different read methods at
// the same time (SPARK-5225).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's unfortunate. Since it's a pre-existing problem, it's fine to not fix it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, I guess we'd unconditionally overwrite so we might handle it wrong even for the same read method case? This looks good to me, just curious RE: whether this fixed another bug.

@SparkQA
Copy link

SparkQA commented Jan 18, 2016

Test build #49615 has finished for PR 10815 at commit 34c7ce5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}

self.context.runJob(self, writeToFile)
writer.commitJob()
}

private def initHadoopOutputMetrics(context: TaskContext): (OutputMetrics, Option[() => Long]) = {
// TODO: these don't seem like the right abstractions.
// We should abstract the duplicate code in a less awkward way.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; this is kinda messy.

@JoshRosen
Copy link
Contributor

I'm all finished with my review pass. I have two main pieces of feedback:

  • I think there's some opportunity to clean up the use of multiple Options in PairRDDFunctions, which could help to make the code easier to understand.
  • I have a question RE source/binary compatibility concerns for the changes in `TaskMetrics.

Aside from those things, this looks good.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49622 has finished for PR 10815 at commit e99b9af.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49627 has finished for PR 10815 at commit e99b9af.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49642 has finished for PR 10815 at commit c04b5df.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49646 has finished for PR 10815 at commit 269031f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@JoshRosen
Copy link
Contributor

Okay, so it turns out that I was wrong about the var -> def issue:

scala> class Foo {
     |    var field = 1
     | }
defined class Foo

becomes

scala> :javap -s - Foo
Compiled from "<console>"
public class  {
  public static final  MODULE$;
    descriptor: L;
  public static {};
    descriptor: ()V

  public scala.tools.nsc.interpreter.IMain $intp();
    descriptor: ()Lscala/tools/nsc/interpreter/IMain;

  public ();
    descriptor: ()V
}
Compiled from "<console>"
public class Foo {
  public int field();
    descriptor: ()I

  public void field_$eq(int);
    descriptor: (I)V

  public Foo();
    descriptor: ()V
}

Do you mind rolling back the changes due to that? Sorry about that.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49632 has finished for PR 10815 at commit d2e4e23.

  • This patch fails from timeout after a configured wait of 250m.
  • This patch merges cleanly.
  • This patch adds no public classes.

@andrewor14
Copy link
Contributor Author

retest this please

@JoshRosen
Copy link
Contributor

Uh oh, this merge-conflicted. I'm going to try to fix the conflicts and will submit a PR against your PR. You can on-the-go merge-button it, then I'll retest to get this in.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49657 has finished for PR 10815 at commit 12bd943.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@JoshRosen
Copy link
Contributor

Fixed the conflicts at andrewor14#3

Fix merge conflicts in get-or-create-metrics PR
@andrewor14
Copy link
Contributor Author

retest this please

@JoshRosen
Copy link
Contributor

LGTM, so feel free to merge.

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49665 has finished for PR 10815 at commit bfb3c05.

  • This patch fails from timeout after a configured wait of 250m.
  • This patch merges cleanly.
  • This patch adds no public classes.

@JoshRosen
Copy link
Contributor

Jenkins retest this please

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49687 has finished for PR 10815 at commit bfb3c05.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@andrewor14
Copy link
Contributor Author

Merged into master.

@asfgit asfgit closed this in b122c86 Jan 19, 2016
@andrewor14 andrewor14 deleted the get-or-create-metrics branch January 19, 2016 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants