-
Notifications
You must be signed in to change notification settings - Fork 903
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
Allocator support exitOnOutOfMemory config. #3984
Merged
StevenLuMT
merged 11 commits into
apache:master
from
horizonzy:allocator-support-exit-oom-conifg
Jul 15, 2024
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2dcd2ea
Allocator support exitOnOutOfMemory config.
horizonzy d833b9d
fix checkstyle.
horizonzy aaca547
Fix checkstyle.
horizonzy 6368ad1
Fix checkstyle.
horizonzy 3fe25b6
Fix ci.
horizonzy ad92acf
Fix checkstyle.
horizonzy 31c5403
For compatible.
horizonzy 4a7b02a
Fix checkstyle.
horizonzy 1359c82
Merge branch 'master' into allocator-support-exit-oom-conifg
horizonzy 2934bc6
fix ci.
horizonzy 7995b51
code clean.
horizonzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...keeper-common-allocator/src/main/java/org/apache/bookkeeper/common/util/ShutdownUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.bookkeeper.common.util; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Forked from <a href="https://github.com/apache/pulsar">Pulsar</a>. | ||
*/ | ||
@Slf4j | ||
public class ShutdownUtil { | ||
private static final Method log4j2ShutdownMethod; | ||
|
||
static { | ||
// use reflection to find org.apache.logging.log4j.LogManager.shutdown method | ||
Method shutdownMethod = null; | ||
try { | ||
shutdownMethod = Class.forName("org.apache.logging.log4j.LogManager") | ||
.getMethod("shutdown"); | ||
} catch (ClassNotFoundException | NoSuchMethodException e) { | ||
// ignore when Log4j2 isn't found, log at debug level | ||
log.debug("Cannot find org.apache.logging.log4j.LogManager.shutdown method", e); | ||
} | ||
log4j2ShutdownMethod = shutdownMethod; | ||
} | ||
|
||
/** | ||
* Triggers an immediate forceful shutdown of the current process. | ||
* | ||
* @param status Termination status. By convention, a nonzero status code indicates abnormal termination. | ||
* @see Runtime#halt(int) | ||
*/ | ||
public static void triggerImmediateForcefulShutdown(int status) { | ||
triggerImmediateForcefulShutdown(status, true); | ||
} | ||
public static void triggerImmediateForcefulShutdown(int status, boolean logging) { | ||
try { | ||
if (status != 0 && logging) { | ||
log.warn("Triggering immediate shutdown of current process with status {}", status, | ||
new Exception("Stacktrace for immediate shutdown")); | ||
} | ||
shutdownLogging(); | ||
} finally { | ||
Runtime.getRuntime().halt(status); | ||
} | ||
} | ||
|
||
private static void shutdownLogging() { | ||
// flush log buffers and shutdown log4j2 logging to prevent log truncation | ||
if (log4j2ShutdownMethod != null) { | ||
try { | ||
// use reflection to call org.apache.logging.log4j.LogManager.shutdown() | ||
log4j2ShutdownMethod.invoke(null); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
log.error("Unable to call org.apache.logging.log4j.LogManager.shutdown using reflection.", e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Triggers an immediate forceful shutdown of the current process using 1 as the status code. | ||
* | ||
* @see Runtime#halt(int) | ||
*/ | ||
public static void triggerImmediateForcefulShutdown() { | ||
triggerImmediateForcefulShutdown(1); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...keeper-common-allocator/src/main/java/org/apache/bookkeeper/common/util/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
* defines the utilities for allocator used across the project. | ||
*/ | ||
package org.apache.bookkeeper.common.util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question, this is copied from pulsar-common directly, why not import pulsar-common in bookkeeper/bookkeeper-common-allocator/pom.xml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except for the ShutdownUtil problem, the rest are pretty good,LGTM @horizonzy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor import, we needn't import new dependency.