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

Updates to the AccessLogger class to fix the server hangs in Z/OS #30411

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
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 @@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
Copy link
Member

Choose a reason for hiding this comment

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

Let's update the copyright range fro 2004, 2022 -> 2004, 2024

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand All @@ -16,9 +16,14 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Pattern;

import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
Expand Down Expand Up @@ -50,12 +55,6 @@
import com.ibm.wsspi.http.logging.AccessLogForwarder;
import com.ibm.wsspi.http.logging.AccessLogRecordData;
import com.ibm.wsspi.http.logging.LogForwarderManager;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
* Implementation of an NCSA access log file. This will perform the disk IO on
Expand Down Expand Up @@ -89,7 +88,7 @@ public class AccessLogger extends LoggerOffThread implements AccessLog {

/** */
private static final String ROLLOVER_START_TIME_DEFAULT = "00:00";

/** */
private static final long ROLLOVER_INTERVAL_DEFAULT = 1440;

Expand Down Expand Up @@ -140,7 +139,7 @@ public static class FormatSegment {

private boolean isLogRolloverScheduled = false;

private volatile Timer timedLogRollover_Timer = new Timer();
private volatile Timer timedLogRollover_Timer = null;

/**
* Constructor of this NCSA access log file.
Expand All @@ -165,9 +164,14 @@ protected void activate(ComponentContext ctx, Map<String, Object> config) {
@Deactivate
protected void deactivate(ComponentContext ctx) {
if (this.isLogRolloverScheduled) {
timedLogRollover_Timer.cancel();
timedLogRollover_Timer.purge();
this.isLogRolloverScheduled = false;
if (timedLogRollover_Timer != null) {
timedLogRollover_Timer.cancel();
timedLogRollover_Timer.purge();
this.isLogRolloverScheduled = false;
timedLogRollover_Timer = null;

}

}
stop();
}
Expand All @@ -190,8 +194,7 @@ private synchronized void configure() {
// new file name
setFilename(filename);
isFilePathChanged = true;
}
else
} else
isFilePathChanged = false;

String logFormat = config.get(PROP_LOGFORMAT).toString();
Expand Down Expand Up @@ -220,7 +223,7 @@ private synchronized void configure() {
Tr.event(tc, "Config: invalid access max files: " + value);
}
}

} catch (FileNotFoundException e) {
FFDCFilter.processException(e, getClass().getName() + ".modified", "name", this);
if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
Expand Down Expand Up @@ -675,8 +678,8 @@ public String toString() {
}

/**
* Schedule time based log rollover
*/
* Schedule time based log rollover
*/
private void scheduleTimeBasedLogRollover(Map<String, Object> config) {
setRolloverStartTime(config.get(PROP_ROLLOVERSTARTTIME).toString());
setRolloverInterval(config.get(PROP_ROLLOVERINTERVAL).toString());
Expand All @@ -694,16 +697,18 @@ private void scheduleTimeBasedLogRollover(Map<String, Object> config) {
//if filePath is changed, need to reschedule with correct WorkerThread
if (this.rolloverStartTime.equals(rolloverStartTime) && this.rolloverInterval == rolloverInterval && !isFilePathChanged) {
return;
}
else {
timedLogRollover_Timer.cancel();
timedLogRollover_Timer.purge();
this.isLogRolloverScheduled = false;
} else {
if (timedLogRollover_Timer != null) {
timedLogRollover_Timer.cancel();
timedLogRollover_Timer.purge();
this.isLogRolloverScheduled = false;
}

}
}

//if both rolloverStartTime and rolloverInterval are empty, return
if ((rolloverStartTime == null || rolloverStartTime.isEmpty()) && (rolloverInterval < 0)) {
if ((rolloverStartTime == null || rolloverStartTime.isEmpty()) && (rolloverInterval < 0)) {
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(tc, "Neither rolloverStartTime nor rolloverInterval are set. Returning without scheduling time based access log rollover.");
}
Expand All @@ -713,7 +718,7 @@ private void scheduleTimeBasedLogRollover(Map<String, Object> config) {

//check and set time based log rollover values/defaults
//if rolloverInterval is less than 1 minute -- value returned from server.xml will round down to 0
if (rolloverInterval == 0) {
if (rolloverInterval == 0) {
Tr.warning(tc, "log.rollover.interval.too.short.warning");
rolloverInterval = ROLLOVER_INTERVAL_DEFAULT;
}
Expand All @@ -725,11 +730,10 @@ private void scheduleTimeBasedLogRollover(Map<String, Object> config) {
if (!Pattern.matches(ROLLOVER_START_TIME_FORMAT, rolloverStartTime)) {
Tr.warning(tc, "log.rollover.start.time.format.warning");
rolloverStartTime = ROLLOVER_START_TIME_DEFAULT;
}
}
else {
}
} else {
//set default of non-existing startTime if interval exists
rolloverStartTime = ROLLOVER_START_TIME_DEFAULT;
rolloverStartTime = ROLLOVER_START_TIME_DEFAULT;
}

if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Expand All @@ -738,8 +742,6 @@ private void scheduleTimeBasedLogRollover(Map<String, Object> config) {
Tr.debug(tc, "rolloverStartTime=" + rolloverStartTime);
}



this.rolloverStartTime = rolloverStartTime;
this.rolloverInterval = rolloverInterval;

Expand All @@ -758,41 +760,42 @@ private void scheduleTimeBasedLogRollover(Map<String, Object> config) {

//calculate next rollover after server update
//if currTime before startTime, firstRollover = startTime - n(interval)
if (currCal.before(sched)) {
if (currCal.before(sched)) {
while (currCal.before(sched)) {
sched.add(Calendar.MINUTE, (int)rolloverInterval*(-1));
sched.add(Calendar.MINUTE, (int) rolloverInterval * (-1));
}
sched.add(Calendar.MINUTE, (int)rolloverInterval); //add back interval due to time overlap
sched.add(Calendar.MINUTE, (int) rolloverInterval); //add back interval due to time overlap
}
//if currTime after startTime, firstRollover = startTime + n(interval)
else if (currCal.after(sched)) {
else if (currCal.after(sched)) {
while (currCal.after(sched)) {
sched.add(Calendar.MINUTE, (int)rolloverInterval);
sched.add(Calendar.MINUTE, (int) rolloverInterval);
}
}
//if currTime == startTime, set first rollover to next rolloverInterval
else if (currCal.equals(sched)) {
sched.add(Calendar.MINUTE, (int)rolloverInterval);
else if (currCal.equals(sched)) {
sched.add(Calendar.MINUTE, (int) rolloverInterval);
}

Date firstRollover = sched.getTime();
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(tc, "Log rollover settings updated - next rollover will be at ... "+sched.getTime());
Tr.debug(tc, "Log rollover settings updated - next rollover will be at ... " + sched.getTime());
}

//schedule rollover
timedLogRollover_Timer = new Timer(true);
TimedLogRoller tlr = new TimedLogRoller(this.getWorkerThread());
timedLogRollover_Timer.scheduleAtFixedRate(tlr, firstRollover, rolloverInterval*60000);
timedLogRollover_Timer.scheduleAtFixedRate(tlr, firstRollover, rolloverInterval * 60000);
this.isLogRolloverScheduled = true;

}

/**
* LogRoller task to be run/scheduled in timed log rollover.
*/
private class TimedLogRoller extends TimerTask {
private WorkerThread wt;
private final WorkerThread wt;

TimedLogRoller(WorkerThread wt) {
this.wt = wt;
}
Expand Down