Skip to content

KAFKA-5761: Serializer API should support ByteBuffer#21656

Open
flore77 wants to merge 1 commit intoapache:trunkfrom
flore77:kip-646
Open

KAFKA-5761: Serializer API should support ByteBuffer#21656
flore77 wants to merge 1 commit intoapache:trunkfrom
flore77:kip-646

Conversation

@flore77
Copy link
Copy Markdown

@flore77 flore77 commented Mar 6, 2026

This implements KIP-646

Summary

  • Adds serializeToByteBuffer() default method to the Serializer interface, returning ByteBuffer instead of byte[]
  • Overrides in built-in serializers (ByteArray, ByteBuffer, Bytes, Integer, Long, Short, Float, Double, Boolean, Void) with optimized implementations that avoid unnecessary copies
  • Updates the producer pipeline (KafkaProducer → RecordAccumulator → ProducerBatch) to use ByteBuffer end-to-end, eliminating byte[] → ByteBuffer wrapping in MemoryRecordsBuilder
  • Adds ByteBuffer overload to Partitioner interface with zero-copy optimization for exact backing arrays
  • Extends Utils.murmur2() and BuiltInPartitioner.partitionForKey() to accept ByteBuffer natively, with byte[] versions delegating to them

Test plan

  • SerializationTest — verifies serializeToByteBuffer() matches serialize() output for all built-in serializers, null handling, and ByteBuffer zero-copy
  • PartitionerTest — verifies default ByteBuffer partition method passes backing array directly (zero-copy) and copies when buffer is a slice
  • KafkaProducerTest — end-to-end producer pipeline with ByteBuffer path
  • RecordAccumulatorTest, ProducerBatchTest, SenderTest, MockProducerTest — existing tests pass via byte[] overloads that delegate to ByteBuffer

@github-actions github-actions bot added triage PRs from the community producer clients labels Mar 6, 2026
@flore77 flore77 changed the title KIP-646: Serializer API should support ByteBuffer KAFKA-5761: Serializer API should support ByteBuffer Mar 6, 2026
@clolov
Copy link
Copy Markdown
Contributor

clolov commented Mar 6, 2026

Hello @flore77! As far as I have seen KIP-646 was never voted on and we can't really make a change before it passes a vote. If you are interested in taking the KIP forward I would first suggest you bump the DISCUSS thread so that people can have the opportunity to raise suggestions. Afterwards, open a VOTE thread and if that passes successfully we can come back to reviewing this PR 😊

@flore77
Copy link
Copy Markdown
Author

flore77 commented Mar 7, 2026

@clolov ack. I was not aware of the voting process, I requested an ASF account to drive this KIP forward. Thanks for letting me know!

@github-actions
Copy link
Copy Markdown

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants