-
Notifications
You must be signed in to change notification settings - Fork 104
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
Cleaning and refactoring block fs for readability #3552
Conversation
@@ -318,22 +318,21 @@ static block_fs_type *block_fs_alloc_empty(const fs::path &mount_file, | |||
|
|||
block_fs->fsync_interval = fsync_interval; | |||
block_fs->block_size = block_size; | |||
{ |
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.
I had a reread parts of "clean code" last night so take this as a highly influenced opinion. Perhaps the block should be extracted as a function?
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.
Can the function be re-used you think?
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.
No, the style used by Robert C. Martin is shorter functions (that do one thing at one abstraction level) where the name serves as documentation, ie.:
static std::tuple<int, int> read_mount_file_header(const fs::path &mount_file){
FILE *stream = util_fopen(mount_file.c_str(), "r");
int id = util_fread_int(stream);
int version = util_fread_int(stream);
fclose(stream);
return {id, version};
}
static void validate_mount_file(const fs::path &mount_file){
auto &[id, version] = read_mount_file_header(mount_file);
if (version != 0)
throw std::runtime_error(fmt::format(
"block_fs data version unexpected. Expected 0, got {}", version));
if (id != MOUNT_MAP_MAGIC_INT)
util_abort("%s: The file:%s does not seem to be a valid block_fs "
"mount map \n",
__func__, mount_file.c_str());
}
static block_fs_type *block_fs_alloc_empty(const fs::path &mount_file,
int block_size, int fsync_interval,
bool read_only) {
block_fs_type *block_fs = new block_fs_type;
UTIL_TYPE_ID_INIT(block_fs, BLOCK_FS_TYPE_ID);
block_fs->fsync_interval = fsync_interval;
block_fs->block_size = block_size;
validate_mount_file(mount_file);
block_fs_reinit(block_fs);
block_fs->data_owner = !read_only;
return block_fs;
}
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.
Also, should that second util_abort
also be a throw std::runtime_error
?
The changes are good. There is more we could do, but I leave it up to you whether you want that it a separate PR. |
Remove unnecessary scoping-brackets. Update outdated docstrings.
Codecov Report
@@ Coverage Diff @@
## main #3552 +/- ##
==========================================
+ Coverage 64.99% 65.01% +0.01%
==========================================
Files 599 599
Lines 46993 46989 -4
Branches 4216 4210 -6
==========================================
+ Hits 30544 30549 +5
+ Misses 15071 15065 -6
+ Partials 1378 1375 -3
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
Read about block_fs and did some clean-up.
Pre review checklist
Adding labels helps the maintainers when writing release notes. This is the list of release note labels.