-
Notifications
You must be signed in to change notification settings - Fork 386
box: don't delete inprogress files during normal GC #6555
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
Merged
locker
merged 1 commit into
tarantool:master
from
locker:gh-6554-gc-removes-inprogress-xlogs
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelogs/unreleased/gh-6554-fix-gc-removing-inprogress-xlogs.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## bugfix/core | ||
|
||
* Fixed a bug because of which the garbage collector could remove an xlog file | ||
that is still in use (gh-6554). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
-- test-run result file version 2 | ||
test_run = require('test_run').new() | ||
| --- | ||
| ... | ||
fiber = require('fiber') | ||
| --- | ||
| ... | ||
fio = require('fio') | ||
| --- | ||
| ... | ||
|
||
-- | ||
-- gh-6554: GC removes xlog.inprogress files. | ||
-- | ||
assert(box.cfg.wal_dir == box.cfg.memtx_dir) | ||
| --- | ||
| - true | ||
| ... | ||
|
||
function count_inprogress() \ | ||
return #fio.glob(box.cfg.wal_dir .. '/*.xlog.inprogress') \ | ||
end | ||
| --- | ||
| ... | ||
|
||
-- Run GC after each checkpoint. | ||
checkpoint_count = box.cfg.checkpoint_count | ||
| --- | ||
| ... | ||
box.cfg{checkpoint_count = 1} | ||
| --- | ||
| ... | ||
|
||
s = box.schema.create_space('test') | ||
| --- | ||
| ... | ||
_ = s:create_index('pk') | ||
| --- | ||
| ... | ||
box.snapshot() | ||
| --- | ||
| - ok | ||
| ... | ||
|
||
-- Suspend GC. | ||
files = box.backup.start() | ||
| --- | ||
| ... | ||
|
||
-- Create a checkpoint. | ||
_ = s:replace{1} | ||
| --- | ||
| ... | ||
box.snapshot() | ||
| --- | ||
| - ok | ||
| ... | ||
|
||
-- Block a writer on xlog.inprogress -> xlog rename. | ||
box.error.injection.set('ERRINJ_XLOG_RENAME_DELAY', true) | ||
| --- | ||
| - ok | ||
| ... | ||
c = fiber.channel() | ||
| --- | ||
| ... | ||
_ = fiber.create(function() local r = pcall(s.replace, s, {1}) c:put(r) end) | ||
| --- | ||
| ... | ||
_ = test_run:wait_cond(function() return count_inprogress() > 0 end) | ||
| --- | ||
| ... | ||
assert(count_inprogress() == 1) | ||
| --- | ||
| - true | ||
| ... | ||
|
||
-- Resume GC and wait for it to delete old files. | ||
box.backup.stop() | ||
| --- | ||
| ... | ||
for _, f in ipairs(files) do \ | ||
test_run:wait_cond(function() \ | ||
return not fio.path.exists(f) \ | ||
end) \ | ||
end | ||
| --- | ||
| ... | ||
|
||
-- The xlog.inprogress file shouldn't be deleted by GC. | ||
assert(count_inprogress() == 1) | ||
| --- | ||
| - true | ||
| ... | ||
|
||
-- Resume the blocked writer and check that it succeeds. | ||
box.error.injection.set('ERRINJ_XLOG_RENAME_DELAY', false) | ||
| --- | ||
| - ok | ||
| ... | ||
assert(c:get() == true) | ||
| --- | ||
| - true | ||
| ... | ||
|
||
-- The xlog.inprogress file was renamed. | ||
assert(count_inprogress() == 0) | ||
| --- | ||
| - true | ||
| ... | ||
|
||
-- Cleanup. | ||
s:drop() | ||
| --- | ||
| ... | ||
box.cfg{checkpoint_count = checkpoint_count} | ||
| --- | ||
| ... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AFAIU this was moved from
memtx_engine_end_recovery
in the commit you mentioned, becausememtx_engine_end_recovery
happens too early. With your patch applied theinprogress
files left by the main node won't be removed by the hot_standby node.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 mean
xdir_collect_inprogress
should be called somewhere around these lines: https://github.com/tarantool/tarantool/blob/master/src/box/box.cc#L3441-L3449So I propose to move it to
recovery_finalize
orwal_enable
. Both functions seem suitable to me.Or maybe extract
xdir_collect_inprogress
and call it explicitly.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.
BTW, the commit you mention (5aa243d) also added
engine_collect_garbage
togc_init
: 5aa243d#diff-0bcbae7cd0018b8d3a9816c5ed98dc346f51946ea7be03730fff798c603c2da2R116This seems useless, since
gc_init
is called even beforeengine_init
.I propose you remove that extraneous
engine_collect_garbage
call as well.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.
Good catch. Looks like it was added there to make GC tests pass. This is not needed now. Removed. Thanks!
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.
Right, we shouldn't run xdir_collect_garbage until the end of the hot standby mode, because we risk deleting files that are still in use by the master instance. Thanks for catching this!
I moved engine_end_recovery back to its old place - after hot standby completes - and introduced a new engine callback for memtx to build its secondary keys before hot standby - engine_begin_hot_standby. PTAL.