mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 05:41:26 +02:00
BUG/MEDIUM: pattern: only visit equivalent nodes when skipping versions
Miroslav reported in issue #1802 a problem that affects atomic map/acl updates. During an update, incorrect versions are properly skipped, but in order to do so, we rely on ebmb_next() instead of ebmb_next_dup(). This means that if a new matching entry is in the process of being added and is the first one to succeed in the lookup, we'll skip it due to its version and use the next entry regardless of its value provided that it has the correct version. For IP addresses and string prefixes it's particularly visible because a lookup may match a new longer prefix that's not yet committed (e.g. 11.0.0.1 would match 11/8 when 10/7 was the only committed one), and skipping it could end up on 12/8 for example. As soon as a commit for the last version happens, the issue disappears. This problem only affects tree-based matches: the "str", "ip", and "beg" matches. Here we replace the ebmb_next() values with ebmb_next_dup() for exact string matches, and with ebmb_lookup_shorter() for longest matches, which will first visit duplicates, then look for shorter prefixes. This relies on previous commit: MINOR: ebtree: add ebmb_lookup_shorter() to pursue lookups Both need to be backported to 2.4, where the generation ID was added. Note that nowadays a simpler and more efficient approach might be employed, by having a single version in the current tree, and a list of trees per version. Manipulations would look up the tree version and work (and lock) only in the relevant trees, while normal operations would be performed on the current tree only. Committing would just be a matter of swapping tree roots and deleting old trees contents.
This commit is contained in:
parent
81f3b80e32
commit
51d38a26fe
@ -476,7 +476,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_next_dup(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
@ -671,7 +671,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_lookup_shorter(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
@ -982,7 +982,7 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_lookup_shorter(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
@ -1008,7 +1008,7 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_lookup_shorter(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
@ -1032,7 +1032,7 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_lookup_shorter(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
@ -1069,7 +1069,7 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int
|
||||
while (node) {
|
||||
elt = ebmb_entry(node, struct pattern_tree, node);
|
||||
if (elt->ref->gen_id != expr->ref->curr_gen) {
|
||||
node = ebmb_next(node);
|
||||
node = ebmb_lookup_shorter(node);
|
||||
continue;
|
||||
}
|
||||
if (fill) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user