-
Notifications
You must be signed in to change notification settings - Fork 902
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
fix Flaky-test: BookieZKExpireTest.testBookieServerZKSessionExpireBehaviour #3418
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -77,6 +77,7 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher, AutoCloseable | |
private final String connectString; | ||
private final int sessionTimeoutMs; | ||
private final boolean allowReadOnlyMode; | ||
private final boolean retryExpired; | ||
|
||
// state for the zookeeper client | ||
private final AtomicReference<ZooKeeper> zk = new AtomicReference<ZooKeeper>(); | ||
|
@@ -173,6 +174,7 @@ public static class Builder { | |
int retryExecThreadCount = DEFAULT_RETRY_EXECUTOR_THREAD_COUNT; | ||
double requestRateLimit = 0; | ||
boolean allowReadOnlyMode = false; | ||
boolean retryExpired = true; | ||
|
||
private Builder() {} | ||
|
||
|
@@ -221,6 +223,11 @@ public Builder allowReadOnlyMode(boolean allowReadOnlyMode) { | |
return this; | ||
} | ||
|
||
public Builder retryExpired(boolean retryExpired) { | ||
this.retryExpired = retryExpired; | ||
return this; | ||
} | ||
|
||
public ZooKeeperClient build() throws IOException, KeeperException, InterruptedException { | ||
checkNotNull(connectString); | ||
checkArgument(sessionTimeoutMs > 0); | ||
|
@@ -253,7 +260,8 @@ public ZooKeeperClient build() throws IOException, KeeperException, InterruptedE | |
statsLogger, | ||
retryExecThreadCount, | ||
requestRateLimit, | ||
allowReadOnlyMode | ||
allowReadOnlyMode, | ||
retryExpired | ||
); | ||
// Wait for connection to be established. | ||
try { | ||
|
@@ -282,11 +290,13 @@ protected ZooKeeperClient(String connectString, | |
StatsLogger statsLogger, | ||
int retryExecThreadCount, | ||
double rate, | ||
boolean allowReadOnlyMode) throws IOException { | ||
boolean allowReadOnlyMode, | ||
boolean retryExpired) throws IOException { | ||
super(connectString, sessionTimeoutMs, watcherManager, allowReadOnlyMode); | ||
this.connectString = connectString; | ||
this.sessionTimeoutMs = sessionTimeoutMs; | ||
this.allowReadOnlyMode = allowReadOnlyMode; | ||
this.retryExpired = retryExpired; | ||
this.watcherManager = watcherManager; | ||
this.connectRetryPolicy = connectRetryPolicy; | ||
this.operationRetryPolicy = operationRetryPolicy; | ||
|
@@ -356,6 +366,13 @@ private void onExpired() { | |
|
||
logger.info("ZooKeeper session {} is expired from {}.", | ||
Long.toHexString(getSessionId()), connectString); | ||
|
||
if (!retryExpired) { | ||
logger.warn("ZooKeeper session expired retries have been disabled"); | ||
return; | ||
} | ||
|
||
Comment on lines
+369
to
+374
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. Recreating new zookeeper instances is prohibited here. |
||
|
||
try { | ||
connectExecutor.submit(clientCreator); | ||
} catch (RejectedExecutionException ree) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ public void testBookieServerZKRequestTimeoutBehaviour() throws Exception { | |
Thread[] threads = new Thread[threadCount * 2]; | ||
threadCount = Thread.enumerate(threads); | ||
for (int i = 0; i < threadCount; i++) { | ||
if (threads[i].getName().indexOf("SendThread") != -1) { | ||
if (threads[i].getName().contains("SendThread")) { | ||
threadset.add(threads[i]); | ||
} | ||
} | ||
|
@@ -93,7 +93,7 @@ conf, new TestBookieImpl(conf), | |
threads = new Thread[threadCount * 2]; | ||
threadCount = Thread.enumerate(threads); | ||
for (int i = 0; i < threadCount; i++) { | ||
if (threads[i].getName().indexOf("SendThread") != -1 | ||
if (threads[i].getName().contains("SendThread") | ||
&& !threadset.contains(threads[i])) { | ||
sendthread = threads[i]; | ||
break; | ||
|
@@ -113,7 +113,9 @@ conf, new TestBookieImpl(conf), | |
assertTrue("Bookie Server should not shutdown on zk timeout", server.isRunning()); | ||
} finally { | ||
System.clearProperty("zookeeper.request.timeout"); | ||
server.shutdown(); | ||
if (server != null) { | ||
server.shutdown(); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -139,7 +141,7 @@ public void testBookieServerZKSessionExpireBehaviour() throws Exception { | |
Thread[] threads = new Thread[threadCount * 2]; | ||
threadCount = Thread.enumerate(threads); | ||
for (int i = 0; i < threadCount; i++) { | ||
if (threads[i].getName().indexOf("SendThread") != -1) { | ||
if (threads[i].getName().contains("SendThread")) { | ||
threadset.add(threads[i]); | ||
} | ||
} | ||
|
@@ -163,7 +165,7 @@ conf, new TestBookieImpl(conf), | |
threads = new Thread[threadCount * 2]; | ||
threadCount = Thread.enumerate(threads); | ||
for (int i = 0; i < threadCount; i++) { | ||
if (threads[i].getName().indexOf("SendThread") != -1 | ||
if (threads[i].getName().contains("SendThread") | ||
&& !threadset.contains(threads[i])) { | ||
sendthread = threads[i]; | ||
break; | ||
|
@@ -177,13 +179,15 @@ conf, new TestBookieImpl(conf), | |
log.info("Resuming threads"); | ||
sendthread.resume(); | ||
|
||
// allow watcher thread to run | ||
Thread.sleep(3000); | ||
// allow client.waitForConnection() timeout | ||
Thread.sleep(10000); | ||
assertFalse("Bookie should shutdown on losing zk session", server.isBookieRunning()); | ||
assertFalse("Bookie Server should shutdown on losing zk session", server.isRunning()); | ||
Comment on lines
+182
to
185
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. The increase from 3 seconds to 10 seconds is because creating a bookie temporary node needs to wait for the old zk client to establish a connection with the server. There is a timeout period of conf.getZkTimeout()=6 seconds. Once the timeout period expires, the bookie service will Closed due to session timeout, the extra 4 seconds is to consolidate the stability of the test and give the bookie service a little extra time to perform the shutdown. |
||
} finally { | ||
System.clearProperty("zookeeper.request.timeout"); | ||
server.shutdown(); | ||
if (server != null) { | ||
server.shutdown(); | ||
} | ||
} | ||
} | ||
|
||
|
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 check(zkRetryExpired) is difficult to understand, what scene is set to true and what scene is set to false