Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -22,21 +22,17 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;
import org.apache.bookkeeper.common.conf.ComponentConfiguration;
import org.apache.bookkeeper.stats.StatsLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A mix of {@link AbstractComponent} and {@link LifecycleComponent}.
*/
@Slf4j
@CustomLog
public abstract class AbstractLifecycleComponent<ConfT extends ComponentConfiguration>
extends AbstractComponent<ConfT> implements LifecycleComponent {

private static final Logger LOG = LoggerFactory.getLogger(AbstractLifecycleComponent.class);

protected final Lifecycle lifecycle = new Lifecycle();
private final Set<LifecycleListener> listeners = new CopyOnWriteArraySet<>();
protected final StatsLogger statsLogger;
Expand Down Expand Up @@ -82,9 +78,12 @@ public void start() {
try {
doStart();
} catch (Throwable exc) {
LOG.error("Failed to start Component: {}", getName(), exc);
log.error()
.exception(exc)
.attr("component", getName())
.log("Failed to start component");
if (uncaughtExceptionHandler != null) {
LOG.error("Calling uncaughtExceptionHandler");
log.error("Calling uncaughtExceptionHandler");
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), exc);
} else {
throw exc;
Expand Down Expand Up @@ -122,7 +121,10 @@ public void close() {
try {
doClose();
} catch (IOException e) {
log.warn("failed to close {}", componentName, e);
log.warn()
.exception(e)
.attr("component", componentName)
.log("Failed to close component");
}
listeners.forEach(LifecycleListener::afterClose);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.CustomLog;

/**
* Allows for AutoClosable resources to be added to the component
* lifecycle without having to implement ServerLifecycleComponent directly.
*/
@CustomLog
public class AutoCloseableLifecycleComponent implements LifecycleComponent {
private static final Logger LOG = LoggerFactory.getLogger(AutoCloseableLifecycleComponent.class);

protected final Lifecycle lifecycle = new Lifecycle();
private final Set<LifecycleListener> listeners = new CopyOnWriteArraySet<>();
Expand Down Expand Up @@ -100,7 +99,10 @@ public void close() {
try {
closeable.close();
} catch (Exception e) {
LOG.warn("failed to close {}", componentName, e);
log.warn()
.exception(e)
.attr("component", componentName)
.log("Failed to close component");
}
listeners.forEach(LifecycleListener::afterClose);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;

/**
* A simple wrapper for a {@link Runnable} that logs any exception thrown by it, before
* re-throwing it.
*/
@Slf4j
@CustomLog
public final class LogExceptionRunnable implements Runnable {

private final Runnable task;
Expand All @@ -41,7 +41,10 @@ public void run() {
try {
task.run();
} catch (Throwable t) {
log.error("Exception while executing runnable " + task, t);
log.error()
.exception(t)
.attr("task", task)
.log("Exception while executing runnable");
Throwables.throwIfUnchecked(t);
throw new AssertionError(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;
import org.apache.bookkeeper.common.util.affinity.CpuAffinity;
import org.apache.bookkeeper.stats.Gauge;
import org.apache.bookkeeper.stats.NullStatsLogger;
Expand All @@ -56,7 +56,7 @@
* achieved by hashing the key objects to threads by their {@link #hashCode()}
* method.
*/
@Slf4j
@CustomLog
public class OrderedExecutor implements ExecutorService {
public static final int NO_TASK_LIMIT = -1;
private static final int DEFAULT_MAX_ARRAY_QUEUE_SIZE = 10_000;
Expand Down Expand Up @@ -205,7 +205,10 @@ public void run() {
long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos);
taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS);
if (elapsedMicroSec >= warnTimeMicroSec) {
log.warn("Runnable {} took too long {} micros to execute.", runnableClass, elapsedMicroSec);
log.warn()
.attr("runnable", runnableClass)
.attr("elapsedMicroSec", elapsedMicroSec)
.log("Runnable took too long to execute");
}
}
}
Expand Down Expand Up @@ -235,7 +238,10 @@ public T call() throws Exception {
long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos);
taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS);
if (elapsedMicroSec >= warnTimeMicroSec) {
log.warn("Callable {} took too long {} micros to execute.", callableClass, elapsedMicroSec);
log.warn()
.attr("callable", callableClass)
.attr("elapsedMicroSec", elapsedMicroSec)
.log("Callable took too long to execute");
}
}
}
Expand Down Expand Up @@ -419,8 +425,9 @@ protected OrderedExecutor(String baseName, int numThreads, ThreadFactory threadF
try {
CpuAffinity.acquireCore();
} catch (Throwable t) {
log.warn("Failed to acquire CPU core for thread {}: {}", Thread.currentThread().getName(),
t.getMessage(), t);
log.warn().exception(t)
.attr("thread", Thread.currentThread().getName())
.log("Failed to acquire CPU core for thread");
}
}
}).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@

package org.apache.bookkeeper.common.util;

import io.github.merlimat.slog.Logger;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A runnable that catches runtime exceptions.
*/
@FunctionalInterface
public interface SafeRunnable extends Runnable {

Logger LOGGER = LoggerFactory.getLogger(SafeRunnable.class);
Logger LOGGER = Logger.get(SafeRunnable.class);

@Override
default void run() {
try {
safeRun();
} catch (Throwable t) {
LOGGER.error("Unexpected throwable caught ", t);
LOGGER.error().exception(t).log("Unexpected throwable caught");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import lombok.CustomLog;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.LogEvent;
Expand All @@ -40,14 +41,12 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test that decorators applied by OrderedExecutor/Scheduler are correctly applied.
*/
@CustomLog
public class TestOrderedExecutorDecorators {
private static final Logger log = LoggerFactory.getLogger(TestOrderedExecutorDecorators.class);
private static final String MDC_KEY = "mdc-key";

private NullAppender mockAppender;
Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-all.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [64]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-compression-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -422,6 +423,7 @@ Apache Software License, Version 2.
[61] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[62] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[63] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[64] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-bkctl.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [59]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-common-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -355,6 +356,7 @@ Apache Software License, Version 2.
[56] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[57] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[58] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[59] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-server.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [63]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-compression-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -417,6 +418,7 @@ Apache Software License, Version 2.
[60] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[61] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[62] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[63] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
24 changes: 24 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# 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.
#

# this is the top level Lombok configuration file
# see https://projectlombok.org/features/configuration for reference

config.stopBubbling = true
lombok.log.custom.declaration = io.github.merlimat.slog.Logger io.github.merlimat.slog.Logger.get(TYPE)
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<rocksdb.version>9.9.3</rocksdb.version>
<shrinkwrap.version>3.3.0</shrinkwrap.version>
<slf4j.version>2.0.12</slf4j.version>
<slog.version>0.9.8</slog.version>
<snakeyaml.version>2.0</snakeyaml.version>
<spotbugs-annotations.version>4.6.0</spotbugs-annotations.version>
<spotless.version>2.43.0</spotless.version>
Expand Down Expand Up @@ -273,6 +274,11 @@
</dependency>

<!-- logging dependencies -->
<dependency>
<groupId>io.github.merlimat.slog</groupId>
<artifactId>slog</artifactId>
<version>${slog.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-bom</artifactId>
Expand Down Expand Up @@ -882,6 +888,10 @@
</dependency>

<!-- compilation dependencies (available at all classpaths) -->
<dependency>
<groupId>io.github.merlimat.slog</groupId>
<artifactId>slog</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Loading