-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix crash #1450
Merged
Fix crash #1450
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c415318
copying each header to the cache, we must leave space for the string
avbelov23 036420c
eliminated the progressive accumulation of duplicate lengths
avbelov23 f2130d5
change `new` according to `parent`
avbelov23 43d108e
change `parent` according to `nchild`
avbelov23 8531145
the function moves up the tree, and at each iteration, the node side
avbelov23 ae3e5f8
if there was a deletion, then we look for a new place to add a node,
avbelov23 9f0f753
adding an insert rebalance test
avbelov23 49598e2
adding a removal rebalance test
avbelov23 879b7c1
refactoring
avbelov23 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
This file contains 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 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 |
---|---|---|
|
@@ -2538,13 +2538,19 @@ tfw_hpack_rbtree_ins_rebalance(TfwHPackETbl *__restrict tbl, | |
HPACK_RB_SET_BLACK(uncle); | ||
HPACK_RB_SET_RED(gparent); | ||
parent = HPACK_NODE_COND(tbl, gparent->parent); | ||
new = gparent; | ||
} | ||
else { | ||
if (!HPACK_NODE_EMPTY(parent->right) | ||
&& new == HPACK_NODE(tbl, parent->right)) | ||
{ | ||
tfw_hpack_rbtree_left_rt(tbl, parent); | ||
parent = new; | ||
/* | ||
* Don't need `new = HPACK_NODE_COND(tbl, parent->left);`. | ||
* This is the last iteration, because the parent will turn | ||
* black below | ||
*/ | ||
} | ||
HPACK_RB_SET_BLACK(parent); | ||
HPACK_RB_SET_RED(gparent); | ||
|
@@ -2558,13 +2564,19 @@ tfw_hpack_rbtree_ins_rebalance(TfwHPackETbl *__restrict tbl, | |
HPACK_RB_SET_BLACK(uncle); | ||
HPACK_RB_SET_RED(gparent); | ||
parent = HPACK_NODE_COND(tbl, gparent->parent); | ||
new = gparent; | ||
} | ||
else { | ||
if (!HPACK_NODE_EMPTY(parent->left) | ||
&& new == HPACK_NODE(tbl, parent->left)) | ||
{ | ||
tfw_hpack_rbtree_right_rt(tbl, parent); | ||
parent = new; | ||
/* | ||
* Don't need `new = HPACK_NODE_COND(tbl, parent->right);`. | ||
* This is the last iteration, because the parent will turn | ||
* black below | ||
*/ | ||
} | ||
HPACK_RB_SET_BLACK(parent); | ||
HPACK_RB_SET_RED(gparent); | ||
|
@@ -2582,15 +2594,14 @@ tfw_hpack_rbtree_ins_rebalance(TfwHPackETbl *__restrict tbl, | |
static void | ||
tfw_hpack_rbtree_del_rebalance(TfwHPackETbl *__restrict tbl, | ||
TfwHPackNode *__restrict nchild, | ||
TfwHPackNode *__restrict parent, | ||
bool left) | ||
TfwHPackNode *__restrict parent) | ||
{ | ||
BUG_ON(!tbl->root); | ||
|
||
while (!nchild || (nchild != tbl->root && HPACK_RB_IS_BLACK(nchild))) { | ||
TfwHPackNode *brother, *l_neph, *r_neph; | ||
|
||
if (left) { | ||
if (nchild == HPACK_NODE_COND(tbl, parent->left)) { | ||
BUG_ON(HPACK_NODE_EMPTY(parent->right)); | ||
brother = HPACK_NODE(tbl, parent->right); | ||
if (HPACK_RB_IS_RED(brother)) { | ||
|
@@ -2616,6 +2627,7 @@ tfw_hpack_rbtree_del_rebalance(TfwHPackETbl *__restrict tbl, | |
{ | ||
HPACK_RB_SET_RED(brother); | ||
nchild = parent; | ||
parent = HPACK_NODE_COND(tbl, nchild->parent); | ||
} | ||
else | ||
{ | ||
|
@@ -2653,6 +2665,7 @@ tfw_hpack_rbtree_del_rebalance(TfwHPackETbl *__restrict tbl, | |
{ | ||
HPACK_RB_SET_RED(brother); | ||
nchild = parent; | ||
parent = HPACK_NODE_COND(tbl, nchild->parent); | ||
} | ||
else | ||
{ | ||
|
@@ -2692,12 +2705,11 @@ tfw_hpack_rbtree_min(TfwHPackETbl *__restrict tbl, | |
/* | ||
* Procedure for branches replacement in red-black tree. | ||
*/ | ||
static inline bool | ||
static inline void | ||
tfw_hpack_rbtree_replace(TfwHPackETbl *__restrict tbl, | ||
TfwHPackNode *__restrict old, | ||
TfwHPackNode *__restrict new) | ||
{ | ||
bool left = true; | ||
TfwHPackNode *parent = HPACK_NODE_COND(tbl, old->parent); | ||
|
||
BUG_ON(!old); | ||
|
@@ -2716,13 +2728,10 @@ tfw_hpack_rbtree_replace(TfwHPackETbl *__restrict tbl, | |
WARN_ON_ONCE(HPACK_NODE_EMPTY(parent->right) | ||
|| old != HPACK_NODE(tbl, parent->right)); | ||
parent->right = HPACK_NODE_COND_OFF(tbl, new); | ||
left = false; | ||
} | ||
|
||
if (new) | ||
new->parent = HPACK_NODE_COND_OFF(tbl, parent); | ||
|
||
return left; | ||
} | ||
|
||
/* | ||
|
@@ -2820,15 +2829,15 @@ tfw_hpack_rbtree_erase(TfwHPackETbl *__restrict tbl, | |
{ | ||
TfwHPackNode *nchild, *sv = node; | ||
TfwHPackNode *parent = HPACK_NODE_COND(tbl, node->parent); | ||
bool left_child = false, sv_black = HPACK_RB_IS_BLACK(sv); | ||
bool sv_black = HPACK_RB_IS_BLACK(sv); | ||
|
||
if (HPACK_NODE_EMPTY(node->left)) { | ||
nchild = HPACK_NODE_COND(tbl, node->right); | ||
left_child = tfw_hpack_rbtree_replace(tbl, node, nchild); | ||
tfw_hpack_rbtree_replace(tbl, node, nchild); | ||
} | ||
else if (HPACK_NODE_EMPTY(node->right)) { | ||
nchild = HPACK_NODE_COND(tbl, node->left); | ||
left_child = tfw_hpack_rbtree_replace(tbl, node, nchild); | ||
tfw_hpack_rbtree_replace(tbl, node, nchild); | ||
} | ||
else { | ||
TfwHPackNode *n_left; | ||
|
@@ -2842,7 +2851,7 @@ tfw_hpack_rbtree_erase(TfwHPackETbl *__restrict tbl, | |
TfwHPackNode *n_right; | ||
|
||
parent = HPACK_NODE(tbl, sv->parent); | ||
left_child = tfw_hpack_rbtree_replace(tbl, sv, nchild); | ||
tfw_hpack_rbtree_replace(tbl, sv, nchild); | ||
|
||
n_right = HPACK_NODE(tbl, node->right); | ||
n_right->parent = HPACK_NODE_OFF(tbl, sv); | ||
|
@@ -2867,7 +2876,7 @@ tfw_hpack_rbtree_erase(TfwHPackETbl *__restrict tbl, | |
* the last). | ||
*/ | ||
if (sv_black && tbl->root) | ||
tfw_hpack_rbtree_del_rebalance(tbl, nchild, parent, left_child); | ||
tfw_hpack_rbtree_del_rebalance(tbl, nchild, parent); | ||
} | ||
|
||
static inline void | ||
|
@@ -2945,18 +2954,33 @@ tfw_hpack_rbuf_calc(TfwHPackETbl *__restrict tbl, unsigned short new_size, | |
|
||
static inline void | ||
tfw_hpack_rbuf_commit(TfwHPackETbl *__restrict tbl, | ||
TfwStr *__restrict hdr, | ||
TfwHPackNode *__restrict del_list[], | ||
TfwHPackNodeIter *__restrict place, | ||
TfwHPackETblIter *__restrict iter) | ||
{ | ||
int i; | ||
bool was_del = false; | ||
const TfwHPackNode *node = NULL; | ||
TfwHPackETblRes res = HPACK_IDX_ST_NOT_FOUND; | ||
|
||
for (i = 0; i < HPACK_MAX_ENC_EVICTION; ++i) { | ||
TfwHPackNode *del_node = del_list[i]; | ||
|
||
if (!del_node) | ||
break; | ||
tfw_hpack_rbtree_erase(tbl, del_node); | ||
was_del = true; | ||
} | ||
|
||
/* | ||
* If there was a deletion, the place may turn out to be invalid as a result | ||
* of reducing the procedure for deleting a node with two children to | ||
* deleting a node with less than two children. | ||
*/ | ||
if (was_del) { | ||
res = tfw_hpack_rbtree_find(tbl, hdr, &node, place); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, there is a case, when |
||
WARN_ON_ONCE(res == HPACK_IDX_ST_FOUND); | ||
} | ||
|
||
tfw_hpack_rbtree_add(tbl, iter->last, place); | ||
|
@@ -3084,7 +3108,7 @@ tfw_hpack_add_node(TfwHPackETbl *__restrict tbl, TfwStr *__restrict hdr, | |
ptr = tfw_hpack_write(&s_nm, it.last->hdr); | ||
tfw_hpack_write(&s_val, ptr); | ||
|
||
tfw_hpack_rbuf_commit(tbl, del_list, place, &it); | ||
tfw_hpack_rbuf_commit(tbl, hdr, del_list, place, &it); | ||
|
||
WARN_ON_ONCE(tbl->rb_len > tbl->size); | ||
|
||
|
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.
Good catch!