Skip to content

Commit

Permalink
Make slogger use current class (#3994)
Browse files Browse the repository at this point in the history
### Motivation
We use Slogger to support DirectIO Entrylogger and create the slogger instance in DbLedgerStorage and passed down to DirectIOEntrylogger. However, in the subclasses, we generate a new Slogger instance without setting the context, which leads to the Slogger instance belonging to DbLedgerStorage or Slf4j. The broker logs are as follows.
```
2023-06-19T15:21:56,518+0800 [main] INFO  org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage - ENTRYLOG_IDS_CANDIDATES_SELECTED
2023-06-19T15:21:56,561+0800 [main] INFO  org.apache.bookkeeper.slogger.slf4j.Slf4jSlogger {directory=data/bookkeeper/ledgers/current, event=ENTRYLOGGER_CREATED, maxCachedReaders=32, maxCachedReadersPerThread=4, maxFileSize=1073741824, maxSaneEntrySize=5252620, perThreadBufferSize=33554432, readBufferSize=8388608, singleWriteBufferSize=33554432, totalReadBufferSize=268435456, totalWriteBufferSize=268435456} - ENTRYLOGGER_CREATED
```

Without the specific slogger instance name, it will be hard to configure a specific class to enable KV logger configuration.

### Modification
Set the specific class context for each subclass slogger instance.
After this change, the broker logs are as follows.
```
2023-06-19T16:01:56,685+0800 [main] INFO  org.apache.bookkeeper.bookie.storage.directentrylogger.EntryLogIdsImpl {dirs=[data/bookkeeper/ledgers/current], durationMs=0, event=ENTRYLOG_IDS_CANDIDATES_SELECTED, maxId=21474836
47, nextId=0} - ENTRYLOG_IDS_CANDIDATES_SELECTED
2023-06-19T16:01:56,721+0800 [main] INFO  org.apache.bookkeeper.bookie.storage.directentrylogger.DirectEntryLogger {directory=data/bookkeeper/ledgers/current, event=ENTRYLOGGER_CREATED, maxCachedReaders=32, maxCachedReader
sPerThread=4, maxFileSize=1073741824, maxSaneEntrySize=5252620, perThreadBufferSize=33554432, readBufferSize=8388608, singleWriteBufferSize=33554432, totalReadBufferSize=268435456, totalWriteBufferSize=268435456} - ENTRYLO
GGER_CREATED
```
  • Loading branch information
hangc0276 authored Jun 20, 2023
1 parent 5e9fdc2 commit 8085f66
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private DirectCompactionEntryLog(int srcLogId,
this.srcLogId = srcLogId;
this.dstLogId = dstLogId;

this.slog = slog.kv("dstLogId", dstLogId).kv("srcLogId", srcLogId).ctx();
this.slog = slog.kv("dstLogId", dstLogId).kv("srcLogId", srcLogId).ctx(DirectCompactionEntryLog.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.apache.bookkeeper.bookie.EntryLogMetadata;
import org.apache.bookkeeper.bookie.storage.CompactionEntryLog;
import org.apache.bookkeeper.bookie.storage.EntryLogIds;
import org.apache.bookkeeper.bookie.storage.EntryLogIdsImpl;
import org.apache.bookkeeper.bookie.storage.EntryLogScanner;
import org.apache.bookkeeper.bookie.storage.EntryLogger;
import org.apache.bookkeeper.common.util.nativeio.NativeIO;
Expand Down Expand Up @@ -112,7 +111,7 @@ public DirectEntryLogger(File ledgerDir,
this.maxSaneEntrySize = maxSaneEntrySize;
this.readBufferSize = Buffer.nextAlignment(readBufferSize);
this.ids = ids;
this.slog = slogParent.kv("directory", ledgerDir).ctx();
this.slog = slogParent.kv("directory", ledgerDir).ctx(DirectEntryLogger.class);

this.stats = new DirectEntryLoggerStats(stats);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DirectWriter implements LogWriter {
final ExecutorService writeExecutor;
final Object bufferLock = new Object();
final List<Future<?>> outstandingWrites = new ArrayList<Future<?>>();
final Slogger slog;
Buffer nativeBuffer;
long offset;
private static volatile boolean useFallocate = true;
Expand All @@ -60,6 +61,7 @@ class DirectWriter implements LogWriter {
this.filename = filename;
this.writeExecutor = writeExecutor;
this.nativeIO = nativeIO;
this.slog = slog.ctx(DirectWriter.class);

offset = 0;

Expand All @@ -76,7 +78,7 @@ class DirectWriter implements LogWriter {
if (useFallocate) {
if (!SystemUtils.IS_OS_LINUX) {
disableUseFallocate();
slog.warn(Events.FALLOCATE_NOT_AVAILABLE);
this.slog.warn(Events.FALLOCATE_NOT_AVAILABLE);
} else {
try {
int ret = nativeIO.fallocate(fd, NativeIO.FALLOC_FL_ZERO_RANGE, 0, maxFileSize);
Expand All @@ -85,7 +87,7 @@ class DirectWriter implements LogWriter {
// fallocate(2) is not supported on all filesystems. Since this is an optimization, disable
// subsequent usage instead of failing the operation.
disableUseFallocate();
slog.kv("message", ex.getMessage())
this.slog.kv("message", ex.getMessage())
.kv("file", filename)
.kv("errno", ex.getErrno())
.warn(Events.FALLOCATE_NOT_AVAILABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*
*/
package org.apache.bookkeeper.bookie.storage;
package org.apache.bookkeeper.bookie.storage.directentrylogger;

import java.io.File;
import java.io.IOException;
Expand All @@ -29,7 +29,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.bookkeeper.bookie.LedgerDirsManager;
import org.apache.bookkeeper.bookie.storage.directentrylogger.Events;
import org.apache.bookkeeper.bookie.storage.EntryLogIds;
import org.apache.bookkeeper.slogger.Slogger;
import org.apache.commons.lang3.tuple.Pair;
/**
Expand All @@ -48,7 +48,7 @@ public class EntryLogIdsImpl implements EntryLogIds {
public EntryLogIdsImpl(LedgerDirsManager ledgerDirsManager,
Slogger slog) throws IOException {
this.ledgerDirsManager = ledgerDirsManager;
this.slog = slog;
this.slog = slog.ctx(EntryLogIdsImpl.class);
findLargestGap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
import org.apache.bookkeeper.bookie.LedgerDirsManager;
import org.apache.bookkeeper.bookie.LedgerStorage;
import org.apache.bookkeeper.bookie.StateManager;
import org.apache.bookkeeper.bookie.storage.EntryLogIdsImpl;
import org.apache.bookkeeper.bookie.storage.EntryLogger;
import org.apache.bookkeeper.bookie.storage.directentrylogger.DirectEntryLogger;
import org.apache.bookkeeper.bookie.storage.directentrylogger.EntryLogIdsImpl;
import org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageFactory.DbConfigType;
import org.apache.bookkeeper.bookie.storage.ldb.SingleDirectoryDbLedgerStorage.LedgerLoggerProcessor;
import org.apache.bookkeeper.common.util.MathUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.bookkeeper.bookie.DefaultEntryLogger;
import org.apache.bookkeeper.bookie.LedgerDirsManager;
import org.apache.bookkeeper.bookie.storage.directentrylogger.DirectEntryLogger;
import org.apache.bookkeeper.bookie.storage.directentrylogger.EntryLogIdsImpl;
import org.apache.bookkeeper.common.util.nativeio.NativeIOImpl;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.slogger.Slogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* under the License.
*
*/
package org.apache.bookkeeper.bookie.storage;
package org.apache.bookkeeper.bookie.storage.directentrylogger;

import static org.apache.bookkeeper.bookie.storage.EntryLogTestUtils.logIdFromLocation;
import static org.apache.bookkeeper.bookie.storage.EntryLogTestUtils.makeEntry;
Expand All @@ -33,8 +33,8 @@
import io.netty.buffer.ByteBuf;
import java.io.File;
import org.apache.bookkeeper.bookie.LedgerDirsManager;
import org.apache.bookkeeper.bookie.storage.directentrylogger.DirectCompactionEntryLog;
import org.apache.bookkeeper.bookie.storage.directentrylogger.DirectEntryLogger;
import org.apache.bookkeeper.bookie.storage.EntryLogIds;
import org.apache.bookkeeper.bookie.storage.EntryLogger;
import org.apache.bookkeeper.slogger.Slogger;
import org.apache.bookkeeper.test.TmpDirs;
import org.apache.commons.lang3.tuple.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.bookkeeper.bookie.MockLedgerStorage;
import org.apache.bookkeeper.bookie.TransactionalEntryLogCompactor;
import org.apache.bookkeeper.bookie.storage.CompactionEntryLog;
import org.apache.bookkeeper.bookie.storage.EntryLogIdsImpl;
import org.apache.bookkeeper.bookie.storage.EntryLogScanner;
import org.apache.bookkeeper.bookie.storage.EntryLogger;
import org.apache.bookkeeper.common.util.nativeio.NativeIOImpl;
Expand Down

0 comments on commit 8085f66

Please sign in to comment.