Fix swapdb bugs when multiple clients involved. #738
Merged
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.
This PR fixes couple of bugs related to swapdb. Following are the list of bugs:
Bug 1: Incorrect swapdb results in multiple clients (or cli) from different terminals
Terminal 1 (cli)
Terminal 2 (cli)
Expected result: Terminal 2 should correctly display the result for DB0 after the swapdb.
Bug 2: Swapdb result is not recovered after restart in flash mode
Expected result: Even after restarting the server, it should recover the swapdb results correctly.
Bug 3: Watched key/swapdb unit tests failure
As part of this PR, I have fixed a known bug as below (line 1731):
After this fix, following unit tests failed:
I have successfully verified all the above cases, and following are the test results after the fix:
Test bug 1 fix:
Terminal 1 (cli)
Terminal 2 (cli)
Test bug 2 fix:
Test bug 3 fix:
./runtest unit test passed
Additional information
The bug 2 was expected to be fixed in the previous PR #668. However, in the PR, the line https://github.com/Snapchat/KeyDB/blob/main/src/db.cpp#L1728 was still kept though it was expected to be removed. But, now as part of this PR we still don't need to remove that line but with a new solution of
storage_id
.Also, for the bug 3, when the same unit test was executed manually, server crashed with the following stack race:
@paulmchen @hengku @CrazyTennisFan