Skip to content

Commit 2ce4f4a

Browse files
committed
Unified code paths into Segment.toProducerPartitionState(). 🤠
1 parent 803da1f commit 2ce4f4a

3 files changed

Lines changed: 28 additions & 37 deletions

File tree

clients/da-vinci-client/src/main/java/com/linkedin/davinci/validation/PartitionTracker.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,35 +244,8 @@ private void updateOffsetRecord(TopicType type, GUID guid, Segment segment, Offs
244244
}
245245

246246
if (state == null) {
247-
state = new ProducerPartitionState();
248-
249-
/**
250-
* The aggregates and debugInfo being stored in the {@link ProducerPartitionState} will add a bit
251-
* of overhead when we checkpoint this metadata to disk, so we should be careful not to add a very
252-
* large number of elements to these arbitrary collections.
253-
* <p>
254-
* In the case of the debugInfo, it is expected (at the time of writing this comment) that all
255-
* partitions produced by the same producer GUID would have the same debug values (though nothing
256-
* precludes us from having per-partition debug values in the future if there is a use case for
257-
* that). It is redundant that we store the same debug values once per partition. In the future,
258-
* if we want to eliminate this redundancy, we could move the per-producer debug info to another
259-
* data structure, though that would increase bookkeeping complexity. This is expected to be a
260-
* minor overhead, and therefore it appears to be premature to optimize this now.
261-
*/
262-
state.aggregates = CollectionUtils.substituteEmptyMap(segment.getAggregates());
263-
state.debugInfo = CollectionUtils.substituteEmptyMap(segment.getDebugInfo());
247+
state = segment.toProducerPartitionState();
264248
}
265-
state.checksumType = segment.getCheckSumType().getValue();
266-
/**
267-
* {@link MD5Digest#getEncodedState()} is allocating a byte array to contain the intermediate state,
268-
* which is expensive. We should only invoke this closure when necessary.
269-
*/
270-
state.checksumState = ByteBuffer.wrap(segment.getCheckSumState());
271-
state.segmentNumber = segment.getSegmentNumber();
272-
state.messageSequenceNumber = segment.getSequenceNumber();
273-
state.messageTimestamp = segment.getLastRecordProducerTimestamp();
274-
state.segmentStatus = segment.getStatus().getValue();
275-
state.isRegistered = segment.isRegistered();
276249

277250
setProducerState(offsetRecord, type, guid, state);
278251
}

internal/venice-common/src/main/java/com/linkedin/venice/kafka/validation/Segment.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,33 @@ private Map<CharSequence, CharSequence> getDedupedDebugInfo(Map<CharSequence, Ch
413413

414414
public ProducerPartitionState toProducerPartitionState() {
415415
ProducerPartitionState pps = new ProducerPartitionState();
416-
pps.segmentNumber = segmentNumber;
417-
pps.segmentStatus = getStatus().getValue();
418-
pps.messageSequenceNumber = sequenceNumber;
419-
pps.checksumState = ByteBuffer.wrap(getCheckSumState());
416+
/**
417+
* The aggregates and debugInfo being stored in the {@link ProducerPartitionState} will add a bit
418+
* of overhead when we checkpoint this metadata to disk, so we should be careful not to add a very
419+
* large number of elements to these arbitrary collections.
420+
* <p>
421+
* In the case of the debugInfo, it is expected (at the time of writing this comment) that all
422+
* partitions produced by the same producer GUID would have the same debug values (though nothing
423+
* precludes us from having per-partition debug values in the future if there is a use case for
424+
* that). It is redundant that we store the same debug values once per partition. In the future,
425+
* if we want to eliminate this redundancy, we could move the per-producer debug info to another
426+
* data structure, though that would increase bookkeeping complexity. This is expected to be a
427+
* minor overhead, and therefore it appears to be premature to optimize this now.
428+
*/
429+
pps.aggregates = CollectionUtils.substituteEmptyMap(getAggregates());
430+
pps.debugInfo = CollectionUtils.substituteEmptyMap(getDebugInfo());
420431
pps.checksumType = getCheckSumType().getValue();
421-
pps.aggregates = aggregates;
422-
pps.debugInfo = debugInfo;
423-
pps.messageTimestamp = lastRecordProducerTimestamp;
424-
pps.isRegistered = registered;
432+
/**
433+
* {@link MD5Digest#getEncodedState()} is allocating a byte array to contain the intermediate,
434+
* which is expensive. We should only invoke this closure when necessary.
435+
*/
436+
pps.checksumState = ByteBuffer.wrap(getCheckSumState());
437+
pps.segmentNumber = getSegmentNumber();
438+
pps.messageSequenceNumber = getSequenceNumber();
439+
pps.messageTimestamp = getLastRecordProducerTimestamp();
440+
pps.segmentStatus = getStatus().getValue();
441+
pps.isRegistered = isRegistered();
442+
425443
return pps;
426444
}
427445

internal/venice-common/src/test/java/com/linkedin/venice/kafka/validation/SegmentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,6 @@ public void testToProducerPartitionState(CheckSumType checkSumType) {
206206
@Test
207207
public void testToProducerPartitionState_NoCheckSum() {
208208
Segment segment = new Segment(1, 1, 1, CheckSumType.NONE, new HashMap<>(), new HashMap<>());
209-
ProducerPartitionState pps = segment.toProducerPartitionState(); // assert does not throw with checksumtype NONE
209+
segment.toProducerPartitionState(); // assert that a NullPointerException is not thrown with checksumtype NONE
210210
}
211211
}

0 commit comments

Comments
 (0)