fsync the old aof file when open a new INCR AOF#11004
fsync the old aof file when open a new INCR AOF#11004oranagra merged 3 commits intoredis:unstablefrom
Conversation
|
interesting... you're right that it'll not be fsynced in time (or even at all). p.s. in theory we can use SYNC_FILE_RANGE_WRITE without waiting (and no need for a thread), but that's non-standard. |
|
yes, bg fsync sounds like a better idea.
so a new bg job opcodes? like a new BIO_FSYNC_AND_CLOSE, then we call it in openNewIncrAofForAppend, replace the bioCreateCloseJob |
|
Something irrelevant to the pr, but occasionally found when viewing the code, that bioCreateCloseJob here seems a misuse. bioCreateCloseJob is basically used in bg_unlink to forbid the blocking in unlink, here no file unlink, so maybe closing the file directly is just ok. |
|
I prefer to add |
|
Another finding is that If there's a background |
|
@uvletter i'm having hard time following your post. i.e. related to this comment: |
|
I try to explain uvletter's comment (hope i got it right), let's assume a modified version of this PR
and then here are some cases: when calling flushAppendOnlyFile, is there already bg fsync in progress (using everysec)
|
|
Sorry for my mess expression(or English)... I hope I make it clear this time.
Lines 1938 to 1941 in e6f6709 Lines 1981 to 1982 in e6f6709 But for the new INCR AOF implementation, the AOF file wouldn't be overwritten/rename directly, every AOF is a new file, so it seems
case 1: case 2: case 3:
Maybe I wanted to express, with case 1, bg fsync is a qualified but still not perfect solution. I have no good idea as well, so just throw some points/questions I found. |
|
I don't think the redundant One thing I think needs attention is to determine the order of execution of Since only AOF currently uses @oranagra WDYT? |
|
i hope i'm not missing anything too important (quite a lot of details and cases, and i didn't allocate enough time to dive deep into it).
please let me know if you think i'm missing and important detail. |
In rewriteAppendOnlyFileBackground, after flushAppendOnlyFile(1), and before openNewIncrAofForAppend, we should call redis_fsync to fsync the aof file. Because we may open a new INCR AOF in openNewIncrAofForAppend, in the case of using everysec policy, the old AOF file may not be flushed in time (or even at all). When using everysec, we don't want to pay the disk latency from the main thread, so we introduce a new BIO_FSYNC_AND_CLOSE bio opcode, it will close the fd after the fsync, both in background. We use bioCreateFsyncCloseJob to replace bioCreateCloseJob in openNewIncrAofForAppend, to make sure we will fsync the aof file before close it.
As the For @oranagra 's three points I generally agree, about point 2 I wanna add(It's just my inference, not sure it's right), that the flushAppendOnlyFile(1) here is more likely getting blocked than the flushAppendOnlyFile(0) in beforeSleep, flushAppendOnlyFile(0) only try to write if it's postponed more than two seconds due to the bg fsync, but flushAppendOnlyFile(1) always write without conditions. So if nearly before the flushAppendOnlyFile(1) a flushAppendOnlyFile(0) in beforeSleep get executed and submit a bg fsync, the flushAppendOnlyFile(1) here would likely get blocked(though the condition is still harsh). And I think BIO_AOF_FSYNC_AND_CLOSE is currently reasonable solution(except someone put forward a better one) |
it's a waste to open another thread for this.
oranagra
left a comment
There was a problem hiding this comment.
the amount of changes seem reasonable to me. i think we can accept that.
any other comments before i merge this?
i am good, i don't have it here |
In rewriteAppendOnlyFileBackground, after flushAppendOnlyFile(1), and before openNewIncrAofForAppend, we should call redis_fsync to fsync the aof file. Because we may open a new INCR AOF in openNewIncrAofForAppend, in the case of using everysec policy, the old AOF file may not be fsynced in time (or even at all). When using everysec, we don't want to pay the disk latency from the main thread, so we will do a background fsync. Adding a argument for bioCreateCloseJob, a `need_fsync` flag to indicate that a fsync is required before the file is closed. So we will fsync the old AOF file before we close it. A cleanup, we make union become a union, since the free_* args and the fd / fsync args are never used together. Co-authored-by: Oran Agra <[email protected]> (cherry picked from commit 03fff10)
In rewriteAppendOnlyFileBackground, after flushAppendOnlyFile(1), and before openNewIncrAofForAppend, we should call redis_fsync to fsync the aof file. Because we may open a new INCR AOF in openNewIncrAofForAppend, in the case of using everysec policy, the old AOF file may not be fsynced in time (or even at all). When using everysec, we don't want to pay the disk latency from the main thread, so we will do a background fsync. Adding a argument for bioCreateCloseJob, a `need_fsync` flag to indicate that a fsync is required before the file is closed. So we will fsync the old AOF file before we close it. A cleanup, we make union become a union, since the free_* args and the fd / fsync args are never used together. Co-authored-by: Oran Agra <[email protected]>
In rewriteAppendOnlyFileBackground, after flushAppendOnlyFile(1),
and before openNewIncrAofForAppend, we should call redis_fsync
to fsync the aof file.
Because we may open a new INCR AOF in openNewIncrAofForAppend,
in the case of using everysec policy, the old AOF file may not
be fsynced in time (or even at all).
When using everysec, we don't want to pay the disk latency from
the main thread, so we will do a background fsync.
Adding a argument for bioCreateCloseJob, a
need_fsyncflag toindicate that a fsync is required before the file is closed. So we will
fsync the old AOF file before we close it.
A cleanup, we make bio_job become a union, since the free_* args and
the fd / fsync args are never used together.