Skip to content

Commit

Permalink
[Fix-apache#3618][server] resolve task executed finished but not rele…
Browse files Browse the repository at this point in the history
…ase the file handle
  • Loading branch information
lgcareer committed Oct 22, 2020
1 parent 7a088b7 commit 247494a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.server.log;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.FileAppender;
import org.slf4j.Marker;

import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER;

/**
* Task log appender
*/
public class TaskLogAppender extends FileAppender<ILoggingEvent>{
@Override
protected void append(ILoggingEvent event) {
Marker marker = event.getMarker();
if (marker !=null) {
if (marker.equals(FINALIZE_SESSION_MARKER)) {
stop();
}
}
super.subAppend(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER;


/**
* task scheduler thread
Expand Down Expand Up @@ -132,7 +134,6 @@ public void run() {

// task result process
task.after();

responseCommand.setStatus(task.getExitStatus().getCode());
responseCommand.setEndTime(new Date());
responseCommand.setProcessId(task.getProcessId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,19 @@ private void printCommand(List<String> commands) {
* clear
*/
private void clear() {

List<String> markerList = new ArrayList<String>() {
{
add(ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER.toString());
}
};

if (!logBuffer.isEmpty()) {
// log handle
logHandler.accept(logBuffer);

logBuffer.clear();
}
logHandler.accept(markerList);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
*/
package org.apache.dolphinscheduler.server.worker.task;

import org.apache.commons.lang.StringUtils;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.*;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.enums.TaskRecordStatus;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.task.AbstractParameters;
import org.apache.dolphinscheduler.common.task.conditions.ConditionsParameters;
Expand All @@ -34,14 +38,13 @@
import org.apache.dolphinscheduler.dao.TaskRecordDao;
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext;
import org.apache.dolphinscheduler.server.utils.ParamUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER;

/**
* executive task
*/
Expand Down Expand Up @@ -118,7 +121,11 @@ public void cancelApplication(boolean status) throws Exception {
*/
public void logHandle(List<String> logs) {
// note that the "new line" is added here to facilitate log parsing
logger.info(" -> {}", String.join("\n\t", logs));
if (logs.contains(FINALIZE_SESSION_MARKER.toString())) {
logger.info(FINALIZE_SESSION_MARKER, FINALIZE_SESSION_MARKER.toString());
} else {
logger.info(" -> {}", String.join("\n\t", logs));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<logBase>${log.base}</logBase>
</Discriminator>
<sift>
<appender name="FILE-${taskAppId}" class="ch.qos.logback.core.FileAppender">
<appender name="FILE-${taskAppId}" class="org.apache.dolphinscheduler.server.log.TaskLogAppender">
<file>${log.base}/${taskAppId}.log</file>
<encoder>
<pattern>
Expand Down

0 comments on commit 247494a

Please sign in to comment.