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

PAYARA-3344 Added System Property for Shutdown Grace Period #3702

Merged
merged 4 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -39,6 +39,7 @@
*/
package fish.payara.micro.boot.runtime;

import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl;
import com.sun.enterprise.module.bootstrap.ModuleStartup;
import java.util.Properties;
import org.glassfish.embeddable.CommandRunner;
Expand Down Expand Up @@ -74,19 +75,20 @@ public void start() throws GlassFishException {
}

@Override
public void stop() throws GlassFishException {
public synchronized void stop() throws GlassFishException {
if (status == Status.STOPPED || status == Status.STOPPING || status == Status.DISPOSED) {
throw new IllegalStateException("Already in " + status + " state.");
}

status = Status.STOPPING;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question is: after status is STOPPING will this prevent accepting new requests? I think the intention is to finish the ongoing ones but I guess we do not want to accept new ones.

Copy link
Member

Choose a reason for hiding this comment

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

I don't follow what the question is here?
There's a check literally above this that prints an error if multiple things try to stop the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I wanted to point out is that before the wait only the status was changed. No internal processing has been signalled to stop by that point. I would imagine that it could very well be the case that new request still are accepted and start to process. If the goal with this feature is to give time to finish started requests it seams only consequent not to accept new ones. I would assume that some parts of the server needs to be stopped or flagged to get this behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Searching the source I don't see that status is used much other than to print it into the admin console. Perhaps we could use this status variable better to stop processing etc.However that would be a different JIRA.

GlassFishImpl.sleepShutdownGracePeriod();
kernel.stop();
habitat.shutdown();
status = Status.STOPPED;
}

@Override
public void dispose() throws GlassFishException {
public synchronized void dispose() throws GlassFishException {
if (status == Status.DISPOSED) {
throw new IllegalStateException("Already disposed.");
} else if (status != Status.STOPPED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public enum RUNTIME_OPTION {
sslcert(true),
help(false),
enablesni(false),
hzpublicaddress(true);
hzpublicaddress(true),
shutdowngrace(true, new IntegerValidator(1, Integer.MAX_VALUE));

private RUNTIME_OPTION(boolean hasValue) {
this(hasValue, new Validator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.glassfish.embeddable.GlassFishRuntime;
import com.sun.appserv.server.util.Version;
import com.sun.enterprise.glassfish.bootstrap.Constants;
import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl;
import com.sun.enterprise.server.logging.ODLLogFormatter;
import fish.payara.micro.PayaraMicroRuntime;
import fish.payara.micro.boot.PayaraMicroBoot;
Expand Down Expand Up @@ -1382,6 +1383,9 @@ else if (requestTracing[0].matches("\\D+")) {
case hzpublicaddress:
publicAddress = value;
break;
case shutdowngrace:
System.setProperty(GlassFishImpl.PAYARA_SHUTDOWNGRACE_PROPERTY, value);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
* Portions Copyright [2017-2019] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.glassfish.bootstrap;
Expand All @@ -57,6 +57,8 @@

public class GlassFishImpl implements GlassFish {

public static final String PAYARA_SHUTDOWNGRACE_PROPERTY = "fish.payara.shutdowngrace";

private ModuleStartup gfKernel;
private ServiceLocator habitat;
volatile Status status = Status.INIT;
Expand Down Expand Up @@ -87,10 +89,24 @@ public synchronized void stop() throws GlassFishException {
throw new IllegalStateException("Already in " + status + " state.");
}
status = Status.STOPPING;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here: do we prevent accepting new requests effectively?

sleepShutdownGracePeriod();
gfKernel.stop();
status = Status.STOPPED;
}

public static void sleepShutdownGracePeriod() {
String shutdowngrace = System.getProperty(PAYARA_SHUTDOWNGRACE_PROPERTY);
if (shutdowngrace != null) {
try {
Thread.sleep(Integer.parseInt(shutdowngrace));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (NumberFormatException e) {
// no sleep, continue shutdown
}
}
}

public synchronized void dispose() throws GlassFishException {
if (status == Status.DISPOSED) {
throw new IllegalStateException("Already disposed.");
Expand Down