Skip to content

Commit ce7c5b8

Browse files
committed
produce: set MaxTimestamp
Similar to other clients, set the MaxTimestamp computed from the records in the batch. Signed-off-by: Tyler Rockwood <[email protected]>
1 parent 60592f6 commit ce7c5b8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

produce_set.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ func (ps *produceSet) buildRequest() *ProduceRequest {
164164
rb := set.recordsToSend.RecordBatch
165165
if len(rb.Records) > 0 {
166166
rb.LastOffsetDelta = int32(len(rb.Records) - 1)
167+
var maxTimestampDelta time.Duration
167168
for i, record := range rb.Records {
168169
record.OffsetDelta = int64(i)
170+
maxTimestampDelta = max(maxTimestampDelta, record.TimestampDelta)
169171
}
172+
// Also set the MaxTimestamp similar to the
173+
rb.MaxTimestamp = rb.FirstTimestamp.Add(maxTimestampDelta)
170174
}
171175

172176
// Set the batch as transactional when a transactionalID is set

produce_set_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func TestProduceSetV3RequestBuilding(t *testing.T) {
260260
if !batch.FirstTimestamp.Equal(now.Truncate(time.Millisecond)) {
261261
t.Errorf("Wrong first timestamp: %v", batch.FirstTimestamp)
262262
}
263+
if !batch.MaxTimestamp.Equal(now.Add(9 * time.Second).Truncate(time.Millisecond)) {
264+
t.Errorf("Wrong max timestamp: %v", batch.MaxTimestamp)
265+
}
263266
for i := 0; i < 10; i++ {
264267
rec := batch.Records[i]
265268
if rec.TimestampDelta != time.Duration(i)*time.Second {

0 commit comments

Comments
 (0)