Skip to content

Commit 21e37c9

Browse files
authored
Merge branch 'master' into lh-java-17-min
2 parents c472134 + 606db74 commit 21e37c9

File tree

196 files changed

+3305
-1830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+3305
-1830
lines changed

Diff for: .github/actions/bot/src/run.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
async function run(core, context, github) {
2020

2121
try {
22-
const owner = process.env.PROVIDER;
23-
const repo = process.env.REPOSITORY;
22+
const owner = context.repo.owner;
23+
const repo = context.repo.repo;
2424
const reRunCmd = process.env.RERUN_CMD;
2525
const comment = context.payload.comment.body;
2626

2727
if (comment !== reRunCmd) {
28-
console.log("this is not a bot command");
28+
core.info("this is not a bot command");
2929
return;
3030
}
3131

@@ -35,13 +35,13 @@ async function run(core, context, github) {
3535
sha: prRef,
3636
}
3737
}
38-
} = await github.pulls.get({
38+
} = await github.rest.pulls.get({
3939
owner,
4040
repo,
4141
pull_number: context.issue.number,
4242
});
4343

44-
const jobs = await github.checks.listForRef({
44+
const jobs = await github.rest.checks.listForRef({
4545
owner,
4646
repo,
4747
ref: prRef,
@@ -50,8 +50,8 @@ async function run(core, context, github) {
5050

5151
jobs.data.check_runs.forEach(job => {
5252
if (job.conclusion === 'failure' || job.conclusion === 'cancelled') {
53-
console.log("rerun job " + job.name);
54-
github.checks.rerequestSuite({
53+
core.info("rerun job " + job.name);
54+
github.rest.checks.rerequestSuite({
5555
owner,
5656
repo,
5757
check_suite_id: job.check_suite.id

Diff for: .github/actions/tune-runner-vm/action.yml

-7
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ runs:
7676
7777
# stop Azure Linux agent to save RAM
7878
sudo systemctl stop walinuxagent.service || true
79-
80-
# enable docker experimental mode which is
81-
# required for using "docker build --squash" / "-Ddocker.squash=true"
82-
daemon_json="$(sudo cat /etc/docker/daemon.json | jq '.experimental = true')"
83-
echo "$daemon_json" | sudo tee /etc/docker/daemon.json
84-
# restart docker daemon
85-
sudo systemctl restart docker
8679
echo '::endgroup::'
8780
8881
# show memory

Diff for: .github/workflows/bk-ci.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ on:
3232

3333
env:
3434
MAVEN_OPTS: -Xss1500k -Xmx1500m -Daether.connector.http.reuseConnections=false -Daether.connector.requestTimeout=60000 -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true -Dmaven.wagon.http.serviceUnavailableRetryStrategy.class=standard -Dmaven.wagon.rto=60000
35+
NIST_NVD_API_KEY: ${{ secrets.NIST_NVD_API_KEY }}
3536

3637
concurrency:
3738
group: ${{ github.workflow }}-${{ github.ref }}
@@ -84,7 +85,7 @@ jobs:
8485
if: steps.check_changes.outputs.docs_only != 'true'
8586
run: |
8687
mvn -T 1C -B -nsu clean install -Ddistributedlog -DskipTests
87-
mvn -T 1C -B -nsu apache-rat:check checkstyle:check spotbugs:check package -Ddistributedlog -DskipTests
88+
mvn -T 1C -B -nsu apache-rat:check checkstyle:check spotbugs:check spotless:check package -Ddistributedlog -DskipTests
8889
8990
- name: Check license files
9091
if: steps.check_changes.outputs.docs_only != 'true'
@@ -241,7 +242,9 @@ jobs:
241242
run: mvn -B -nsu clean install -Pdocker -DskipTests
242243

243244
- name: Run metadata driver tests
244-
run: mvn -B -nsu -f metadata-drivers/pom.xml test -DintegrationTests
245+
# Exclude jetcd-core-shaded from integration tests, as it’s a POM-only project used internally,
246+
# and maven prioritizes workspace artifacts during testing.
247+
run: mvn -B -nsu -f metadata-drivers/pom.xml -pl '!jetcd-core-shaded' test -DintegrationTests
245248

246249
- name: Run all integration tests (except backward compatibility tests)
247250
run: |

Diff for: .github/workflows/bot.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ jobs:
3434
- name: bot actions
3535
uses: actions/github-script@v7
3636
env:
37-
PROVIDER: 'apache'
38-
REPOSITORY: 'bookkeeper'
3937
RERUN_CMD: 'rerun failure checks'
4038
with:
4139
github-token: ${{secrets.BKBOT_TOKEN}}
4240
script: |
4341
const path = require('path')
4442
const scriptPath = path.resolve('.github/actions/bot/src/run.js')
45-
require(scriptPath)({core}, {context}, {github})
43+
require(scriptPath)({core}, {context}, {github})

Diff for: .github/workflows/owasp-daily-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ on:
2121
- cron: '0 0 * * *' # Runs at 00:00 UTC every day
2222
workflow_dispatch:
2323

24+
env:
25+
NIST_NVD_API_KEY: ${{ secrets.NIST_NVD_API_KEY }}
26+
2427
jobs:
2528
owasp-daily-build:
2629
name: OWASP Dependency Check

Diff for: NOTICE

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Apache BookKeeper
2-
Copyright 2011-2024 The Apache Software Foundation
2+
Copyright 2011-2025 The Apache Software Foundation
33

44
This product includes software developed at
55
The Apache Software Foundation (http://www.apache.org/).
6-

Diff for: bookkeeper-benchmark/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<groupId>org.apache.bookkeeper</groupId>
2424
<version>4.18.0-SNAPSHOT</version>
2525
</parent>
26-
<groupId>org.apache.bookkeeper</groupId>
2726
<artifactId>bookkeeper-benchmark</artifactId>
2827
<name>Apache BookKeeper :: Benchmark</name>
2928
<properties>

Diff for: bookkeeper-common-allocator/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<groupId>io.netty</groupId>
3030
<artifactId>netty-buffer</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.mockito</groupId>
34+
<artifactId>mockito-core</artifactId>
35+
<scope>test</scope>
36+
</dependency>
3237
</dependencies>
3338
<build>
3439
<plugins>

Diff for: bookkeeper-common-allocator/src/main/java/org/apache/bookkeeper/common/allocator/ByteBufAllocatorBuilder.java

+2
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ static ByteBufAllocatorBuilder create() {
9292
* <p>Default is {@link LeakDetectionPolicy#Disabled}
9393
*/
9494
ByteBufAllocatorBuilder leakDetectionPolicy(LeakDetectionPolicy leakDetectionPolicy);
95+
96+
ByteBufAllocatorBuilder exitOnOutOfMemory(boolean exitOnOutOfMemory);
9597
}

Diff for: bookkeeper-common-allocator/src/main/java/org/apache/bookkeeper/common/allocator/impl/ByteBufAllocatorBuilderImpl.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ public class ByteBufAllocatorBuilderImpl implements ByteBufAllocatorBuilder {
3737
OutOfMemoryPolicy outOfMemoryPolicy = OutOfMemoryPolicy.FallbackToHeap;
3838
Consumer<OutOfMemoryError> outOfMemoryListener = null;
3939
LeakDetectionPolicy leakDetectionPolicy = LeakDetectionPolicy.Disabled;
40+
boolean exitOnOutOfMemory = false;
4041

4142
@Override
4243
public ByteBufAllocatorWithOomHandler build() {
4344
return new ByteBufAllocatorImpl(pooledAllocator, unpooledAllocator, poolingPolicy, poolingConcurrency,
44-
outOfMemoryPolicy, outOfMemoryListener, leakDetectionPolicy);
45+
outOfMemoryPolicy, outOfMemoryListener, leakDetectionPolicy, exitOnOutOfMemory);
4546
}
4647

4748
@Override
@@ -86,4 +87,10 @@ public ByteBufAllocatorBuilder leakDetectionPolicy(LeakDetectionPolicy leakDetec
8687
return this;
8788
}
8889

90+
@Override
91+
public ByteBufAllocatorBuilder exitOnOutOfMemory(boolean exitOnOutOfMemory) {
92+
this.exitOnOutOfMemory = exitOnOutOfMemory;
93+
return this;
94+
}
95+
8996
}

Diff for: bookkeeper-common-allocator/src/main/java/org/apache/bookkeeper/common/allocator/impl/ByteBufAllocatorImpl.java

+28-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.bookkeeper.common.allocator.LeakDetectionPolicy;
3030
import org.apache.bookkeeper.common.allocator.OutOfMemoryPolicy;
3131
import org.apache.bookkeeper.common.allocator.PoolingPolicy;
32+
import org.apache.bookkeeper.common.util.ShutdownUtil;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
3435

@@ -48,15 +49,24 @@ public class ByteBufAllocatorImpl extends AbstractByteBufAllocator implements By
4849
private final PoolingPolicy poolingPolicy;
4950
private final OutOfMemoryPolicy outOfMemoryPolicy;
5051
private Consumer<OutOfMemoryError> outOfMemoryListener;
52+
private final boolean exitOnOutOfMemory;
5153

5254
ByteBufAllocatorImpl(ByteBufAllocator pooledAllocator, ByteBufAllocator unpooledAllocator,
5355
PoolingPolicy poolingPolicy, int poolingConcurrency, OutOfMemoryPolicy outOfMemoryPolicy,
5456
Consumer<OutOfMemoryError> outOfMemoryListener,
5557
LeakDetectionPolicy leakDetectionPolicy) {
56-
super(poolingPolicy == PoolingPolicy.PooledDirect /* preferDirect */);
58+
this(pooledAllocator, unpooledAllocator, poolingPolicy, poolingConcurrency, outOfMemoryPolicy,
59+
outOfMemoryListener, leakDetectionPolicy, false);
60+
}
5761

62+
ByteBufAllocatorImpl(ByteBufAllocator pooledAllocator, ByteBufAllocator unpooledAllocator,
63+
PoolingPolicy poolingPolicy, int poolingConcurrency, OutOfMemoryPolicy outOfMemoryPolicy,
64+
Consumer<OutOfMemoryError> outOfMemoryListener,
65+
LeakDetectionPolicy leakDetectionPolicy, boolean exitOnOutOfMemory) {
66+
super(poolingPolicy == PoolingPolicy.PooledDirect /* preferDirect */);
5867
this.poolingPolicy = poolingPolicy;
5968
this.outOfMemoryPolicy = outOfMemoryPolicy;
69+
this.exitOnOutOfMemory = exitOnOutOfMemory;
6070
if (outOfMemoryListener == null) {
6171
this.outOfMemoryListener = (v) -> {
6272
log.error("Unable to allocate memory", v);
@@ -146,7 +156,7 @@ protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
146156
: unpooledAllocator;
147157
return alloc.heapBuffer(initialCapacity, maxCapacity);
148158
} catch (OutOfMemoryError e) {
149-
outOfMemoryListener.accept(e);
159+
consumeOOMError(e);
150160
throw e;
151161
}
152162
}
@@ -166,12 +176,12 @@ private ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity, boolean ca
166176
try {
167177
return unpooledAllocator.heapBuffer(initialCapacity, maxCapacity);
168178
} catch (OutOfMemoryError e2) {
169-
outOfMemoryListener.accept(e2);
179+
consumeOOMError(e2);
170180
throw e2;
171181
}
172182
} else {
173183
// ThrowException
174-
outOfMemoryListener.accept(e);
184+
consumeOOMError(e);
175185
throw e;
176186
}
177187
}
@@ -181,12 +191,24 @@ private ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity, boolean ca
181191
try {
182192
return unpooledAllocator.directBuffer(initialCapacity, maxCapacity);
183193
} catch (OutOfMemoryError e) {
184-
outOfMemoryListener.accept(e);
185-
throw e;
194+
consumeOOMError(e);
195+
throw e;
186196
}
187197
}
188198
}
189199

200+
private void consumeOOMError(OutOfMemoryError outOfMemoryError) {
201+
try {
202+
outOfMemoryListener.accept(outOfMemoryError);
203+
} catch (Throwable e) {
204+
log.warn("Consume outOfMemory error failed.", e);
205+
}
206+
if (exitOnOutOfMemory) {
207+
log.info("Exiting JVM process for OOM error: {}", outOfMemoryError.getMessage(), outOfMemoryError);
208+
ShutdownUtil.triggerImmediateForcefulShutdown();
209+
}
210+
}
211+
190212
@Override
191213
public boolean isDirectBufferPooled() {
192214
return pooledAllocator != null && pooledAllocator.isDirectBufferPooled();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.bookkeeper.common.util;
20+
21+
import java.lang.reflect.InvocationTargetException;
22+
import java.lang.reflect.Method;
23+
import lombok.extern.slf4j.Slf4j;
24+
25+
/**
26+
* Forked from <a href="https://github.com/apache/pulsar">Pulsar</a>.
27+
*/
28+
@Slf4j
29+
public class ShutdownUtil {
30+
private static final Method log4j2ShutdownMethod;
31+
32+
static {
33+
// use reflection to find org.apache.logging.log4j.LogManager.shutdown method
34+
Method shutdownMethod = null;
35+
try {
36+
shutdownMethod = Class.forName("org.apache.logging.log4j.LogManager")
37+
.getMethod("shutdown");
38+
} catch (ClassNotFoundException | NoSuchMethodException e) {
39+
// ignore when Log4j2 isn't found, log at debug level
40+
log.debug("Cannot find org.apache.logging.log4j.LogManager.shutdown method", e);
41+
}
42+
log4j2ShutdownMethod = shutdownMethod;
43+
}
44+
45+
/**
46+
* Triggers an immediate forceful shutdown of the current process.
47+
*
48+
* @param status Termination status. By convention, a nonzero status code indicates abnormal termination.
49+
* @see Runtime#halt(int)
50+
*/
51+
public static void triggerImmediateForcefulShutdown(int status) {
52+
triggerImmediateForcefulShutdown(status, true);
53+
}
54+
public static void triggerImmediateForcefulShutdown(int status, boolean logging) {
55+
try {
56+
if (status != 0 && logging) {
57+
log.warn("Triggering immediate shutdown of current process with status {}", status,
58+
new Exception("Stacktrace for immediate shutdown"));
59+
}
60+
shutdownLogging();
61+
} finally {
62+
Runtime.getRuntime().halt(status);
63+
}
64+
}
65+
66+
private static void shutdownLogging() {
67+
// flush log buffers and shutdown log4j2 logging to prevent log truncation
68+
if (log4j2ShutdownMethod != null) {
69+
try {
70+
// use reflection to call org.apache.logging.log4j.LogManager.shutdown()
71+
log4j2ShutdownMethod.invoke(null);
72+
} catch (IllegalAccessException | InvocationTargetException e) {
73+
log.error("Unable to call org.apache.logging.log4j.LogManager.shutdown using reflection.", e);
74+
}
75+
}
76+
}
77+
78+
/**
79+
* Triggers an immediate forceful shutdown of the current process using 1 as the status code.
80+
*
81+
* @see Runtime#halt(int)
82+
*/
83+
public static void triggerImmediateForcefulShutdown() {
84+
triggerImmediateForcefulShutdown(1);
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
/**
19+
* defines the utilities for allocator used across the project.
20+
*/
21+
package org.apache.bookkeeper.common.util;

0 commit comments

Comments
 (0)