-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28805: Chunked persistence of backing map for persistent bucket cache. #6183
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| */ | ||
| package org.apache.hadoop.hbase.io.hfile.bucket; | ||
|
|
||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
|
|
@@ -45,28 +46,45 @@ private BucketProtoUtils() { | |
|
|
||
| } | ||
|
|
||
| static BucketCacheProtos.BucketCacheEntry toPB(BucketCache cache) { | ||
| static BucketCacheProtos.BucketCacheEntry toPB(BucketCache cache, BucketCacheProtos.BackingMap backingMap) { | ||
| return BucketCacheProtos.BucketCacheEntry.newBuilder().setCacheCapacity(cache.getMaxSize()) | ||
| .setIoClass(cache.ioEngine.getClass().getName()) | ||
| .setMapClass(cache.backingMap.getClass().getName()) | ||
| .putAllDeserializers(CacheableDeserializerIdManager.save()) | ||
| .putAllCachedFiles(toCachedPB(cache.fullyCachedFiles)) | ||
| .setBackingMap(BucketProtoUtils.toPB(cache.backingMap)) | ||
| .setBackingMap(backingMap) | ||
| .setChecksum(ByteString | ||
| .copyFrom(((PersistentIOEngine) cache.ioEngine).calculateChecksum(cache.getAlgorithm()))) | ||
| .build(); | ||
| } | ||
|
|
||
| private static BucketCacheProtos.BackingMap toPB(Map<BlockCacheKey, BucketEntry> backingMap) { | ||
| static void toPB(BucketCache cache, FileOutputStream fos, long chunkSize) throws IOException{ | ||
|
||
| int blockCount = 0; | ||
| int chunkCount = 0; | ||
| int backingMapSize = cache.backingMap.size(); | ||
| BucketCacheProtos.BackingMap.Builder builder = BucketCacheProtos.BackingMap.newBuilder(); | ||
| for (Map.Entry<BlockCacheKey, BucketEntry> entry : backingMap.entrySet()) { | ||
| builder.addEntry(BucketCacheProtos.BackingMapEntry.newBuilder().setKey(toPB(entry.getKey())) | ||
| .setValue(toPB(entry.getValue())).build()); | ||
| for (Map.Entry<BlockCacheKey, BucketEntry> entry : cache.backingMap.entrySet()) { | ||
| blockCount++; | ||
| builder.addEntry(BucketCacheProtos.BackingMapEntry.newBuilder() | ||
| .setKey(BucketProtoUtils.toPB(entry.getKey())) | ||
| .setValue(BucketProtoUtils.toPB(entry.getValue())).build()); | ||
| if (blockCount % chunkSize == 0 || (blockCount == backingMapSize)) { | ||
| chunkCount++; | ||
| if (chunkCount == 1) { | ||
| // Persist all details along with the first chunk into BucketCacheEntry | ||
| BucketProtoUtils.toPB(cache, builder.build()).writeDelimitedTo(fos); | ||
| } else { | ||
| // Directly persist subsequent backing-map chunks. | ||
| builder.build().writeDelimitedTo(fos); | ||
| } | ||
| if (blockCount < backingMapSize) { | ||
| builder = BucketCacheProtos.BackingMap.newBuilder(); | ||
| } | ||
| } | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| private static BucketCacheProtos.BlockCacheKey toPB(BlockCacheKey key) { | ||
| static BucketCacheProtos.BlockCacheKey toPB(BlockCacheKey key) { | ||
| return BucketCacheProtos.BlockCacheKey.newBuilder().setHfilename(key.getHfileName()) | ||
| .setOffset(key.getOffset()).setPrimaryReplicaBlock(key.isPrimary()) | ||
| .setBlockType(toPB(key.getBlockType())).build(); | ||
|
|
@@ -103,7 +121,7 @@ private static BucketCacheProtos.BlockType toPB(BlockType blockType) { | |
| } | ||
| } | ||
|
|
||
| private static BucketCacheProtos.BucketEntry toPB(BucketEntry entry) { | ||
| static BucketCacheProtos.BucketEntry toPB(BucketEntry entry) { | ||
| return BucketCacheProtos.BucketEntry.newBuilder().setOffset(entry.offset()) | ||
| .setCachedTime(entry.getCachedTime()).setLength(entry.getLength()) | ||
| .setDiskSizeWithHeader(entry.getOnDiskSizeWithHeader()) | ||
|
|
||
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
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.
Since we are already passing the output stream to BucketProtoUtils, who's now also responsible for serialization, can we just move everything there?
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
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