-
Notifications
You must be signed in to change notification settings - Fork 170
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
Using File System "Punch Hole" API for GC #313
Open
v01dstar
wants to merge
23
commits into
tikv:master
Choose a base branch
from
v01dstar:gc-punch-hole
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9dd0342
Add feature switch
v01dstar 05aa72b
Add hole-punch support
v01dstar 4389c79
Save progress
v01dstar e821ebd
Fix some test failures
tonyxuqqi 9e6fb39
Add punch hole test case
tonyxuqqi f9ccccb
Fix punch hole gc
tonyxuqqi 4232feb
Clean up debug prints
tonyxuqqi 41dc96d
Deal with multi-threading
v01dstar 14c8829
Clean up
v01dstar b1686a9
Fix hole punchable block stats
v01dstar 7d642c6
Add post punch hole verification in test
v01dstar 808de9d
Fix macro def
v01dstar 10e03c8
Add debug info
v01dstar 75824b3
Add more debug info, fix update hole_punchable_block bug
v01dstar 7ba8634
Change the way punch hole gc is scheduled
v01dstar c216451
Do not delete input files while doing punch hole gc
v01dstar 6837cf8
Fix update blob file in blob_ranges_ lookup bug
v01dstar c34a728
Refine blob file meta management
v01dstar 898be37
Correct stats
v01dstar d362e9e
Add more logs
v01dstar 1c4a741
Deal with iter errors
v01dstar 6eee534
Fix not passing punch hole meta bug
v01dstar d46d160
Remove unnecessary logs
v01dstar 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 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 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 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,87 @@ | ||
#include "blob_aligned_blocks_collector.h" | ||
|
||
#include "base_db_listener.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
TablePropertiesCollector* | ||
BlobAlignedBlocksCollectorFactory::CreateTablePropertiesCollector( | ||
rocksdb::TablePropertiesCollectorFactory::Context /* context */) { | ||
return new BlobAlignedBlocksCollector(); | ||
} | ||
|
||
const std::string BlobAlignedBlocksCollector::kPropertiesName = | ||
"TitanDB.blob_aligned_blocks"; | ||
|
||
bool BlobAlignedBlocksCollector::Encode( | ||
const std::map<uint64_t, uint64_t>& aligned_blocks, std::string* result) { | ||
PutVarint32(result, static_cast<uint32_t>(aligned_blocks.size())); | ||
for (const auto& f_blocks : aligned_blocks) { | ||
PutVarint64(result, f_blocks.first); | ||
PutVarint64(result, f_blocks.second); | ||
} | ||
return true; | ||
} | ||
bool BlobAlignedBlocksCollector::Decode( | ||
Slice* slice, std::map<uint64_t, uint64_t>* aligned_blocks) { | ||
uint32_t num = 0; | ||
if (!GetVarint32(slice, &num)) { | ||
return false; | ||
} | ||
uint64_t file_number; | ||
uint64_t size; | ||
for (uint32_t i = 0; i < num; ++i) { | ||
if (!GetVarint64(slice, &file_number)) { | ||
return false; | ||
} | ||
if (!GetVarint64(slice, &size)) { | ||
return false; | ||
} | ||
(*aligned_blocks)[file_number] = size; | ||
} | ||
return true; | ||
} | ||
|
||
Status BlobAlignedBlocksCollector::AddUserKey(const Slice& /* key */, | ||
const Slice& value, | ||
EntryType type, | ||
SequenceNumber /* seq */, | ||
uint64_t /* file_size */) { | ||
if (type != kEntryBlobIndex) { | ||
return Status::OK(); | ||
} | ||
|
||
Slice copy = value; | ||
|
||
BlobIndex index; | ||
auto s = index.DecodeFrom(const_cast<Slice*>(©)); | ||
if (!s.ok()) { | ||
return s; | ||
} | ||
|
||
auto iter = aligned_blocks_.find(index.file_number); | ||
if (iter == aligned_blocks_.end()) { | ||
aligned_blocks_[index.file_number] = index.blob_handle.size / 4096 + 1; | ||
} else { | ||
iter->second += index.blob_handle.size / 4096 + 1; | ||
} | ||
|
||
return Status::OK(); | ||
} | ||
|
||
Status BlobAlignedBlocksCollector::Finish(UserCollectedProperties* properties) { | ||
if (aligned_blocks_.empty()) { | ||
return Status::OK(); | ||
} | ||
|
||
std::string res; | ||
bool ok __attribute__((__unused__)) = Encode(aligned_blocks_, &res); | ||
assert(ok); | ||
assert(!res.empty()); | ||
properties->emplace(std::make_pair(kPropertiesName, res)); | ||
return Status::OK(); | ||
} | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |
This file contains 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,56 @@ | ||
#pragma once | ||
|
||
#include "rocksdb/listener.h" | ||
#include "rocksdb/table_properties.h" | ||
#include "util/coding.h" | ||
|
||
#include "blob_file_set.h" | ||
#include "db_impl.h" | ||
|
||
// BlobAlignedBlocksCollector is a TablePropertiesCollector that collects | ||
// the mapping from file number to the number of aligned blocks in the file. | ||
// This information is used by punch hole GC. This is not the same as the | ||
// live_data_size. Because, to use punch hole GC, blobs have to be aligned to | ||
// the file system block size (so that the file is still parsable after holes | ||
// are punched). This is basically live_data_size plus the size of all the | ||
// padding bytes divided by the file system block size. | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
class BlobAlignedBlocksCollectorFactory final | ||
: public TablePropertiesCollectorFactory { | ||
public: | ||
TablePropertiesCollector* CreateTablePropertiesCollector( | ||
TablePropertiesCollectorFactory::Context context) override; | ||
|
||
const char* Name() const override { return "BlobAlignedBlocksCollector"; } | ||
|
||
std::shared_ptr<Logger> info_logger_; | ||
}; | ||
|
||
class BlobAlignedBlocksCollector final : public TablePropertiesCollector { | ||
public: | ||
const static std::string kPropertiesName; | ||
|
||
static bool Encode(const std::map<uint64_t, uint64_t>& aligned_blocks, | ||
std::string* result); | ||
static bool Decode(Slice* slice, | ||
std::map<uint64_t, uint64_t>* aligned_blocks); | ||
|
||
Status AddUserKey(const Slice& key, const Slice& value, EntryType type, | ||
SequenceNumber seq, uint64_t file_size) override; | ||
Status Finish(UserCollectedProperties* properties) override; | ||
UserCollectedProperties GetReadableProperties() const override { | ||
return UserCollectedProperties(); | ||
} | ||
const char* Name() const override { return "BlobAlignedBlocksCollector"; } | ||
|
||
BlobAlignedBlocksCollector() {} | ||
|
||
private: | ||
std::map<uint64_t, uint64_t> aligned_blocks_; | ||
std::shared_ptr<Logger> info_logger_; | ||
}; | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |
This file contains 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 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
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.
please add the comment