MINOR: pattern: move the update revision to the pat_ref, not the expression
It's not possible to uniquely update a single expression without updating
the pattern reference, I don't know why we've put the revision in the
expression back then, given that it in fact provides an update for a
full pattern. Let's move the revision into the reference's head instead.
diff --git a/include/haproxy/pattern-t.h b/include/haproxy/pattern-t.h
index d5c2adc..aa77c9a 100644
--- a/include/haproxy/pattern-t.h
+++ b/include/haproxy/pattern-t.h
@@ -106,6 +106,7 @@
struct list pat; /* The head of the list of struct pattern_expr. */
unsigned int flags; /* flags PAT_REF_*. */
int unique_id; /* Each pattern reference have unique id. */
+ unsigned long long revision; /* updated for each update */
__decl_thread(HA_SPINLOCK_T lock); /* Lock used to protect pat ref elements */
};
@@ -179,7 +180,6 @@
*/
struct pattern_expr {
struct list list; /* Used for chaining pattern_expr in pat_ref. */
- unsigned long long revision; /* updated for each update */
struct pat_ref *ref; /* The pattern reference if exists. */
struct pattern_head *pat_head; /* Point to the pattern_head that contain manipulation functions.
* Note that this link point on compatible head but not on the real
diff --git a/src/pattern.c b/src/pattern.c
index e028545..328c514 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -500,7 +500,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -523,7 +523,7 @@
}
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -540,7 +540,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -560,7 +560,7 @@
}
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -603,7 +603,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -620,7 +620,7 @@
}
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -679,7 +679,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -702,7 +702,7 @@
}
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -720,7 +720,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -743,7 +743,7 @@
}
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -765,7 +765,7 @@
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
- pat_lru_tree, expr, expr->revision);
+ pat_lru_tree, expr, expr->ref->revision);
if (lru && lru->domain) {
ret = lru->data;
return ret;
@@ -802,7 +802,7 @@
}
leave:
if (lru)
- lru64_commit(lru, ret, expr, expr->revision, NULL);
+ lru64_commit(lru, ret, expr, expr->ref->revision, NULL);
return ret;
}
@@ -1101,7 +1101,7 @@
free_pattern_tree(&expr->pattern_tree);
free_pattern_tree(&expr->pattern_tree_2);
LIST_INIT(&expr->patterns);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_prune_ptr(struct pattern_expr *expr)
@@ -1118,7 +1118,7 @@
free_pattern_tree(&expr->pattern_tree);
free_pattern_tree(&expr->pattern_tree_2);
LIST_INIT(&expr->patterns);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_prune_reg(struct pattern_expr *expr)
@@ -1135,7 +1135,7 @@
free_pattern_tree(&expr->pattern_tree);
free_pattern_tree(&expr->pattern_tree_2);
LIST_INIT(&expr->patterns);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
/*
@@ -1160,7 +1160,7 @@
/* chain pattern in the expression */
LIST_ADDQ(&expr->patterns, &patl->list);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1189,7 +1189,7 @@
/* chain pattern in the expression */
LIST_ADDQ(&expr->patterns, &patl->list);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1219,7 +1219,7 @@
/* chain pattern in the expression */
LIST_ADDQ(&expr->patterns, &patl->list);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1248,7 +1248,7 @@
/* chain pattern in the expression */
LIST_ADDQ(&expr->patterns, &patl->list);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1297,7 +1297,7 @@
/* Insert the entry. */
ebmb_insert_prefix(&expr->pattern_tree, &node->node, 4);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1325,7 +1325,7 @@
/* Insert the entry. */
ebmb_insert_prefix(&expr->pattern_tree_2, &node->node, 16);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1369,7 +1369,7 @@
/* index the new node */
ebst_insert(&expr->pattern_tree, &node->node);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1411,7 +1411,7 @@
/* index the new node */
ebmb_insert_prefix(&expr->pattern_tree, &node->node, len);
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
/* that's ok */
return 1;
@@ -1432,7 +1432,7 @@
free(pat->pat.data);
free(pat);
}
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_del_tree_ip(struct pattern_expr *expr, struct pat_ref_elt *ref)
@@ -1476,7 +1476,7 @@
free(elt->data);
free(elt);
}
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_del_list_ptr(struct pattern_expr *expr, struct pat_ref_elt *ref)
@@ -1495,7 +1495,7 @@
free(pat->pat.data);
free(pat);
}
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_del_tree_str(struct pattern_expr *expr, struct pat_ref_elt *ref)
@@ -1523,7 +1523,7 @@
free(elt->data);
free(elt);
}
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pat_del_list_reg(struct pattern_expr *expr, struct pat_ref_elt *ref)
@@ -1542,13 +1542,12 @@
free(pat->pat.data);
free(pat);
}
- expr->revision = rdtsc();
+ expr->ref->revision = rdtsc();
}
void pattern_init_expr(struct pattern_expr *expr)
{
LIST_INIT(&expr->patterns);
- expr->revision = 0;
expr->pattern_tree = EB_ROOT;
expr->pattern_tree_2 = EB_ROOT;
}
@@ -1853,6 +1852,7 @@
ref->flags = flags;
ref->unique_id = -1;
+ ref->revision = 0;
LIST_INIT(&ref->head);
LIST_INIT(&ref->pat);