Fix /api/v2/contexts,nodes,nodes_instances,q before match (#15223)
* readers should be able to recursively acquire the lock, even when there is a writer waiting * in /api/v2/contexts/nodes/nodes_instances/q calls, when the context is collected, before should be matched against now, not the latest cached retention
Costa Tsaousis committed
Jun 20, 2023 at 21:55 UTC
a8da69781970b585e2b4af58f763dfb240445d92
1 file changed
+3
-3
database/contexts/api_v2.c
+3
-3
@@ -141,7 +141,7 @@ static FTS_MATCH rrdcontext_to_json_v2_full_text_search(struct rrdcontext_to_jso
141
dfe_start_read(rc->rrdinstances, ri) {
142
if(matched) break;
143
144
- if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, ri->first_time_s, ri->last_time_s, 0))
144
+ if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, ri->first_time_s, (ri->flags & RRD_FLAG_COLLECTED) ? ctl->now : ri->last_time_s, 0))
145
continue;
146
147
if(unlikely(full_text_search_string(&ctl->q.fts, q, ri->id)) ||
@@ -152,7 +152,7 @@ static FTS_MATCH rrdcontext_to_json_v2_full_text_search(struct rrdcontext_to_jso
152
153
RRDMETRIC *rm;
154
dfe_start_read(ri->rrdmetrics, rm) {
155
- if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, rm->first_time_s, rm->last_time_s, 0))
155
+ if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, rm->first_time_s, (rm->flags & RRD_FLAG_COLLECTED) ? ctl->now : rm->last_time_s, 0))
156
continue;
157
158
if(unlikely(full_text_search_string(&ctl->q.fts, q, rm->id)) ||
@@ -200,7 +200,7 @@ static ssize_t rrdcontext_to_json_v2_add_context(void *data, RRDCONTEXT_ACQUIRED
200
201
RRDCONTEXT *rc = rrdcontext_acquired_value(rca);
202
203
- if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, rc->first_time_s, rc->last_time_s, 0))
203
+ if(ctl->window.enabled && !query_matches_retention(ctl->window.after, ctl->window.before, rc->first_time_s, (rc->flags & RRD_FLAG_COLLECTED) ? ctl->now : rc->last_time_s, 0))
204
return 0; // continue to next context
205
206
FTS_MATCH match = ctl->q.host_match;