Skip to content
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

Cleanup aof temp files in sigShutdownHandler before exiting #1482

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

enjoy-binbin
Copy link
Member

@enjoy-binbin enjoy-binbin commented Dec 24, 2024

I think this code previously only meant to handle save in shutdown,
which means we may a do foreground save in shutdown. It also implicitly
handles the backgroud save, for example the child process will also
get the chance to call getpid() and clean up the temp RDB file.

However, we did not handle AOFRW, so we also leave temp files in here.
Noted that we can not use the same aofRemoveTempFile(getpid()) trick
for AOF. Since we rename the temp file (temp-rewriteaof-bg-pid.aof) to
the base aof file only in backgroundRewriteDoneHandler, and in this time,
there is no child process, so the cleanup job must be done by the parent
process.

The following sequences have been tested (not just signal handlers):

  1. Long foreground save + shutdown
  2. Long backgroud save + shutdown
  3. Long backgroud save + long lua script + shutdown
  4. Long bgrewriteaof + shutdown
  5. Long bgrewriteaof + long lua script + shutdown
  6. Short bgrewriteaof + long done handler + shutdown

All temporary files will be removed in the local tests.

I think this code previously only meant to handle save in shutdown,
which means we may a do foreground save in shutdown. It also implicitly
handles the backgroud save, for example the child process will also
get the chance to call getpid() and clean up the temp RDB file.

However, we did not handle AOFRW, so we also leave temp files in here.
Noted that we can not use the same aofRemoveTempFile(getpid()) trick
for AOF. Since we rename the temp file (temp-rewriteaof-bg-pid.aof) to
the base aof file only in backgroundRewriteDoneHandler, and in this time,
there is no child process, so the cleanup job must be done by the parent
child.

The following sequences have been tested (not just signal handlers):
1. Long foreground save + shutdown
2. Long backgroud save + shutdown
3. Long backgroud save + long lua script + shutdown
4. Long bgrewriteaof + shutdown
5. Long bgrewriteaof + long lua script + shutdown
6. Short bgrewriteaof + long done handler + shutdown

All temporary files will be removed in the local tests.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.84%. Comparing base (d00c856) to head (ab77b25).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1482      +/-   ##
============================================
- Coverage     70.86%   70.84%   -0.02%     
============================================
  Files           119      119              
  Lines         64852    64869      +17     
============================================
  Hits          45958    45958              
- Misses        18894    18911      +17     
Files with missing lines Coverage Δ
src/aof.c 80.31% <100.00%> (+0.20%) ⬆️
src/server.c 87.47% <100.00%> (+0.01%) ⬆️
src/server.h 100.00% <ø> (ø)

... and 13 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant