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
[CURATOR-367] Delay reconnect on session expired #197
Changes from 2 commits
651ac59
7c35e44
7f53bc1
4a95669
952dd6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,9 @@ public void process(WatchedEvent event) | |
log.debug("ConnectState watcher: " + event); | ||
} | ||
|
||
if ( event.getType() == Watcher.Event.EventType.None ) | ||
final boolean eventTypeNone = event.getType() == Watcher.Event.EventType.None; | ||
|
||
if ( eventTypeNone ) | ||
{ | ||
boolean wasConnected = isConnected.get(); | ||
boolean newIsConnected = checkState(event.getState(), wasConnected); | ||
|
@@ -160,13 +162,33 @@ public void process(WatchedEvent event) | |
} | ||
} | ||
|
||
// only wait during tests | ||
assert waitOnExpiredEvent(event.getState()); | ||
|
||
for ( Watcher parentWatcher : parentWatchers ) | ||
{ | ||
|
||
OperationTrace trace = new OperationTrace("connection-state-parent-process", tracer.get(), getSessionId()); | ||
parentWatcher.process(event); | ||
trace.commit(); | ||
} | ||
|
||
if (eventTypeNone) handleState(event.getState()); | ||
} | ||
|
||
// only for testing | ||
private boolean waitOnExpiredEvent(Event.KeeperState currentState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of the boolean return? The method only ever returns true? Is it purely so you can call it from the assert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - only so that it can be called form assert. |
||
{ | ||
if (currentState == Event.KeeperState.Expired) | ||
{ | ||
log.debug("Waiting on Expired event for testing"); | ||
try | ||
{ | ||
Thread.sleep(1000); | ||
} | ||
catch(InterruptedException e) {} | ||
log.debug("Continue processing"); | ||
} | ||
return true; | ||
} | ||
|
||
EnsembleProvider getEnsembleProvider() | ||
|
@@ -240,11 +262,11 @@ private synchronized void reset() throws Exception | |
private boolean checkState(Event.KeeperState state, boolean wasConnected) | ||
{ | ||
boolean isConnected = wasConnected; | ||
boolean checkNewConnectionString = true; | ||
switch ( state ) | ||
{ | ||
default: | ||
case Disconnected: | ||
case Expired: | ||
{ | ||
isConnected = false; | ||
break; | ||
|
@@ -264,14 +286,6 @@ private boolean checkState(Event.KeeperState state, boolean wasConnected) | |
break; | ||
} | ||
|
||
case Expired: | ||
{ | ||
isConnected = false; | ||
checkNewConnectionString = false; | ||
handleExpiredSession(); | ||
break; | ||
} | ||
|
||
case SaslAuthenticated: | ||
{ | ||
// NOP | ||
|
@@ -283,12 +297,19 @@ private boolean checkState(Event.KeeperState state, boolean wasConnected) | |
new EventTrace(state.toString(), tracer.get(), getSessionId()).commit(); | ||
} | ||
|
||
if ( checkNewConnectionString && zooKeeper.hasNewConnectionString() ) | ||
return isConnected; | ||
} | ||
|
||
private void handleState(Event.KeeperState state) | ||
{ | ||
if (state == Event.KeeperState.Expired) | ||
{ | ||
handleExpiredSession(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've lost functionality here right? If there's a new connection string and an expired session we don't get the new connection string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets handled in the handleState() method, which is called from process() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that true of the existing implementation though? If the state is expired then the checkNewConnectionString flag gets set to false so the handleNewConnectionString() method won't get called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh - I think you're right. The old version set |
||
} | ||
else if (zooKeeper.hasNewConnectionString()) | ||
{ | ||
handleNewConnectionString(); | ||
} | ||
|
||
return isConnected; | ||
} | ||
|
||
private void handleNewConnectionString() | ||
|
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.
How is this meant to work? Are you assuming that assertions will only be enabled in testing? If you need some logic to only be executed during testing shouldn't there be some sort of internal flag indicating this?
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.
Yes, assuming assertions are enabled in testing. I've added the delay here wait for the reconnect to happen, but since now the reset is called later in the method it might no longer be necessary.
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.
I don't think that it's reasonable to assume that assertions will only be turned on during testing. If you look at something like LeaderSelector, it has specific code in there to support unit testing (the debugLeadershipLatch variable).
If you can cause the problem to occur without this code though, then it should be removed. I had a quick play with it and I couldn't seem to reproduce it without this code though.
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.
I changed using a debug flag instead of assert. I added an accessor class to be able to set the flag in the package private ConnectionState class.
I cannot cause the problem to occur without this code.