Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Graceful drain on client #16

Merged
merged 4 commits into from
Mar 31, 2017
Merged

Graceful drain on client #16

merged 4 commits into from
Mar 31, 2017

Conversation

aravindvs
Copy link
Contributor

This patch makes sure the client can handle the DRAIN command from
the inputhost.

As soon as it receives the command, it will stop it's write pump and
will mark itself as "closed" so that if we get the same inputhost as a
result of reconfiguration, we open a new connection object.

Add a unit test to test the same.

Aravind Srinivasan added 3 commits March 29, 2017 13:28
This patch makes sure the client can handle the DRAIN command from
the inputhost.

As soon as it receives the command, it will stop it's write pump and
will mark itself as "closed" so that if we get the same inputhost as a
result of reconfiguration, we open a new connection object.

Add a unit test to test the same.
@aravindvs aravindvs requested a review from venkat1109 March 30, 2017 20:11
@coveralls
Copy link

Coverage Status

Coverage remained the same at 80.903% when pulling 6bec9ac on graceful_drain into 5b9071f on master.

1 similar comment
@coveralls
Copy link

coveralls commented Mar 30, 2017

Coverage Status

Coverage remained the same at 80.903% when pulling 6bec9ac on graceful_drain into 5b9071f on master.

// the read pump will exit when the server completes the drain
go conn.stopWritePump()

reconfigInfo := cmd.Reconfigure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about moving this logic into its own method so that it can be shared across the two if branches ?

@@ -140,17 +141,42 @@ func (conn *connection) open() error {
return nil
}

func (conn *connection) close() {
func (conn *connection) isStopped() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/isStopped/isShuttingDown to be consistent with naming.

func (conn *connection) isClosed() bool {
return atomic.LoadInt32(&conn.closed) != 0
return (atomic.LoadInt32(&conn.closed) != 0 || atomic.LoadInt32(&conn.drained) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need the additional atomic var ? Can you not do isShuttingDown() instead of Load(&conn.drained) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason i added this is to avoid taking the lock in isClosed(). If i use isShuttingDown() i need to take the lock to prevent race..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channels are thread safe.. not sure about the race.. Will leave it up to you resolve it.

* s/isStopped/isShuttingDown
* move handle reconfig into its own utility
@coveralls
Copy link

coveralls commented Mar 31, 2017

Coverage Status

Coverage remained the same at 80.903% when pulling 1ede1e5 on graceful_drain into 5b9071f on master.

func (conn *connection) isClosed() bool {
return atomic.LoadInt32(&conn.closed) != 0
return (atomic.LoadInt32(&conn.closed) != 0 || atomic.LoadInt32(&conn.drained) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channels are thread safe.. not sure about the race.. Will leave it up to you resolve it.

@aravindvs aravindvs merged commit de07d3a into master Mar 31, 2017
@aravindvs aravindvs deleted the graceful_drain branch March 31, 2017 23:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants