ZSET B+ Tree PR 1: extract skiplist into dedicated module#3579
ZSET B+ Tree PR 1: extract skiplist into dedicated module#3579rainsupreme wants to merge 1 commit into
Conversation
|
Preview of PR 2: rainsupreme#1 |
| iter->node = iter->node->backward; | ||
| if (iter->node == zslGetHeader(iter->zsl) || iter->node == NULL) iter->zsl = NULL; |
There was a problem hiding this comment.
This permanently "kills" the iterator no?. A subsequent zslNext call returns false. This means a bidirectional iterator cannot reverse direction at boundaries -- should this be a/ handled b/ documented?
There was a problem hiding this comment.
That's true, and a good point. I decided to make it not kill the iterator, as this will make it easier to support range operations later. I added comments and UTs for the iterator.
|
@jjuleslasarte thank you so much for the feedback! I've made some fixes and added UTs 😊 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## zset-btree #3579 +/- ##
==============================================
- Coverage 76.66% 76.45% -0.22%
==============================================
Files 159 161 +2
Lines 80114 80111 -3
==============================================
- Hits 61423 61248 -175
- Misses 18691 18863 +172
🚀 New features to boost your workflow:
|
|
B+ tree is a great idea, and the OrderedIndex abstraction makes sense. I think the main thing to tighten in this first PR is the API boundary and sequencing. Right now the new API surface is still explicitly skiplist-specific: I think the first step should be to move the skiplist implementation out of More specifically, I would prefer this PR to establish a clean skiplist module boundary first, and let the next PR introduce the backend-neutral OrderedIndex interface with only the operations required by existing ZSET code. Extra iterator or construction APIs can be added when a real OrderedIndex method or B+ tree integration needs them. |
|
Hm, I suppose that would make things cleaner while reviewing PRs until I delete skiplist. I had raised a PR like that a while back to separate skiplist stuff into a module and it was rejected, but that was before I had a feature branch to work in. I'm revising this PR now :) |
@PingXie I originally suggested to not do this. It's just moving code around for the sake of it until it's ultimately removed. I primarily didn't want to do it for 9.1 since that is unnecessary divergence between the versions. It's a little bit less relevant now that we did the code cut. I'm OK with an abstraction that covers both, but doing the work to make it opaque then delete it seems like unecessary ask. |
Move the skiplist implementation out of t_zset.c into its own compilation unit. This establishes a clean module boundary in preparation for the OrderedIndex abstraction. Changes: - Create src/skiplist.c with all skiplist data structure operations - Create src/skiplist.h with struct definitions, inline helpers, and function declarations - Remove struct definitions and skiplist function declarations from server.h (replaced with forward declarations) - Add #include "skiplist.h" to files that dereference skiplist structs - Update Makefile and CMakeLists.txt Functions that were static in t_zset.c and are now needed across translation units (zslCreateNode, zslInsertNode, zslDeleteNode, zslDelete, zslFreeNode, zslRandomLevel, zslUpdateScore, zslDeleteRangeByScore/Lex/Rank, zslGetRank) are made non-static. Range parsing helpers (zslParseRange, zslParseLexRangeItem, zsetParseLexRange, zsetFreeLexRange) remain in t_zset.c as they are command-layer logic. No behavioral changes. All existing tests pass. Signed-off-by: Rain Valentine <rsg000@gmail.com>
46f3b20 to
480863e
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
|
Well, I already reorganized it, and I did somewhat prefer to do it that way anyway, so in the end I have no complaints. I hope it makes the PRs more approachable and easier to review. @PingXie what do you think? And, this is in a feature branch, so no worries about getting stuck with partial work in unstable either. ;) |
PingXie
left a comment
There was a problem hiding this comment.
I wasn't aware of the timeline on when we will remove skiplist but this looks great. Thanks @rainsupreme
This is PR 1 of the series introducing an abstraction layer over the sorted set skiplist, enabling a future swap to a B+ tree for memory and performance gains. (Issue #3166) It targets the zset-btree feature branch.
Planned PRs:
Summary of changes:
Move the skiplist implementation out of
t_zset.cinto its own compilation unit (skiplist.c/skiplist.h), establishing a clean module boundary.New files:
src/skiplist.h— struct definitions (zskiplistNode,zskiplist), inline helpers (span/height accessors), and function declarationssrc/skiplist.c— all skiplist data structure operations extracted fromt_zset.cChanges to
server.h:zskiplistNodeandzskipliststruct definitions (moved toskiplist.h)ZSKIPLIST_MAXLEVEL,ZSKIPLIST_MAX_SEARCHdefines (moved toskiplist.h)skiplist.h)struct zskiplistfor thezsetstruct pointerChanges to
t_zset.c:skiplist.c)#include "skiplist.h"zslParseRange,zslParseLexRangeItem,zsetParseLexRange,zsetFreeLexRange) as command-layer logicOther files:
#include "skiplist.h"to files that dereference skiplist struct fields (defrag.c,geo.c,module.c,object.c,sort.c,aof.c,db.c,debug.c,rdb.c,server.c,lazyfree.c,valkey-check-rdb.c)MakefileandCMakeLists.txtto compileskiplist.cFunctions that were
staticint_zset.cand are now needed across translation units are made non-static. No behavioral changes.