Skip to content

Commit 85c8938

Browse files
committed
Removed useless results.put for fail fast
1 parent e8713cc commit 85c8938

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

core/src/main/scala/org/apache/spark/storage/BlockFetcherIterator.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,18 @@ object BlockFetcherIterator {
199199
// Get the local blocks while remote blocks are being fetched. Note that it's okay to do
200200
// these all at once because they will just memory-map some files, so they won't consume
201201
// any memory that might exceed our maxBytesInFlight
202-
var fetchIndex = 0
203-
try {
204-
for (id <- localBlocksToFetch) {
205-
202+
for (id <- localBlocksToFetch) {
203+
try {
206204
// getLocalFromDisk never return None but throws BlockException
207205
val iter = getLocalFromDisk(id, serializer).get
208206
// Pass 0 as size since it's not in flight
209207
results.put(new FetchResult(id, 0, () => iter))
210-
fetchIndex += 1
211208
logDebug("Got local block " + id)
212-
}
213-
} catch {
214-
case e: Exception => {
215-
logError(s"Error occurred while fetching local blocks", e)
216-
for (id <- localBlocksToFetch.drop(fetchIndex)) {
209+
} catch {
210+
case e: Exception => {
211+
logError(s"Error occurred while fetching local blocks", e)
217212
results.put(new FetchResult(id, -1, null))
213+
return
218214
}
219215
}
220216
}

core/src/test/scala/org/apache/spark/storage/BlockFetcherIteratorSuite.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@ class BlockFetcherIteratorSuite extends FunSuite with Matchers {
8181
assert(iterator.next._2.isDefined, "2nd element should be defined but is not actually defined")
8282
assert(iterator.hasNext, "iterator should have 5 elements but actually has 2 elements")
8383
// 3rd fetch should be failed
84-
assert(!iterator.next._2.isDefined, "3nd element should not be defined but is actually defined")
84+
assert(!iterator.next._2.isDefined, "3rd element should not be defined but is actually defined")
8585
assert(iterator.hasNext, "iterator should have 5 elements but actually has 3 elements")
86-
// And then, all of local fetches should be failed
87-
assert(!iterator.next._2.isDefined, "Rest of elements after non-defined element should not be defined " +
88-
"but 4th element is actually defined")
89-
assert(iterator.hasNext, "iterator should have 5 elements but actually has 4 elements")
90-
assert(!iterator.next._2.isDefined, "Rest of elements after non-defined element should not be defined " +
91-
"but 5th element is actually defined")
86+
// Don't call next() after fetching non-defined element even if thare are rest of elements in the iterator.
87+
// Otherwise, BasicBlockFetcherIterator hangs up.
9288
}
9389

9490

0 commit comments

Comments
 (0)