-
Notifications
You must be signed in to change notification settings - Fork 488
Added ExitCodesIT to test process exit codes under various conditions #5811
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
Changes from all commits
99c8070
87e8507
5043c2e
f855c82
d41dbcc
9ae6f1d
bf5e3be
1337d84
57e6330
ec5cd1d
6259885
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 |
|---|---|---|
|
|
@@ -82,21 +82,21 @@ public void lostLock(LockLossReason reason) { | |
| Halt.halt(0, server + " lock in zookeeper lost (reason = " + reason | ||
| + "), exiting cleanly because shutdown is complete."); | ||
| } else { | ||
| Halt.halt(-1, server + " lock in zookeeper lost (reason = " + reason + "), exiting!"); | ||
| Halt.halt(1, server + " lock in zookeeper lost (reason = " + reason + "), exiting!"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void unableToMonitorLockNode(final Exception e) { | ||
| Halt.halt(-1, "FATAL: No longer able to monitor " + server + " lock node", e); | ||
| Halt.halt(1, "FATAL: No longer able to monitor " + server + " lock node", e); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void acquiredLock() { | ||
| LOG.debug("Acquired {} lock", server); | ||
|
|
||
| if (acquiredLock || failedToAcquireLock) { | ||
| Halt.halt(-1, "Zoolock in unexpected state AL " + acquiredLock + " " + failedToAcquireLock); | ||
| Halt.halt(1, "Zoolock in unexpected state AL " + acquiredLock + " " + failedToAcquireLock); | ||
| } | ||
|
|
||
| acquiredLock = true; | ||
|
|
@@ -111,11 +111,11 @@ public synchronized void failedToAcquireLock(Exception e) { | |
| String msg = | ||
| "Failed to acquire " + server + " lock due to incorrect ZooKeeper authentication."; | ||
| LOG.error("{} Ensure instance.secret is consistent across Accumulo configuration", msg, e); | ||
| Halt.halt(-1, msg); | ||
| Halt.halt(1, msg); | ||
| } | ||
|
|
||
| if (acquiredLock) { | ||
| Halt.halt(-1, | ||
| Halt.halt(1, | ||
|
Member
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. 👍 to using positive numbers. |
||
| "Zoolock in unexpected state acquiredLock true with FAL " + failedToAcquireLock); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,24 +76,7 @@ public static interface ThriftServerSupplier { | |
| } | ||
|
|
||
| public static void startServer(AbstractServer server, Logger LOG) throws Exception { | ||
| try { | ||
| server.runServer(); | ||
| } catch (Throwable e) { | ||
| System.err | ||
| .println(server.getClass().getSimpleName() + " died, exception thrown from runServer."); | ||
| e.printStackTrace(); | ||
| LOG.error("{} died, exception thrown from runServer.", server.getClass().getSimpleName(), e); | ||
| throw e; | ||
| } finally { | ||
|
Contributor
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. A bit futher up could change the catch to
Contributor
Author
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. I thought it was for the logging of Error, not just Exception.
Contributor
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 was for logging an error in the case where finally threw an exception in which case the error would be lost and would not propagate. W/o the finally the error will propagate now. So it depends on what the outer code does with it.
Contributor
Author
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. Fixed in ec5cd1d
Contributor
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.
Contributor
Author
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. I don't think we need to. I checked the logs and the Exception and Error are logged correctly. The issue in #5796 was an exception in the try-with-resources was being suppressed when an exception happened in the close. try-with-resources is no longer being used. |
||
| try { | ||
| server.close(); | ||
| } catch (Throwable e) { | ||
| System.err.println("Exception thrown while closing " + server.getClass().getSimpleName()); | ||
| e.printStackTrace(); | ||
| LOG.error("Exception thrown while closing {}", server.getClass().getSimpleName(), e); | ||
| throw e; | ||
| } | ||
| } | ||
| server.runServer(); | ||
| } | ||
|
|
||
| private final MetricSource metricSource; | ||
|
|
@@ -112,6 +95,7 @@ public static void startServer(AbstractServer server, Logger LOG) throws Excepti | |
| private volatile Thread verificationThread; | ||
| private final AtomicBoolean shutdownRequested = new AtomicBoolean(false); | ||
| private final AtomicBoolean shutdownComplete = new AtomicBoolean(false); | ||
| private final AtomicBoolean closed = new AtomicBoolean(false); | ||
|
|
||
| protected AbstractServer(ServerId.Type serverType, ConfigOpts opts, | ||
| Function<SiteConfiguration,ServerContext> serverContextFactory, String[] args) { | ||
|
|
@@ -203,7 +187,8 @@ protected AbstractServer(ServerId.Type serverType, ConfigOpts opts, | |
| * | ||
| * @param isIdle whether the server is idle | ||
| */ | ||
| protected void updateIdleStatus(boolean isIdle) { | ||
| // public for ExitCodesIT | ||
| public void updateIdleStatus(boolean isIdle) { | ||
| boolean shouldResetIdlePeriod = !isIdle || idleReportingPeriodMillis == 0; | ||
| boolean hasIdlePeriodStarted = idlePeriodTimer != null; | ||
| boolean hasExceededIdlePeriod = | ||
|
|
@@ -290,7 +275,10 @@ public AtomicBoolean getShutdownComplete() { | |
| */ | ||
| public void runServer() throws Exception { | ||
| final AtomicReference<Throwable> err = new AtomicReference<>(); | ||
| serverThread = new Thread(TraceUtil.wrap(this), applicationName); | ||
| serverThread = new Thread(TraceUtil.wrap(() -> { | ||
| this.run(); | ||
| close(); | ||
| }), applicationName); | ||
| serverThread.setUncaughtExceptionHandler((thread, exception) -> err.set(exception)); | ||
| serverThread.start(); | ||
| serverThread.join(); | ||
|
|
@@ -331,7 +319,8 @@ public String getBindAddress() { | |
| return bindAddress; | ||
| } | ||
|
|
||
| protected TServer getThriftServer() { | ||
| // public for ExitCodesIT | ||
| public TServer getThriftServer() { | ||
| if (thriftServer == null) { | ||
| return null; | ||
| } | ||
|
|
@@ -451,7 +440,7 @@ public void startServiceLockVerificationThread() { | |
| log.trace( | ||
| "ServiceLockVerificationThread - checking ServiceLock existence in ZooKeeper"); | ||
| if (lock != null && !lock.verifyLockAtSource()) { | ||
| Halt.halt(-1, "Lock verification thread could not find lock"); | ||
| Halt.halt(1, "Lock verification thread could not find lock"); | ||
| } | ||
| // Need to sleep, not yield when the thread priority is greater than NORM_PRIORITY | ||
| // so that this thread does not get immediately rescheduled. | ||
|
|
@@ -476,8 +465,21 @@ public void startServiceLockVerificationThread() { | |
|
|
||
| @Override | ||
| public void close() { | ||
| if (context != null) { | ||
| context.close(); | ||
|
|
||
| if (closed.compareAndSet(false, true)) { | ||
|
|
||
| // Must set shutdown as completed before calling ServerContext.close(). | ||
| // ServerContext.close() calls ClientContext.close() -> | ||
| // ZooSession.close() which removes all of the ephemeral nodes and | ||
| // forces the watches to fire. The ServiceLockWatcher has a reference | ||
| // to shutdownComplete and will terminate the JVM with a 0 exit code | ||
| // if true. Otherwise it will exit with a non-zero exit code. | ||
| getShutdownComplete().set(true); | ||
|
|
||
| if (context != null) { | ||
| context.getLowMemoryDetector().logGCInfo(getConfiguration()); | ||
| context.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -488,4 +490,7 @@ protected void waitForUpgrade() throws InterruptedException { | |
| } | ||
| } | ||
|
|
||
| public void requestShutdownForTests() { | ||
| shutdownRequested.set(true); | ||
| } | ||
| } | ||
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 needed to be moved to the end because it closes ZooKeeper, which deletes all ephemeral nodes and fires any watchers.