Skip to content
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

Force kill testcluster nodes #37353

Merged
merged 7 commits into from
Feb 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,30 @@ synchronized void stop(boolean tailLogs) {
}
logger.info("Stopping `{}`, tailLogs: {}", this, tailLogs);
requireNonNull(esProcess, "Can't stop `" + this + "` as it was not started or already stopped.");
stopHandle(esProcess.toHandle());
// Test clusters are not reused, don't spend time on a graceful shutdown
stopHandle(esProcess.toHandle(), true);
if (tailLogs) {
logFileContents("Standard output of node", getStdoutFile());
logFileContents("Standard error of node", getStdErrFile());
}
esProcess = null;
}

private void stopHandle(ProcessHandle processHandle) {
private void stopHandle(ProcessHandle processHandle, boolean forcibly) {
// Stop all children first, ES could actually be a child when there's some wrapper process like on Windows.
if (processHandle.isAlive()) {
processHandle.children().forEach(this::stopHandle);
processHandle.children().forEach(each -> stopHandle(each, forcibly));
}
logProcessInfo("Terminating elasticsearch process:", processHandle.info());
logProcessInfo(
"Terminating elasticsearch process" + (forcibly ? " forcibly " : "gratefully") + ":",
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, should be "gracefully". Not say we are not grateful 😉

processHandle.info()
);
if (processHandle.isAlive()) {
processHandle.destroy();
if (forcibly) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the order of this all can be cleaned up to not have doubling up on waits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rjernst done, ready for review

Copy link
Member

Choose a reason for hiding this comment

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

We're still doing multiple aliveness checks when we already know it is killed. Here is what I was envisioning:

if (processHandle.isAlive() == false) {
    logger.info("Process was not running when we tried to terminate it.");
	return;
}

// Stop all children first, ES could actually be a child when there's some wrapper process like on Windows.
processHandle.children().forEach(each -> stopHandle(each, forcibly));

logProcessInfo("Terminating elasticsearch process" + (forcibly ? " forcibly " : "gratefully") + ":", processHandle.info());

if (forcibly) {
    processHandle.destroyForcibly();
} else {
    processHandle.destroy();
    waitForProcessToExit(processHandle);
    if (processHandle.isAlive()) {
	    logger.info("process did not terminate after {} {}, stopping it forcefully",
	                       ES_DESTROY_TIMEOUT, ES_DESTROY_TIMEOUT_UNIT);
	    processHandle.destroyForcibly();
    }
}

waitForProcessToExit(processHandle);
if (processHandle.isAlive()) {
    throw new TestClustersException("Was not able to terminate elasticsearch process");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rjernst implemented as suggested

processHandle.destroyForcibly();
} else {
processHandle.destroy();
}
} else {
logger.info("Process was not running when we tried to terminate it.");
}
Expand Down