Skip to content

Commit f04df4a

Browse files
committed
fix(pipeline): DATA_FLOWS link every caller and handler of a route
create_data_flows copied a route's callers (HTTP_CALLS + ASYNC_CALLS) into a 64-slot buffer and its INFRA_MAPS handlers into a 32-slot one, each keeping the first entries in edge-insertion order. In a parallel index that order is worker interleaving, so which DATA_FLOWS existed changed between two indexes of the same tree with the same binary (thingsboard, 2026-10-17), and every caller past the 64th lost its flow outright. The pass now walks the graph buffer's own edge arrays and creates the full caller x handler product per route. A (caller, handler) pair that is reached twice keeps cbm_gbuf_insert_edge's order-free property winner, so the flow set and its properties no longer depend on the order edges were inserted in. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 354ccec commit f04df4a

1 file changed

Lines changed: 62 additions & 73 deletions

File tree

‎src/pipeline/pass_route_nodes.c‎

Lines changed: 62 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,6 @@ static void finish_data_flow_props(char *props, size_t propsz, size_t pos,
677677
}
678678
}
679679

680-
typedef struct {
681-
int64_t source_id;
682-
const char *props;
683-
const char *edge_type;
684-
} caller_edge_ref_t;
685-
686680
static bool http_call_edge_has_valid_route(const cbm_gbuf_edge_t *edge) {
687681
char url_buf[CBM_SZ_512];
688682
const char *url = json_extract(edge->properties_json, "url_path", url_buf, sizeof(url_buf));
@@ -747,84 +741,81 @@ static int try_create_data_flow(cbm_gbuf_t *gb, int64_t caller_id, int64_t handl
747741
return SKIP_ONE;
748742
}
749743

750-
/* Collect extra handler IDs reachable via INFRA_MAPS chain from a route. */
751-
static int collect_infra_handlers(cbm_gbuf_t *gb, int64_t route_id, int64_t *out, int max_out) {
752-
const cbm_gbuf_edge_t **infra_edges = NULL;
753-
int infra_count = 0;
754-
cbm_gbuf_find_edges_by_source_type(gb, route_id, "INFRA_MAPS", &infra_edges, &infra_count);
744+
/* One route's DATA_FLOWS context: its direct handlers (handler -[HANDLES]-> route) and its
745+
* INFRA_MAPS hops (route -[INFRA_MAPS]-> endpoint, whose handlers are reached via the endpoint).
746+
* The edge arrays are the graph buffer's own index arrays. Inserting DATA_FLOWS never appends to a
747+
* HANDLES, INFRA_MAPS, HTTP_CALLS or ASYNC_CALLS array, so they stay valid while flows are added. */
748+
typedef struct {
749+
cbm_gbuf_t *gb;
750+
const cbm_gbuf_node_t *route;
751+
const cbm_gbuf_edge_t **handles;
752+
int handles_count;
753+
const cbm_gbuf_edge_t **infra;
754+
int infra_count;
755+
int flows;
756+
int skipped;
757+
} route_flows_t;
758+
759+
static void route_flow_add(route_flows_t *rf, const cbm_gbuf_edge_t *caller, int64_t handler_id,
760+
const char *edge_type, bool via_infra) {
761+
int rc = try_create_data_flow(rf->gb, caller->source_id, handler_id, rf->route, edge_type,
762+
caller->properties_json, via_infra);
763+
if (rc > 0) {
764+
rf->flows++;
765+
} else if (rc < 0) {
766+
rf->skipped++;
767+
}
768+
}
755769

756-
int n = 0;
757-
for (int ie = 0; ie < infra_count; ie++) {
770+
/* DATA_FLOWS from one caller edge to every handler of the route, direct and via infra. */
771+
static void caller_data_flows(route_flows_t *rf, const cbm_gbuf_edge_t *caller,
772+
const char *edge_type) {
773+
for (int hi = 0; hi < rf->handles_count; hi++) {
774+
route_flow_add(rf, caller, rf->handles[hi]->source_id, edge_type, false);
775+
}
776+
for (int ie = 0; ie < rf->infra_count; ie++) {
758777
const cbm_gbuf_edge_t **ep_handles = NULL;
759778
int ep_hcount = 0;
760-
cbm_gbuf_find_edges_by_target_type(gb, infra_edges[ie]->target_id, "HANDLES", &ep_handles,
761-
&ep_hcount);
762-
for (int eh = 0; eh < ep_hcount && n < max_out; eh++) {
763-
out[n++] = ep_handles[eh]->source_id;
779+
cbm_gbuf_find_edges_by_target_type(rf->gb, rf->infra[ie]->target_id, "HANDLES",
780+
&ep_handles, &ep_hcount);
781+
for (int eh = 0; eh < ep_hcount; eh++) {
782+
route_flow_add(rf, caller, ep_handles[eh]->source_id, edge_type, true);
764783
}
765784
}
766-
return n;
767785
}
768786

769-
/* Collect caller edges (HTTP_CALLS + ASYNC_CALLS) targeting a route. */
770-
static int collect_caller_edges(cbm_gbuf_t *gb, int64_t route_id, caller_edge_ref_t *out,
771-
int max_out) {
772-
int n = 0;
787+
/* Create DATA_FLOWS between EVERY caller (HTTP_CALLS + ASYNC_CALLS) and EVERY handler of one
788+
* route node.
789+
*
790+
* Callers were copied into a 64-slot buffer and infra handlers into a 32-slot one, each keeping the
791+
* first entries in edge-insertion order -- i.e. in parallel worker interleaving. Which DATA_FLOWS
792+
* existed therefore changed between two indexes of the same tree with the same binary
793+
* (thingsboard, 2026-10-17), and every caller past the 64th lost its flow outright. The flow set
794+
* is now the full caller x handler product. A (caller, handler) pair reached twice -- through two
795+
* routes, or directly and via infra -- keeps the order-free property winner of
796+
* cbm_gbuf_insert_edge. */
797+
static void create_route_data_flows(cbm_gbuf_t *gb, const cbm_gbuf_node_t *route, int *flows,
798+
int *skipped) {
799+
route_flows_t rf = {.gb = gb, .route = route};
800+
cbm_gbuf_find_edges_by_target_type(gb, route->id, "HANDLES", &rf.handles, &rf.handles_count);
801+
cbm_gbuf_find_edges_by_source_type(gb, route->id, "INFRA_MAPS", &rf.infra, &rf.infra_count);
802+
773803
const cbm_gbuf_edge_t **http_edges = NULL;
774804
int http_count = 0;
775-
cbm_gbuf_find_edges_by_target_type(gb, route_id, "HTTP_CALLS", &http_edges, &http_count);
776-
for (int i = 0; i < http_count && n < max_out; i++) {
777-
if (!http_call_edge_has_valid_route(http_edges[i])) {
778-
continue;
805+
cbm_gbuf_find_edges_by_target_type(gb, route->id, "HTTP_CALLS", &http_edges, &http_count);
806+
for (int i = 0; i < http_count; i++) {
807+
if (http_call_edge_has_valid_route(http_edges[i])) {
808+
caller_data_flows(&rf, http_edges[i], "HTTP_CALLS");
779809
}
780-
out[n].source_id = http_edges[i]->source_id;
781-
out[n].props = http_edges[i]->properties_json;
782-
out[n].edge_type = "HTTP_CALLS";
783-
n++;
784810
}
785811
const cbm_gbuf_edge_t **async_edges = NULL;
786812
int async_count = 0;
787-
cbm_gbuf_find_edges_by_target_type(gb, route_id, "ASYNC_CALLS", &async_edges, &async_count);
788-
for (int i = 0; i < async_count && n < max_out; i++) {
789-
out[n].source_id = async_edges[i]->source_id;
790-
out[n].props = async_edges[i]->properties_json;
791-
out[n].edge_type = "ASYNC_CALLS";
792-
n++;
793-
}
794-
return n;
795-
}
796-
797-
/* Create DATA_FLOWS between callers and handlers for one route node. */
798-
static void create_route_data_flows(cbm_gbuf_t *gb, const cbm_gbuf_node_t *route,
799-
const caller_edge_ref_t *callers, int n_callers, int *flows,
800-
int *skipped) {
801-
const cbm_gbuf_edge_t **handles_edges = NULL;
802-
int handles_count = 0;
803-
cbm_gbuf_find_edges_by_target_type(gb, route->id, "HANDLES", &handles_edges, &handles_count);
804-
805-
int64_t extra_handlers[CBM_SZ_32];
806-
int n_extra = collect_infra_handlers(gb, route->id, extra_handlers, CBM_SZ_32);
807-
808-
for (int ci = 0; ci < n_callers; ci++) {
809-
for (int hi = 0; hi < handles_count; hi++) {
810-
int rc = try_create_data_flow(gb, callers[ci].source_id, handles_edges[hi]->source_id,
811-
route, callers[ci].edge_type, callers[ci].props, false);
812-
if (rc > 0) {
813-
(*flows)++;
814-
} else if (rc < 0) {
815-
(*skipped)++;
816-
}
817-
}
818-
for (int xi = 0; xi < n_extra; xi++) {
819-
int rc = try_create_data_flow(gb, callers[ci].source_id, extra_handlers[xi], route,
820-
callers[ci].edge_type, callers[ci].props, true);
821-
if (rc > 0) {
822-
(*flows)++;
823-
} else if (rc < 0) {
824-
(*skipped)++;
825-
}
826-
}
813+
cbm_gbuf_find_edges_by_target_type(gb, route->id, "ASYNC_CALLS", &async_edges, &async_count);
814+
for (int i = 0; i < async_count; i++) {
815+
caller_data_flows(&rf, async_edges[i], "ASYNC_CALLS");
827816
}
817+
*flows += rf.flows;
818+
*skipped += rf.skipped;
828819
}
829820

830821
/* Find the enclosing proto service for a function by file + line range. */
@@ -931,9 +922,7 @@ static void create_data_flows(cbm_gbuf_t *gb) {
931922
int skipped = 0;
932923

933924
for (int ri = 0; ri < route_count; ri++) {
934-
caller_edge_ref_t caller_edges[CBM_SZ_64];
935-
int n_callers = collect_caller_edges(gb, routes[ri]->id, caller_edges, CBM_SZ_64);
936-
create_route_data_flows(gb, routes[ri], caller_edges, n_callers, &flows, &skipped);
925+
create_route_data_flows(gb, routes[ri], &flows, &skipped);
937926
}
938927

939928
if (flows > 0 || skipped > 0) {

0 commit comments

Comments
 (0)