Github user pwendell commented on a diff in the pull request:
https://github.com/apache/spark/pull/2087#discussion_r19382961
--- Diff: core/src/main/scala/org/apache/spark/rdd/HadoopRDD.scala ---
@@ -224,18 +223,18 @@ class HadoopRDD[K, V](
val key: K = reader.createKey()
val value: V = reader.createValue()
- // Set the task input metrics.
val inputMetrics = new InputMetrics(DataReadMethod.Hadoop)
- try {
- /* bytesRead may not exactly equal the bytes read by a task: split
boundaries aren't
- * always at record boundaries, so tasks may need to read into
other splits to complete
- * a record. */
- inputMetrics.bytesRead = split.inputSplit.value.getLength()
- } catch {
- case e: java.io.IOException =>
- logWarning("Unable to get input size to set InputMetrics for
task", e)
+ // Find a function that will return the FileSystem bytes read by
this thread.
+ val bytesReadCallback = if
(split.inputSplit.value.isInstanceOf[FileSplit]) {
+ SparkHadoopUtil.get.getFSBytesReadOnThreadCallback(
+ split.inputSplit.value.asInstanceOf[FileSplit].getPath, jobConf)
+ } else {
+ None
+ }
+ if (bytesReadCallback.isDefined) {
+ context.taskMetrics.inputMetrics = Some(inputMetrics)
}
- context.taskMetrics.inputMetrics = Some(inputMetrics)
--- End diff --
Is there a reason why we can't just set the input metrics (this line) here
in both cases? In the case where we can't get the read callback, we just do
this exact thing further down. Is there a reason why you can't just make the
assignment here and just update the `bytesRead` below?
In fact, would it be possible to just do this at the beginning of the
function:
```
context.taskMetrics.inputMetrics = new InputMetrics(DataReadMethod.Hadoop)
```
and not have a `val inputMetrics` here? Then we could just always access
`context.taskMetrics` in the code and we'd just have one code path for
accessing this.
---
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]