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
dc47084f
Commit
dc47084f
authored
11 years ago
by
Mridul Muralidharan
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to fix bug reported in PR 791 : a race condition in ConnectionManager and Connection
parent
5133e4be
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/src/main/scala/spark/network/Connection.scala
+36
-6
36 additions, 6 deletions
core/src/main/scala/spark/network/Connection.scala
core/src/main/scala/spark/network/ConnectionManager.scala
+2
-1
2 additions, 1 deletion
core/src/main/scala/spark/network/ConnectionManager.scala
with
38 additions
and
7 deletions
core/src/main/scala/spark/network/Connection.scala
+
36
−
6
View file @
dc47084f
...
...
@@ -45,12 +45,15 @@ abstract class Connection(val channel: SocketChannel, val selector: Selector,
channel
.
socket
.
setKeepAlive
(
true
)
/*channel.socket.setReceiveBufferSize(32768) */
@volatile
private
var
closed
=
false
var
onCloseCallback
:
Connection
=>
Unit
=
null
var
onExceptionCallback
:
(
Connection
,
Exception
)
=>
Unit
=
null
var
onKeyInterestChangeCallback
:
(
Connection
,
Int
)
=>
Unit
=
null
val
remoteAddress
=
getRemoteAddress
()
def
resetForceReregister
()
:
Boolean
// Read channels typically do not register for write and write does not for read
// Now, we do have write registering for read too (temporarily), but this is to detect
// channel close NOT to actually read/consume data on it !
...
...
@@ -95,6 +98,7 @@ abstract class Connection(val channel: SocketChannel, val selector: Selector,
}
def
close
()
{
closed
=
true
val
k
=
key
()
if
(
k
!=
null
)
{
k
.
cancel
()
...
...
@@ -103,6 +107,8 @@ abstract class Connection(val channel: SocketChannel, val selector: Selector,
callOnCloseCallback
()
}
protected
def
isClosed
:
Boolean
=
closed
def
onClose
(
callback
:
Connection
=>
Unit
)
{
onCloseCallback
=
callback
}
...
...
@@ -168,7 +174,7 @@ class SendingConnection(val address: InetSocketAddress, selector_ : Selector,
remoteId_
:
ConnectionManagerId
)
extends
Connection
(
SocketChannel
.
open
,
selector_
,
remoteId_
)
{
class
Outbox
(
fair
:
Int
=
0
)
{
private
class
Outbox
(
fair
:
Int
=
0
)
{
val
messages
=
new
Queue
[
Message
]()
val
defaultChunkSize
=
65536
//32768 //16384
var
nextMessageToBeUsed
=
0
...
...
@@ -246,6 +252,13 @@ class SendingConnection(val address: InetSocketAddress, selector_ : Selector,
}
private
val
outbox
=
new
Outbox
(
1
)
/*
This is orthogonal to whether we have pending bytes to write or not - and satisfies a slightly different purpose.
This flag is to see if we need to force reregister for write even when we do not have any pending bytes to write to socket.
This can happen due to a race between adding pending buffers, and checking for existing of data as detailed in
https://github.com/mesos/spark/pull/791#issuecomment-22294729
*/
private
var
needForceReregister
=
false
val
currentBuffers
=
new
ArrayBuffer
[
ByteBuffer
]()
/*channel.socket.setSendBufferSize(256 * 1024)*/
...
...
@@ -267,9 +280,19 @@ class SendingConnection(val address: InetSocketAddress, selector_ : Selector,
def
send
(
message
:
Message
)
{
outbox
.
synchronized
{
outbox
.
addMessage
(
message
)
if
(
channel
.
isConnected
)
{
registerInterest
()
}
needForceReregister
=
true
}
if
(
channel
.
isConnected
)
{
registerInterest
()
}
}
// return previous value after resetting it.
def
resetForceReregister
()
:
Boolean
=
{
outbox
.
synchronized
{
val
result
=
needForceReregister
needForceReregister
=
false
result
}
}
...
...
@@ -322,7 +345,10 @@ class SendingConnection(val address: InetSocketAddress, selector_ : Selector,
outbox
.
synchronized
{
outbox
.
getChunk
()
match
{
case
Some
(
chunk
)
=>
{
currentBuffers
++=
chunk
.
buffers
val
buffers
=
chunk
.
buffers
// If we have 'seen' pending messages, then reset flag - since we handle that as normal registering of event (below)
if
(
needForceReregister
&&
buffers
.
exists
(
_
.
remaining
()
>
0
))
resetForceReregister
()
currentBuffers
++=
buffers
}
case
None
=>
{
// changeConnectionKeyInterest(0)
...
...
@@ -384,7 +410,7 @@ class SendingConnection(val address: InetSocketAddress, selector_ : Selector,
override
def
changeInterestForRead
()
:
Boolean
=
false
override
def
changeInterestForWrite
()
:
Boolean
=
true
override
def
changeInterestForWrite
()
:
Boolean
=
!
isClosed
}
...
...
@@ -534,6 +560,7 @@ private[spark] class ReceivingConnection(channel_ : SocketChannel, selector_ : S
def
onReceive
(
callback
:
(
Connection
,
Message
)
=>
Unit
)
{
onReceiveCallback
=
callback
}
// override def changeInterestForRead(): Boolean = ! isClosed
override
def
changeInterestForRead
()
:
Boolean
=
true
override
def
changeInterestForWrite
()
:
Boolean
=
{
...
...
@@ -549,4 +576,7 @@ private[spark] class ReceivingConnection(channel_ : SocketChannel, selector_ : S
override
def
unregisterInterest
()
{
changeConnectionKeyInterest
(
0
)
}
// For read conn, always false.
override
def
resetForceReregister
()
:
Boolean
=
false
}
This diff is collapsed.
Click to expand it.
core/src/main/scala/spark/network/ConnectionManager.scala
+
2
−
1
View file @
dc47084f
...
...
@@ -123,7 +123,8 @@ private[spark] class ConnectionManager(port: Int) extends Logging {
}
finally
{
writeRunnableStarted
.
synchronized
{
writeRunnableStarted
-=
key
if
(
register
&&
conn
.
changeInterestForWrite
())
{
val
needReregister
=
register
||
conn
.
resetForceReregister
()
if
(
needReregister
&&
conn
.
changeInterestForWrite
())
{
conn
.
registerInterest
()
}
}
...
...
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