How to handle registered file rotations? (Opening a new file that all later ops should use) #1011
-
My application is attempting to write to an append-only file, and rotate to a new file once it hits a certain size. To achieve this, I have a loop which roughly looks like this (very much psudo-code, do the obvious translation from function calls to SQE allocation and filling. Also assume all operations specify const int file = 0; // Always using a single registered file.
off_t offset = 0;
while (true) {
for (auto w : readyToWrite) {
write(file, w, offset);
offset += w.size();
}
if (lastFsyncHasCompleted) {
fsync(file, IOSQE_IO_DRAIN);
if (offset >= kFileRotateSize) {
open(file, makeNextFileName(), IOSQE_IO_DRAIN); // Also closes the already open file.
offset = 0;
nop(IOSQE_DRAIN); // instead of marking next op (whatever it is) with DRAIN
}
io_uring_enter();
// Process completion events
} I have a few questions about if this is valid and the best approach:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
First of all, I always discourage people for using
All requests can get executed asynchronous in parallel, so unless you put some ordering requests might execute in random order.
This may close first and write will fail with
It may successfully open first, replace the file in the table, and then the write will be issued to the new file.
There is
You can only safe the new file once you see the open completion, that's it unless you do some ordering with
Yes, it's valid
It should be. I'd encourage you to write a test and hopefully donate it to liburing :)
|
Beta Was this translation helpful? Give feedback.
First of all, I always discourage people for using
DRAIN
, as its performance is miserable, maintaining it is hard, there will cases when using drain once in past would be slowing down the ring for its entire lifetime, and there are even features incompatible withDRAIN
(e.g.IOSQE_CQE_SKIP_SUCCESS
). Instead, userspace can count the number of inflight requests for a file.All requests can get executed asynchronous in parallel, so unl…