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
memdb: add Flush and Discard API #15780
Conversation
Codecov Report
@@ Coverage Diff @@
## master #15780 +/- ##
===========================================
Coverage ? 80.8249%
===========================================
Files ? 505
Lines ? 136949
Branches ? 0
===========================================
Hits ? 110689
Misses ? 17802
Partials ? 8458 |
/run-all-tests |
PTAL @coocood |
kv/memdb/arena.go
Outdated
type arenaSnapshot struct { | ||
blockSize int | ||
blocks int | ||
availIdx int |
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.
Seems availIdx
is always equal to blocks-1
?
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.
https://github.com/bobotu/tidb/blob/14c3dd17e6bd0c5b578eeffe3e1b3c532224f58e/kv/memdb/arena.go#L106
If size
larger than maxBlockSize
(128M), avaliIdx
will less than len(blocks) - 1
.
But will such a large value appear in practice? If not, we can remove this part of the logic to simplify the code.
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.
We have a 6MB entry limit, so it does not happen, we can simplify the code.
LGTM |
PTAL @tiancaiamao |
/run-all-tests |
/run-all-tests |
1 similar comment
/run-all-tests |
/run-all-tests |
LGTM |
/merge |
/run-all-tests |
/run-cherry-picker |
1 similar comment
/run-cherry-picker |
cherry pick to release-4.0 in PR #16347 |
What problem does this PR solve?
Because #15405 is too large to submit as a single PR, I'm going to port the new revertable mem buffer part in this PR.
To maintain compatibility, I currently keep the
DB
type, but it's really just a wrapper for theSandbox
. After the other parts of the code are updated in subsequent PRs, theDB
will be deleted.What is changed and how it works?
The core of the new design is
Sandbox
. All modifications will be president into rootSandbox
. Sandbox can derive a new childSandbox
at any time.Each
Sandbox
is an independent skip-list, with all nodes stored in a sharedarena
.Flush
will use an optimized in-place algorithm to merge all nodes in the currentSandbox
to its parent's skip-list.Discard
will simply rollback thearena
's state to the snapshot takes at the creation of the derivedSandbox
.Check List
Tests