private void updateRetainedBatchMetadata(long maxTimestamp, long shallowOffsetOfMaxTimestamp, long maxOffset,
                                                 int messagesRetained, int bytesRetained) {
            validateBatchMetadata(maxTimestamp, shallowOffsetOfMaxTimestamp, maxOffset);
            if (maxTimestamp > this.maxTimestamp) {
                this.maxTimestamp = maxTimestamp;
                this.shallowOffsetOfMaxTimestamp = shallowOffsetOfMaxTimestamp;
            }
            this.maxOffset = Math.max(maxOffset, this.maxOffset);
            this.messagesRetained += messagesRetained;
            this.bytesRetained += bytesRetained;
        }
Check whether a record should be retained in the log. Note that {@link #checkBatchRetention(RecordBatch)}
is used prior to checking individual record retention. Only records from batches which were not
explicitly discarded with {@link BatchRetention#DELETE} will be considered.
clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java