-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-4390: Replace MessageSet usage with client-side alternatives #2140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fd0e06b
KAFKA-4390: Replace MessageSet usage with client-side alternatives
hachikuji 0ac2a15
Let ByteBufferLogEntry cache Record instance
hachikuji a4b13ad
Use last offset as offsetOfMaxTimestamp for compressed message sets
hachikuji a90f11c
Fix compresion rate calculation bugs in MemoryRecordsBuilder
hachikuji 3694555
Rename Record.size and LogEntry.size to sizeInBytes for consistency
hachikuji 36068ea
Fill in some of the missing javadocs for Record
hachikuji eef01d6
Always use shallow offset of max timestamp for compressed messages
hachikuji a525530
Remove Message.toFormatVersion and enhance Record conversion tests
hachikuji 7bff341
GroupMetadataManager should use configured timestamp type for offsets…
hachikuji 4968693
Always load file record data lazily
hachikuji 1dbeadf
Ensure producer buffers are deallocated using the initial allocation …
hachikuji cf9b0fd
Various improvements per Guozhang's comments
hachikuji 27ac124
Minor tweaks and doc improvements
hachikuji 4f06bef
More naming/doc tweaks
hachikuji 4e8cf94
Make LogEntry extension constructors private
hachikuji a382de5
Forgotten renamings, cleanup, and buggy offset/timestamp calculation …
hachikuji ef03d29
Missed one renaming
hachikuji ffff0bf
FileRecords positions should be integers
hachikuji a817a76
Cleanup and expand Records javadoc
hachikuji ae0866b
Fix some stale references to log buffer
hachikuji a96750f
Minor cleanup and tightening
hachikuji 620ff2c
Fix Records comment on log entry fields
hachikuji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
clients/src/main/java/org/apache/kafka/common/record/AbstractRecords.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * <p/> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p/> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
| package org.apache.kafka.common.record; | ||
|
|
||
| import org.apache.kafka.common.utils.AbstractIterator; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| public abstract class AbstractRecords implements Records { | ||
|
|
||
| @Override | ||
| public boolean hasMatchingShallowMagic(byte magic) { | ||
| Iterator<? extends LogEntry> iterator = shallowIterator(); | ||
| while (iterator.hasNext()) | ||
| if (iterator.next().magic() != magic) | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Convert this message set to use the specified message format. | ||
| */ | ||
| @Override | ||
| public Records toMessageFormat(byte toMagic) { | ||
| List<LogEntry> converted = new ArrayList<>(); | ||
| Iterator<LogEntry> deepIterator = deepIterator(); | ||
| while (deepIterator.hasNext()) { | ||
| LogEntry entry = deepIterator.next(); | ||
| converted.add(LogEntry.create(entry.offset(), entry.record().convert(toMagic))); | ||
| } | ||
|
|
||
| if (converted.isEmpty()) { | ||
| // This indicates that the message is too large, which indicates that the buffer is not large | ||
| // enough to hold a full log entry. We just return all the bytes in the file message set. | ||
| // Even though the message set does not have the right format version, we expect old clients | ||
| // to raise an error to the user after reading the message size and seeing that there | ||
| // are not enough available bytes in the response to read the full message. | ||
| return this; | ||
| } else { | ||
| // We use the first message to determine the compression type for the resulting message set. | ||
| // This could result in message sets which are either larger or smaller than the original size. | ||
| // For example, it could end up larger if most messages were previously compressed, but | ||
| // it just so happens that the first one is not. There is also some risk that this can | ||
| // cause some timestamp information to be lost (e.g. if the timestamp type was changed) since | ||
| // we are essentially merging multiple message sets. However, currently this method is only | ||
| // used for down-conversion, so we've ignored the problem. | ||
| CompressionType compressionType = shallowIterator().next().record().compressionType(); | ||
| return MemoryRecords.withLogEntries(compressionType, converted); | ||
| } | ||
| } | ||
|
|
||
| public static int estimatedSize(CompressionType compressionType, Iterable<LogEntry> entries) { | ||
| int size = 0; | ||
| for (LogEntry entry : entries) | ||
| size += entry.sizeInBytes(); | ||
| // NOTE: 1024 is the minimum block size for snappy encoding | ||
| return compressionType == CompressionType.NONE ? size : Math.min(Math.max(size / 2, 1024), 1 << 16); | ||
| } | ||
|
|
||
| /** | ||
| * Get the records from this log buffer (note this requires "deep" iteration into the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the reference to "log buffer " still valid? |
||
| * compressed message sets. | ||
| * @return An iterator over the records | ||
| */ | ||
| public Iterator<Record> records() { | ||
| return new AbstractIterator<Record>() { | ||
| private final Iterator<? extends LogEntry> deepEntries = deepIterator(); | ||
| @Override | ||
| protected Record makeNext() { | ||
| if (deepEntries.hasNext()) | ||
| return deepEntries.next().record(); | ||
| return allDone(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we get rid of the re-allocation logic as a whole? Otherwise we cannot remove this additional check I think.