-
Notifications
You must be signed in to change notification settings - Fork 54
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
Reduce system call #175
Reduce system call #175
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,6 +356,55 @@ Status BackupRestore::backup(FileOps* f_ops, | |
} | ||
} | ||
|
||
Status BackupRestore::backup(FileOps* f_ops, | ||
FileHandle** file, | ||
const std::string& filename, | ||
const SizedBuf& ctx, | ||
size_t length, | ||
size_t bytes_to_skip, | ||
bool call_fsync) | ||
{ | ||
Status s; | ||
std::string dst_file = filename + ".bak"; | ||
|
||
try { | ||
if (!f_ops->exist(dst_file)) { | ||
if (*file) { | ||
f_ops->close(*file); | ||
delete *file; | ||
*file = nullptr; | ||
} | ||
} | ||
|
||
if (!(*file)) { | ||
TC( f_ops->open(file, dst_file) ); | ||
} | ||
|
||
size_t file_size = f_ops->eof(*file); | ||
if (length > bytes_to_skip) { | ||
TC( f_ops->pwrite( *file, | ||
ctx.data + bytes_to_skip, | ||
length - bytes_to_skip, | ||
bytes_to_skip ) ); | ||
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. Indent. |
||
} | ||
if (file_size > length) { | ||
f_ops->ftruncate(*file, length); | ||
} | ||
|
||
if (call_fsync) { | ||
f_ops->fsync(*file); | ||
} | ||
return s; | ||
} catch (Status s) { | ||
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. Should be 4 spaces, currently 3. |
||
if (*file) { | ||
f_ops->close(*file); | ||
delete *file; | ||
*file = nullptr; | ||
} | ||
return s; | ||
} | ||
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. Ditto. |
||
} | ||
|
||
Status BackupRestore::restore(FileOps* f_ops, | ||
const std::string& filename) | ||
{ | ||
|
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.
Shall we need to check whether the file exist in each call? I tested it and even if the file is removed, all system call will success, but no file is persisted.
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.
Do you mean if
dst_file
does not exist, but*file != nullptr
, all belowpwrite
succeeds, but nothing is written? Then yes.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.
Yes. So, shall we need to rebuild the *file pointer here? Or we can ignore this case?
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.
Yes we should, otherwise backup won't be working.