BP-47 (task6): Direct I/O entrylogger support (#3263) master
authorHang Chen <chenhang@apache.org>
Thu, 23 Jun 2022 02:19:15 +0000 (10:19 +0800)
committerGitHub <noreply@github.com>
Thu, 23 Jun 2022 02:19:15 +0000 (19:19 -0700)
commit677ccec3eb84f5be1b3556537871e14eb5e8359c
tree87f09aec26e7d6224390c54d4f8a6161cb43514a
parent8d4b9e2ce436977356f882ef39096e8281e56ebd
BP-47 (task6): Direct I/O entrylogger support (#3263)

* Direct I/O entry log support

The implementation uses JNI to do direct I/O to files via posix
syscalls. Fallocate is used if running on linux, otherwise this is
skipped (at the cost of more filesystem operates during writing).

There are two calls to write, writeAt and writeDelimited. I expect
writeAt to be used for the entrylog headers, which entries will go
through writeDelimited. In both cases, the calls may return before the
syscalls occur. #flush() needs to be called to ensure things are
actually written.

The entry log format isn't much changed from what is used by the
existing entrylogger. The biggest difference is the padding. Direct
I/O must write in aligned blocked. The size of the alignment varies by
machine configuration, but 4K is a safe bet on most. As it is unlikely
that entry data will land exactly on the alignment boundary, we need
to add padding to writes. The existing entry logger has been changed
to take this padding into account. When read as a signed int/long/byte
the padding will aways parse to a negative value, which distinguishes
it from valid entry data (the entry size will always be positive) and
also from preallocated space (which is always 0).

Another difference in the format is that the header is now 4K rather
than 1K. Again, this is to allow aligned rights. No changes are
necessary to allow the existing entry logger to deal with the header
change, as we create a dummy entry in the extra header space that the
existing entry logger already knows to ignore.

To enable, set dbStorage_directIOEntryLogger=true in the configuration.

(cherry picked from commit 09a1c81b6894d4398c5a59e54cc18784550badb5)

* format code

* format code

* fix spotbugs check

* fix jnilib not found

* fix jnilib not found

* address comments

* fix so lib not found

* address comments

* format code

* add compat test

* add compat test

* address comments

* fix findbugs failed

* format code

Co-authored-by: Ivan Kelly <ikelly@splunk.com>
31 files changed:
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/AbstractLogCompactor.java
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLocation.java
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/EntryLogIds.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/EntryLogIdsImpl.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectCompactionEntryLog.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLoggerStats.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectReader.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectWriter.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/Events.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/Header.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/LogMetadata.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/LogReader.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/LogReaderScan.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/LogWriter.java [new file with mode: 0644]
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/WriterWithMetadata.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/GarbageCollectorThreadTest.java
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/MockLedgerStorage.java
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/EntryLogTestUtils.java
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/MockEntryLogIds.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/TestEntryLogIds.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestBuffer.java [moved from bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/BufferTest.java with 99% similarity]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestDirectEntryLogger.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestDirectEntryLoggerCompat.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestDirectReader.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestDirectWriter.java [new file with mode: 0644]
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestTransactionalEntryLogCompactor.java [new file with mode: 0644]
native-io/pom.xml
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOJni.java
pom.xml