-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15194-Prepend-Offset-as-Filename #14057
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,9 +59,9 @@ | |
| * the local tiered storage: | ||
| * | ||
| * <code> | ||
| * / storage-directory / topic-partition-uuidBase64 / oAtiIQ95REujbuzNd_lkLQ.log | ||
| * . oAtiIQ95REujbuzNd_lkLQ.index | ||
| * . oAtiIQ95REujbuzNd_lkLQ.timeindex | ||
| * / storage-directory / topic-partition-uuidBase64 / startOffset-oAtiIQ95REujbuzNd_lkLQ.log | ||
|
Member
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. nit Please replace "startOffset" with dummy values.
Contributor
Author
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. Sure. I've added a dummy value there. |
||
| * . startOffset-oAtiIQ95REujbuzNd_lkLQ.index | ||
| * . startOffset-oAtiIQ95REujbuzNd_lkLQ.timeindex | ||
| * </code> | ||
| */ | ||
| public final class RemoteLogSegmentFileset { | ||
|
|
@@ -73,9 +73,9 @@ public final class RemoteLogSegmentFileset { | |
| * The name of each of the files under the scope of a log segment (the log file, its indexes, etc.) | ||
| * follows the structure UUID-FileType. | ||
| */ | ||
| private static final Pattern FILENAME_FORMAT = compile("([a-zA-Z0-9_-]{22})(\\.[a-z_]+)"); | ||
| private static final int GROUP_UUID = 1; | ||
| private static final int GROUP_FILE_TYPE = 2; | ||
| private static final Pattern FILENAME_FORMAT = compile("(\\d+-)([a-zA-Z0-9_-]{22})(\\.[a-z_]+)"); | ||
| private static final int GROUP_UUID = 2; | ||
| private static final int GROUP_FILE_TYPE = 3; | ||
|
|
||
| /** | ||
| * Characterises the type of a file in the local tiered storage copied from Apache Kafka's standard storage. | ||
|
|
@@ -98,10 +98,10 @@ public enum RemoteLogSegmentFileType { | |
|
|
||
| /** | ||
| * Provides the name of the file of this type for the given UUID in the local tiered storage, | ||
| * e.g. uuid.log. | ||
| * e.g. 0-uuid.log. | ||
| */ | ||
| public String toFilename(final Uuid uuid) { | ||
| return uuid.toString() + suffix; | ||
| public String toFilename(final long startOffset, final Uuid uuid) { | ||
| return startOffset + "-" + uuid.toString() + suffix; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -155,19 +155,21 @@ public String getSuffix() { | |
| * the log segment offloaded are not created on the file system until transfer happens. | ||
| * | ||
| * @param storageDir The root directory of the local tiered storage. | ||
| * @param id Remote log segment id assigned to a log segment in Kafka. | ||
| * @param metadata Remote log metadata about a topic partition's remote log. | ||
| * @return A new fileset instance. | ||
| */ | ||
| public static RemoteLogSegmentFileset openFileset(final File storageDir, final RemoteLogSegmentId id) { | ||
| public static RemoteLogSegmentFileset openFileset(final File storageDir, final RemoteLogSegmentMetadata metadata) { | ||
|
|
||
| final RemoteTopicPartitionDirectory tpDir = openTopicPartitionDirectory(id.topicIdPartition(), storageDir); | ||
| final RemoteTopicPartitionDirectory tpDir = openTopicPartitionDirectory( | ||
| metadata.remoteLogSegmentId().topicIdPartition(), storageDir); | ||
| final File partitionDirectory = tpDir.getDirectory(); | ||
| final Uuid uuid = id.id(); | ||
| final Uuid uuid = metadata.remoteLogSegmentId().id(); | ||
| final long startOffset = metadata.startOffset(); | ||
|
|
||
| final Map<RemoteLogSegmentFileType, File> files = stream(RemoteLogSegmentFileType.values()) | ||
| .collect(toMap(identity(), type -> new File(partitionDirectory, type.toFilename(uuid)))); | ||
| .collect(toMap(identity(), type -> new File(partitionDirectory, type.toFilename(startOffset, uuid)))); | ||
|
|
||
| return new RemoteLogSegmentFileset(tpDir, id, files); | ||
| return new RemoteLogSegmentFileset(tpDir, metadata.remoteLogSegmentId(), files); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -183,7 +185,7 @@ public static RemoteLogSegmentFileset openExistingFileset(final RemoteTopicParti | |
| try { | ||
| final Map<RemoteLogSegmentFileType, File> files = | ||
| Files.list(tpDirectory.getDirectory().toPath()) | ||
| .filter(path -> path.getFileName().toString().startsWith(uuid.toString())) | ||
| .filter(path -> path.getFileName().toString().contains(uuid.toString())) | ||
| .collect(toMap(path -> getFileType(path.getFileName().toString()), Path::toFile)); | ||
|
|
||
| final Set<RemoteLogSegmentFileType> expectedFileTypes = stream(RemoteLogSegmentFileType.values()) | ||
|
|
||
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.
Ideally, we want the test implementation to be as close to the actual log file implementation as possible. Considering that, could we use
LogFileUtils#logFile(File dir, long offset)here? Same for index file names.Uh oh!
There was an error while loading. Please reload this page.
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.
@divijvaidya Thanks for your feedback. I think the actual log file was named as [offset.filetype]. Looking at the implementation of
LogFileUtils#logFile(File dir, long offset), I don't think it will allow us to insert a uuid in the middle as part of the filename.If we are to keep the
[offset-uuid.filetype]pattern, instead of usingLogFileUtils#logFile(File dir, long offset), maybe we should makeLogFileUtils#filenamePrefixFromOffset(long offset)as a public method so that we can construct a real offset using this method. What do you think ?FYI, the method to create these offloaded files is
RemoteLogSegmentFileset#openFileset(final File storageDir, final RemoteLogSegmentId id). Currently my PR has changed this method to acceptRemoteLogSegmentMetadatainstead ofRemoteLogSegmentId, get offset from metadata, and prepend it to the filename. (So yes, it's not close to the actual log file implementation, as the offset was just "0" without formatting, instead of "0000000")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.
Ack. I missed that.
Yes please. Let's use that.
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.
@divijvaidya I've changed the code to use
LogFileUtils#filenamePrefixFromOffset(long offset). The filename now should look like a real log file implementation like00000000000000000011-oAtiIQ95REujbuzNd_lkLQ.log