Skip to content

Commit

Permalink
[INLONG-10889][Agent] When the oom is detected, the process exits
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwwhuang committed Aug 26, 2024
1 parent 73881b4 commit 4e862c1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AgentConstants {
public static final String DEFAULT_AGENT_HISTORY_PATH = ".history";

public static final String AGENT_ENABLE_OOM_EXIT = "agent.enable.oom.exit";
public static final boolean DEFAULT_ENABLE_OOM_EXIT = false;
public static final boolean DEFAULT_ENABLE_OOM_EXIT = true;

// pulsar sink config
public static final String PULSAR_CLIENT_IO_TREHAD_NUM = "agent.sink.pulsar.client.io.thread.num";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public static void threadThrowableHandler(Thread t, Throwable e) {
}

private static void handleOOM(Thread t, Throwable e) {
if (ExceptionUtils.indexOfThrowable(e, java.lang.OutOfMemoryError.class) != -1) {
if (ExceptionUtils.indexOfThrowable(e, OutOfMemoryError.class) != -1) {
LOGGER.error("Agent exit caused by {} OutOfMemory: ", t.getName(), e);
forceShutDown();
}
}

private static void forceShutDown() {
try {
Runtime.getRuntime().exit(-1);
Runtime.getRuntime().halt(-1);
} catch (Throwable e) {
LOGGER.error("exit failed, just halt, exception: ", e);
Runtime.getRuntime().halt(-2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static long getFileCreationTime(String fileName) {
creationTime = Files.readAttributes(Paths.get(fileName), BasicFileAttributes.class).creationTime()
.toMillis();
} catch (IOException e) {
LOGGER.error("getFileCreationTime error {}", e.getMessage());
LOGGER.error("getFileCreationTime error {}", e);
}
return creationTime;
}
Expand All @@ -68,7 +68,7 @@ public static long getFileLastModifyTime(String fileName) {
try {
lastModify = Files.getLastModifiedTime(Paths.get(fileName)).toMillis();
} catch (IOException e) {
LOGGER.error("getFileLastModifyTime error {}", e.getMessage());
LOGGER.error("getFileLastModifyTime error {}", e);
}
return lastModify;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void run() {
doRun();
} catch (Throwable e) {
LOGGER.error("do run error: ", e);
ThreadUtils.threadThrowableHandler(Thread.currentThread(), e);
}
running = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ private void sendBatchWithRetryCount(SenderMessage message, int retry) {
}
retry++;
AgentUtils.silenceSleepInMs(retrySleepTime);
ThreadUtils.threadThrowableHandler(Thread.currentThread(), exception);
}
}
}
Expand Down Expand Up @@ -299,10 +300,9 @@ private Runnable flushResendQueue() {
message.getTotalSize(), auditVersion);
sendBatchWithRetryCount(callback.message, callback.retry + 1);
}
} catch (Exception ex) {
LOGGER.error("error caught", ex);
} catch (Throwable t) {
ThreadUtils.threadThrowableHandler(Thread.currentThread(), t);
} catch (Exception e) {
LOGGER.error("error caught", e);
ThreadUtils.threadThrowableHandler(Thread.currentThread(), e);
} finally {
AgentUtils.silenceSleepInMs(batchFlushInterval);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ protected void releaseSource() {
data.setReadBytes(String.valueOf(bytePosition));
data.setReadLines(String.valueOf(linePosition));
OffsetProfile offsetProfile = OffsetManager.getInstance().getOffset(taskId, instanceId);
if (offsetProfile == null) {
return;
}
data.setSendLines(offsetProfile.getOffset());
FileStaticManager.getInstance().putStaticMsg(data);
randomAccessFile.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.inlong.agent.plugin.file.Source;
import org.apache.inlong.agent.plugin.sources.file.extend.ExtendedHandler;
import org.apache.inlong.agent.utils.AgentUtils;
import org.apache.inlong.agent.utils.ThreadUtils;
import org.apache.inlong.common.metric.MetricRegister;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -153,6 +154,7 @@ private Runnable run() {
doRun();
} catch (Throwable e) {
LOGGER.error("do run error maybe file deleted: ", e);
ThreadUtils.threadThrowableHandler(Thread.currentThread(), e);
}
running = false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.inlong.agent.state.State;
import org.apache.inlong.agent.store.Store;
import org.apache.inlong.agent.utils.AgentUtils;
import org.apache.inlong.agent.utils.ThreadUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void run() {
doRun();
} catch (Throwable e) {
LOGGER.error("do run error: ", e);
ThreadUtils.threadThrowableHandler(Thread.currentThread(), e);
}
running = false;
}
Expand Down

0 comments on commit 4e862c1

Please sign in to comment.