-
Notifications
You must be signed in to change notification settings - Fork 412
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
Raft cache persist improve #5
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c53aaea
Unify PersistedContainer Map, Vector and Set
flowbehappy 960eb85
Add version to Region and RegionFile, and do hashcode check for regio…
flowbehappy a7a42ef
checkObjectHashInFile improvement: only read used object data from file
flowbehappy ad045ed
Bug fix: don't throw exception if region not found in KVStore during …
flowbehappy f4776a9
Improve GC: don't generate empty GC file
flowbehappy 70cb6a2
Fix region persist test cases
flowbehappy 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
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,96 @@ | ||
#include <fcntl.h> | ||
|
||
#include <Storages/Transaction/HashCheckHelper.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
namespace ErrorCodes | ||
{ | ||
extern const int FILE_SIZE_NOT_MATCH; | ||
extern const int FILE_DOESNT_EXIST; | ||
extern const int CANNOT_OPEN_FILE; | ||
extern const int CANNOT_READ_FROM_FILE_DESCRIPTOR; | ||
extern const int UNEXPECTED_END_OF_FILE; | ||
extern const int CHECKSUM_DOESNT_MATCH; | ||
extern const int CANNOT_SEEK_THROUGH_FILE; | ||
} // namespace ErrorCodes | ||
|
||
|
||
namespace FileHashCheck | ||
{ | ||
void readFileFully(const std::string & path, int fd, off_t file_offset, size_t read_size, char * data) | ||
{ | ||
|
||
if (-1 == ::lseek(fd, file_offset, SEEK_SET)) | ||
throwFromErrno("Cannot seek through file " + path, ErrorCodes::CANNOT_SEEK_THROUGH_FILE); | ||
|
||
char * pos = data; | ||
size_t remain = read_size; | ||
while (remain) | ||
{ | ||
auto res = ::read(fd, pos, remain); | ||
if (-1 == res && errno != EINTR) | ||
throwFromErrno("Cannot read from file " + path, ErrorCodes::CANNOT_READ_FROM_FILE_DESCRIPTOR); | ||
if (!res && errno != EINTR) | ||
throwFromErrno("End of file", ErrorCodes::UNEXPECTED_END_OF_FILE); | ||
|
||
remain -= res; | ||
pos += res; | ||
} | ||
} | ||
|
||
void checkObjectHashInFile(const std::string & path, const std::vector<size_t> & object_bytes, const std::vector<bool> & use, | ||
const std::vector<uint128> & expected_hash_codes, size_t block_size) | ||
{ | ||
Poco::File file(path); | ||
size_t file_size = file.getSize(); | ||
size_t total_size = 0; | ||
size_t max_size = 0; | ||
for (auto b : object_bytes) | ||
{ | ||
total_size += b; | ||
max_size = std::max(max_size, b); | ||
} | ||
if (total_size != file_size) | ||
throw Exception("File size not match! Expected: " + DB::toString(total_size) + ", got: " + DB::toString(file_size), | ||
ErrorCodes::FILE_SIZE_NOT_MATCH); | ||
|
||
char * object_data_buf = (char *)malloc(max_size); | ||
SCOPE_EXIT({ free(object_data_buf); }); | ||
|
||
auto fd = open(path.c_str(), O_RDONLY); | ||
if (-1 == fd) | ||
throwFromErrno("Cannot open file " + path, errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE); | ||
SCOPE_EXIT({ ::close(fd); }); | ||
|
||
off_t file_offset = 0; | ||
for (size_t index = 0; index < object_bytes.size(); ++index) | ||
{ | ||
if (use[index]) | ||
{ | ||
uint128 hashcode{0, 0}; | ||
size_t bytes = object_bytes[index]; | ||
char * pos = object_data_buf; | ||
|
||
readFileFully(path, fd, file_offset, bytes, object_data_buf); | ||
|
||
while (bytes) | ||
{ | ||
auto to_cal_bytes = std::min(bytes, block_size); | ||
hashcode = CityHash_v1_0_2::CityHash128WithSeed(pos, to_cal_bytes, hashcode); | ||
pos += to_cal_bytes; | ||
bytes -= to_cal_bytes; | ||
} | ||
|
||
if (hashcode != expected_hash_codes[index]) | ||
throw Exception( | ||
"File " + path + " hash code not match at object index: " + DB::toString(index), ErrorCodes::CHECKSUM_DOESNT_MATCH); | ||
} | ||
|
||
file_offset += object_bytes[index]; | ||
} | ||
} | ||
} // namespace FileHashCheck | ||
|
||
} // namespace DB |
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.
maybe we can make abstraction in the concept of Iterator later if have time.
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.
The problem is map use K and V, while others use T only. I can unify map by std::pair<K, V>, but not user friendly.