Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Motivation

Lazy initialization for RecordHeader was introduced in KAFKA-10438, improving performance but also creating unexpected side effects.
Since the Consumer is not thread-safe, the same assumption naturally extends to ConsumerRecord. However, users often assume that read-only access across threads is safe.
With lazy initialization, this assumption no longer holds, which can lead to unexpected behavior.
So far, three concurrency-related issues (KAFKA-12999, KAFKA-17725, KAFKA-18470) have been reported in connection with RecordHeader data access.
Making RecordHeader thread-safe would help avoid user confusion and prevent similar issues in the future.

...

Testing will be carried out using the JMH benchmark described above.
If the benchmark completes successfully without any NullPointerException, it demonstrates that RecordHeader is thread-safe.
Furthermore, it confirms that double-checked locking performs significantly better than full-method synchronization.

Rejected Alternatives

Full-Method Synchronization

Although it seems simple, it introduces significant overhead to key()andvalue() on every method invocation.