Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
ffa5f8e1
Commit
ffa5f8e1
authored
11 years ago
by
jerryshao
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue when local properties pass from parent to child thread
parent
2aff7989
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/src/main/scala/org/apache/spark/SparkContext.scala
+5
-1
5 additions, 1 deletion
core/src/main/scala/org/apache/spark/SparkContext.scala
core/src/test/scala/org/apache/spark/ThreadingSuite.scala
+37
-1
37 additions, 1 deletion
core/src/test/scala/org/apache/spark/ThreadingSuite.scala
with
42 additions
and
2 deletions
core/src/main/scala/org/apache/spark/SparkContext.scala
+
5
−
1
View file @
ffa5f8e1
...
...
@@ -256,7 +256,9 @@ class SparkContext(
private
[
spark
]
var
checkpointDir
:
Option
[
String
]
=
None
// Thread Local variable that can be used by users to pass information down the stack
private
val
localProperties
=
new
ThreadLocal
[
Properties
]
private
val
localProperties
=
new
InheritableThreadLocal
[
Properties
]
{
override
protected
def
childValue
(
parent
:
Properties
)
:
Properties
=
new
Properties
(
parent
)
}
def
initLocalProperties
()
{
localProperties
.
set
(
new
Properties
())
...
...
@@ -273,6 +275,8 @@ class SparkContext(
}
}
def
getLocalProperty
(
key
:
String
)
:
String
=
Option
(
localProperties
.
get
).
map
(
_
.
getProperty
(
key
)).
getOrElse
(
null
)
/** Set a human readable description of the current job. */
def
setJobDescription
(
value
:
String
)
{
setLocalProperty
(
SparkContext
.
SPARK_JOB_DESCRIPTION
,
value
)
...
...
This diff is collapsed.
Click to expand it.
core/src/test/scala/org/apache/spark/ThreadingSuite.scala
+
37
−
1
View file @
ffa5f8e1
...
...
@@ -40,7 +40,7 @@ object ThreadingSuiteState {
}
class
ThreadingSuite
extends
FunSuite
with
LocalSparkContext
{
test
(
"accessing SparkContext form a different thread"
)
{
sc
=
new
SparkContext
(
"local"
,
"test"
)
val
nums
=
sc
.
parallelize
(
1
to
10
,
2
)
...
...
@@ -149,4 +149,40 @@ class ThreadingSuite extends FunSuite with LocalSparkContext {
fail
(
"One or more threads didn't see runningThreads = 4"
)
}
}
test
(
"set local properties in different thread"
)
{
sc
=
new
SparkContext
(
"local"
,
"test"
)
val
threads
=
(
1
to
5
).
map
{
i
=>
new
Thread
()
{
override
def
run
()
{
sc
.
setLocalProperty
(
"test"
,
i
.
toString
)
assert
(
sc
.
getLocalProperty
(
"test"
)
===
i
.
toString
)
}
}
}
threads
.
foreach
(
_
.
start
())
assert
(
sc
.
getLocalProperty
(
"test"
)
===
null
)
}
test
(
"set and get local properties in parent-children thread"
)
{
sc
=
new
SparkContext
(
"local"
,
"test"
)
sc
.
setLocalProperty
(
"test"
,
"parent"
)
val
threads
=
(
1
to
5
).
map
{
i
=>
new
Thread
()
{
override
def
run
()
{
assert
(
sc
.
getLocalProperty
(
"test"
)
===
"parent"
)
sc
.
setLocalProperty
(
"test"
,
i
.
toString
)
assert
(
sc
.
getLocalProperty
(
"test"
)
===
i
.
toString
)
}
}
}
threads
.
foreach
(
_
.
start
())
assert
(
sc
.
getLocalProperty
(
"test"
)
===
"parent"
)
assert
(
sc
.
getLocalProperty
(
"Foo"
)
===
null
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment