What does the values of Position under apache kafka partiton log?

Viewed 106

What does the values of the position under the below log file mean?

Starting offset: 0
offset: 0 position: 0 CreateTime: 1541783974960 isvalid: true keysize: -1 valuesize: 10 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] payload: Spam_Mail1
offset: 1 position: 78 CreateTime: 1541784566896 isvalid: true keysize: -1 valuesize: 0 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] payload: 
offset: 2 position: 146 CreateTime: 1541784725893 isvalid: true keysize: -1 valuesize: 0 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] payload:
1 Answers

The position attribute represents the physical position of the message in the segment log file.

The same attribute is also available in the position index file along with the offset.

When a consumer sends a fetch request for a message at offset x, the brokers looks for the offset closest to offset x in the index file, takes the position value from that index file and goes to that position in the log file (the one you are referring to in your question) to fetch the message.

Hope this helps!

Related