-
Notifications
You must be signed in to change notification settings - Fork 283
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
Prevent parallel writes to rotational media #176
base: main
Are you sure you want to change the base?
Prevent parallel writes to rotational media #176
Conversation
61db4da
to
e1208a5
Compare
bdc9db5
to
c2f2cb6
Compare
since there's no way to gracefully abort plotting (yet), it's likely to be killed with |
@arvidn Yes, it's released automatically if process is killed. |
c2f2cb6
to
c77eb7a
Compare
@arvidn Added logging of time taken to acquire the lock / repushed. |
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.
this looks reasonable to me. I just have some minor nitpicks. Let's see what @wjblanke thinks about it
c77eb7a
to
f069c53
Compare
@arvidn Added all the changes and cleaned up the commits. |
e1e5f98
to
adffb0d
Compare
Fixed merge conflicts. |
Please do not merge, found a problem with symlink (i.e. /mnt/dest -> /mnt/real-hdd) being incorrectly being detected as non-rotational media. |
When multiple plotter instances are working, use flock to prevent them from copying files to destination disk simultaneously on rotational media. Assume media is non-rotational by default. Linux only, on Windows and MacOS the behavior is unchanged.
adffb0d
to
7988adc
Compare
Now works correctly with symlinks. |
@arvidn It was incorrect to zero-out minor device id. I changed the logic to generate a device path using both major and minor id, resolve the resulting symlink then traverse the final path up to the root looking for "queue/rotational". If not found, media is assumed to be non-rotational. Example:
|
@arvidn Would it be possible to merge this PR? If any changes needed, please let me know. |
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.
Ideally there would be unit tests for as much of this as possible. A test that makes sure the directory lock works shouldn't be too difficult, and a test that ensures that the device ID returns something looking like what is expected also shouldn't be too hard.
Is there anything else that could be unit tested on CI?
#if defined(__APPLE__) || defined(_WIN32) | ||
return false; | ||
#else | ||
struct stat s{}; |
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 think this function is linux specific, right?
It should be conditioned by __linux__
, since right now it's for everything except MacOS and Windows.
I also think it should have a comment explaining what it does and why it works. Ideally with links to documentation stating that the assumptions made by this function are safe to make.
namespace DiskUtil { | ||
|
||
#if !defined(__APPLE__) && !defined(_WIN32) | ||
inline fs::path DevicePath(dev_t dev_id) |
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.
this function also looks linux specific, it should be conditioned by __linux__
.
Is the assumptions made by this function a part of the kernel or user space distro? Presumably the former, some links to documentations would be nice for readers.
} | ||
|
||
inline int LockDirectory( | ||
std::string dirname) |
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.
is there a good reason for this to be string
instead of fs::path
?
@@ -373,8 +381,14 @@ class DiskPlotter { | |||
} | |||
} else { | |||
if (!bCopied) { | |||
bool should_lock = DiskUtil::ShouldLock(final_dirname); |
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.
this should probably be const
@@ -153,9 +156,14 @@ class DiskPlotter { | |||
} | |||
#endif /* defined(_WIN32) || defined(__x86_64__) */ | |||
|
|||
const char is_parallel_writing_enabled = !DiskUtil::ShouldLock(final_dirname); |
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 name suggests that this should be a bool
, yet, it's a char
. Is there a good reason for this?
'This PR has been flagged as stale due to no activity for over 60 |
During parallel plotting when copying multiple plots to dest simultaneously, if dest is HDD it'll result in slowdown and FS fragmentation.
This patch tries to detect whether dest is rotational media and if so, uses flock() to prevent multiple simultaneous writes to dest.
Linux only, on other platforms the behavior is unchanged.
Adds a log message notifying if parallel writing is enabled: