diff --git a/core/src/main/scala/kafka/log/Log.scala b/core/src/main/scala/kafka/log/Log.scala index 79db610ca90..560be19721d 100644 --- a/core/src/main/scala/kafka/log/Log.scala +++ b/core/src/main/scala/kafka/log/Log.scala @@ -269,14 +269,14 @@ private[kafka] class Log(val dir: File, // assign offsets to the messageset val offsets = if(assignOffsets) { - val firstOffset = nextOffset.get - validMessages = validMessages.assignOffsets(nextOffset, messageSetInfo.codec) - val lastOffset = nextOffset.get - 1 + val offsetCounter = new AtomicLong(nextOffset.get) + val firstOffset = offsetCounter.get + validMessages = validMessages.assignOffsets(offsetCounter, messageSetInfo.codec) + val lastOffset = offsetCounter.get - 1 (firstOffset, lastOffset) } else { if(!messageSetInfo.offsetsMonotonic) throw new IllegalArgumentException("Out of order offsets found in " + messages) - nextOffset.set(messageSetInfo.lastOffset + 1) (messageSetInfo.firstOffset, messageSetInfo.lastOffset) } @@ -285,6 +285,9 @@ private[kafka] class Log(val dir: File, .format(this.name, offsets._1, nextOffset.get(), validMessages)) segment.append(offsets._1, validMessages) + // advance the log end offset + nextOffset.set(offsets._2 + 1) + // return the offset at which the messages were appended offsets }