Forest0923 commented on PR #19961:
URL: https://github.com/apache/kafka/pull/19961#issuecomment-3022144635

   I'm not exactly sure why `mmap` became null, but perhaps we need to acquire 
the write lock in `append` or `truncateToEntries()`?
   
   I was able to reproduce the issue locally by increasing `maxOffset` like 
below:
   
   ```diff
   diff --git a/core/src/test/scala/unit/kafka/log/LogConcurrencyTest.scala 
b/core/src/test/scala/unit/kafka/log/LogConcurrencyTest.scala
   index 854be39808..06421fd96a 100644
   --- a/core/src/test/scala/unit/kafka/log/LogConcurrencyTest.scala
   +++ b/core/src/test/scala/unit/kafka/log/LogConcurrencyTest.scala
   @@ -67,7 +67,7 @@ class LogConcurrencyTest {
      def testUncommittedDataNotConsumed(log: UnifiedLog): Unit = {
        val executor = Executors.newFixedThreadPool(2)
        try {
   -      val maxOffset = 5000
   +      val maxOffset = 10000
          val consumer = new ConsumerTask(log, maxOffset)
          val appendTask = new LogAppendTask(log, maxOffset)
   ```
   
   Applying the following change seems to fix the issue:
   
   ```diff
   diff --git 
a/storage/src/main/java/org/apache/kafka/storage/internals/log/OffsetIndex.java 
b/storage/src/main/java/org/apache/kafka/storage/internals/log/OffsetIndex.java
   index 04d68e9a54..89875484f7 100644
   --- 
a/storage/src/main/java/org/apache/kafka/storage/internals/log/OffsetIndex.java
   +++ 
b/storage/src/main/java/org/apache/kafka/storage/internals/log/OffsetIndex.java
   @@ -212,7 +212,7 @@ public final class OffsetIndex extends AbstractIndex {
         * Truncates index to a known number of entries.
         */
        private void truncateToEntries(int entries) {
   -        inLock(() -> {
   +        inRemapWriteLockThrows(() -> {
                super.truncateToEntries0(entries);
                this.lastOffset = lastEntry().offset;
                log.debug("Truncated index {} to {} entries; position is now {} 
and last offset is now {}",
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to