-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-897: preemptively serialize closures #143
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ed2ccf0
Test cases for SPARK-897.
willb 5bfff24
Adds proactive closure-serializablilty checking
willb abe816b
Make proactive serializability checking optional.
willb be1ecd6
Don't check serializability of DStream transforms.
willb b215dea
Fixed spurious failures in ImplicitOrderingSuite
willb 3b3f74a
Stylistic and doc cleanups.
willb 64d04d2
FailureSuite now checks both messages and causes.
willb bceab8a
Commented DStream corner cases for serializability checking.
willb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Test cases for SPARK-897.
Tests to make sure that passing an unserializable closure to a transformation fails fast.
- Loading branch information
commit ed2ccf05be7613611d80e2e4b95fd3aec79134b8
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
core/src/test/scala/org/apache/spark/serializer/ProactiveClosureSerializationSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.serializer; | ||
|
|
||
| import java.io.NotSerializableException | ||
|
|
||
| import org.scalatest.FunSuite | ||
|
|
||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.SparkException | ||
| import org.apache.spark.SharedSparkContext | ||
|
|
||
| /* A trivial (but unserializable) container for trivial functions */ | ||
| class UnserializableClass { | ||
| def op[T](x: T) = x.toString | ||
|
|
||
| def pred[T](x: T) = x.toString.length % 2 == 0 | ||
| } | ||
|
|
||
| class ProactiveClosureSerializationSuite extends FunSuite with SharedSparkContext { | ||
|
|
||
| def fixture = (sc.parallelize(0 until 1000).map(_.toString), new UnserializableClass) | ||
|
|
||
| test("throws expected serialization exceptions on actions") { | ||
| val (data, uc) = fixture | ||
|
|
||
| val ex = intercept[SparkException] { | ||
| data.map(uc.op(_)).count | ||
| } | ||
|
|
||
| assert(ex.getMessage.contains("Task not serializable")) | ||
| } | ||
|
|
||
| // There is probably a cleaner way to eliminate boilerplate here, but we're | ||
| // iterating over a map from transformation names to functions that perform that | ||
| // transformation on a given RDD, creating one test case for each | ||
|
|
||
| for (transformation <- | ||
| Map("map" -> xmap _, "flatMap" -> xflatMap _, "filter" -> xfilter _, "mapWith" -> xmapWith _, | ||
| "mapPartitions" -> xmapPartitions _, "mapPartitionsWithIndex" -> xmapPartitionsWithIndex _, | ||
| "mapPartitionsWithContext" -> xmapPartitionsWithContext _, "filterWith" -> xfilterWith _)) { | ||
| val (name, xf) = transformation | ||
|
|
||
| test(s"$name transformations throw proactive serialization exceptions") { | ||
| val (data, uc) = fixture | ||
|
|
||
| val ex = intercept[SparkException] { | ||
| xf(data, uc) | ||
| } | ||
|
|
||
| assert(ex.getMessage.contains("Task not serializable"), s"RDD.$name doesn't proactively throw NotSerializableException") | ||
| } | ||
| } | ||
|
|
||
| private def xmap(x: RDD[String], uc: UnserializableClass): RDD[String] = x.map(y=>uc.op(y)) | ||
| private def xmapWith(x: RDD[String], uc: UnserializableClass): RDD[String] = x.mapWith(x => x.toString)((x,y)=>x + uc.op(y)) | ||
| private def xflatMap(x: RDD[String], uc: UnserializableClass): RDD[String] = x.flatMap(y=>Seq(uc.op(y))) | ||
| private def xfilter(x: RDD[String], uc: UnserializableClass): RDD[String] = x.filter(y=>uc.pred(y)) | ||
| private def xfilterWith(x: RDD[String], uc: UnserializableClass): RDD[String] = x.filterWith(x => x.toString)((x,y)=>uc.pred(y)) | ||
| private def xmapPartitions(x: RDD[String], uc: UnserializableClass): RDD[String] = x.mapPartitions(_.map(y=>uc.op(y))) | ||
| private def xmapPartitionsWithIndex(x: RDD[String], uc: UnserializableClass): RDD[String] = x.mapPartitionsWithIndex((_, it) => it.map(y=>uc.op(y))) | ||
| private def xmapPartitionsWithContext(x: RDD[String], uc: UnserializableClass): RDD[String] = x.mapPartitionsWithContext((_, it) => it.map(y=>uc.op(y))) | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is longer than 100 chars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the following functions too