@@ -698,12 +698,6 @@ static void finish_data_flow_props(char *props, size_t propsz, size_t pos,
698698 }
699699}
700700
701- typedef struct {
702- int64_t source_id ;
703- const char * props ;
704- const char * edge_type ;
705- } caller_edge_ref_t ;
706-
707701static bool http_call_edge_has_valid_route (const cbm_gbuf_edge_t * edge ) {
708702 char url_buf [CBM_SZ_512 ];
709703 const char * url = json_extract (edge -> properties_json , "url_path" , url_buf , sizeof (url_buf ));
@@ -768,84 +762,82 @@ static int try_create_data_flow(cbm_gbuf_t *gb, int64_t caller_id, int64_t handl
768762 return SKIP_ONE ;
769763}
770764
771- /* Collect extra handler IDs reachable via INFRA_MAPS chain from a route. */
772- static int collect_infra_handlers (cbm_gbuf_t * gb , int64_t route_id , int64_t * out , int max_out ) {
773- const cbm_gbuf_edge_t * * infra_edges = NULL ;
774- int infra_count = 0 ;
775- cbm_gbuf_find_edges_by_source_type (gb , route_id , "INFRA_MAPS" , & infra_edges , & infra_count );
765+ /* One route's DATA_FLOWS context: its direct handlers (handler -[HANDLES]-> route) and its
766+ * INFRA_MAPS hops (route -[INFRA_MAPS]-> endpoint, whose handlers are reached via the endpoint).
767+ * The edge arrays are the graph buffer's own index arrays. Inserting DATA_FLOWS never appends to
768+ * a HANDLES, INFRA_MAPS, HTTP_CALLS or ASYNC_CALLS array, so they stay valid while flows are added
769+ * (only edge deletion rebuilds the indexes). */
770+ typedef struct {
771+ cbm_gbuf_t * gb ;
772+ const cbm_gbuf_node_t * route ;
773+ const cbm_gbuf_edge_t * * handles ;
774+ int handles_count ;
775+ const cbm_gbuf_edge_t * * infra ;
776+ int infra_count ;
777+ int flows ;
778+ int skipped ;
779+ } route_flows_t ;
780+
781+ static void route_flow_add (route_flows_t * rf , const cbm_gbuf_edge_t * caller , int64_t handler_id ,
782+ const char * edge_type , bool via_infra ) {
783+ int rc = try_create_data_flow (rf -> gb , caller -> source_id , handler_id , rf -> route , edge_type ,
784+ caller -> properties_json , via_infra );
785+ if (rc > 0 ) {
786+ rf -> flows ++ ;
787+ } else if (rc < 0 ) {
788+ rf -> skipped ++ ;
789+ }
790+ }
776791
777- int n = 0 ;
778- for (int ie = 0 ; ie < infra_count ; ie ++ ) {
792+ /* DATA_FLOWS from one caller edge to every handler of the route, direct and via infra. */
793+ static void caller_data_flows (route_flows_t * rf , const cbm_gbuf_edge_t * caller ,
794+ const char * edge_type ) {
795+ for (int hi = 0 ; hi < rf -> handles_count ; hi ++ ) {
796+ route_flow_add (rf , caller , rf -> handles [hi ]-> source_id , edge_type , false);
797+ }
798+ for (int ie = 0 ; ie < rf -> infra_count ; ie ++ ) {
779799 const cbm_gbuf_edge_t * * ep_handles = NULL ;
780800 int ep_hcount = 0 ;
781- cbm_gbuf_find_edges_by_target_type (gb , infra_edges [ie ]-> target_id , "HANDLES" , & ep_handles ,
801+ cbm_gbuf_find_edges_by_target_type (rf -> gb , rf -> infra [ie ]-> target_id , "HANDLES" , & ep_handles ,
782802 & ep_hcount );
783- for (int eh = 0 ; eh < ep_hcount && n < max_out ; eh ++ ) {
784- out [ n ++ ] = ep_handles [eh ]-> source_id ;
803+ for (int eh = 0 ; eh < ep_hcount ; eh ++ ) {
804+ route_flow_add ( rf , caller , ep_handles [eh ]-> source_id , edge_type , true) ;
785805 }
786806 }
787- return n ;
788807}
789808
790- /* Collect caller edges (HTTP_CALLS + ASYNC_CALLS) targeting a route. */
791- static int collect_caller_edges (cbm_gbuf_t * gb , int64_t route_id , caller_edge_ref_t * out ,
792- int max_out ) {
793- int n = 0 ;
809+ /* Create DATA_FLOWS between EVERY caller (HTTP_CALLS + ASYNC_CALLS) and EVERY handler of one
810+ * route node.
811+ *
812+ * Callers were copied into a 64-slot buffer and infra handlers into a 32-slot one, each keeping the
813+ * first entries in edge-insertion order -- i.e. in parallel worker interleaving. Which DATA_FLOWS
814+ * existed therefore changed between two indexes of the same tree with the same binary
815+ * (thingsboard, 2026-10-17), and every caller past the 64th lost its flow outright. The flow set
816+ * is now the full caller x handler product. A (caller, handler) pair reached twice -- through two
817+ * routes, or directly and via infra -- keeps the order-free property winner of
818+ * cbm_gbuf_insert_edge. */
819+ static void create_route_data_flows (cbm_gbuf_t * gb , const cbm_gbuf_node_t * route , int * flows ,
820+ int * skipped ) {
821+ route_flows_t rf = {.gb = gb , .route = route };
822+ cbm_gbuf_find_edges_by_target_type (gb , route -> id , "HANDLES" , & rf .handles , & rf .handles_count );
823+ cbm_gbuf_find_edges_by_source_type (gb , route -> id , "INFRA_MAPS" , & rf .infra , & rf .infra_count );
824+
794825 const cbm_gbuf_edge_t * * http_edges = NULL ;
795826 int http_count = 0 ;
796- cbm_gbuf_find_edges_by_target_type (gb , route_id , "HTTP_CALLS" , & http_edges , & http_count );
797- for (int i = 0 ; i < http_count && n < max_out ; i ++ ) {
798- if (! http_call_edge_has_valid_route (http_edges [i ])) {
799- continue ;
827+ cbm_gbuf_find_edges_by_target_type (gb , route -> id , "HTTP_CALLS" , & http_edges , & http_count );
828+ for (int i = 0 ; i < http_count ; i ++ ) {
829+ if (http_call_edge_has_valid_route (http_edges [i ])) {
830+ caller_data_flows ( & rf , http_edges [ i ], "HTTP_CALLS" ) ;
800831 }
801- out [n ].source_id = http_edges [i ]-> source_id ;
802- out [n ].props = http_edges [i ]-> properties_json ;
803- out [n ].edge_type = "HTTP_CALLS" ;
804- n ++ ;
805832 }
806833 const cbm_gbuf_edge_t * * async_edges = NULL ;
807834 int async_count = 0 ;
808- cbm_gbuf_find_edges_by_target_type (gb , route_id , "ASYNC_CALLS" , & async_edges , & async_count );
809- for (int i = 0 ; i < async_count && n < max_out ; i ++ ) {
810- out [n ].source_id = async_edges [i ]-> source_id ;
811- out [n ].props = async_edges [i ]-> properties_json ;
812- out [n ].edge_type = "ASYNC_CALLS" ;
813- n ++ ;
814- }
815- return n ;
816- }
817-
818- /* Create DATA_FLOWS between callers and handlers for one route node. */
819- static void create_route_data_flows (cbm_gbuf_t * gb , const cbm_gbuf_node_t * route ,
820- const caller_edge_ref_t * callers , int n_callers , int * flows ,
821- int * skipped ) {
822- const cbm_gbuf_edge_t * * handles_edges = NULL ;
823- int handles_count = 0 ;
824- cbm_gbuf_find_edges_by_target_type (gb , route -> id , "HANDLES" , & handles_edges , & handles_count );
825-
826- int64_t extra_handlers [CBM_SZ_32 ];
827- int n_extra = collect_infra_handlers (gb , route -> id , extra_handlers , CBM_SZ_32 );
828-
829- for (int ci = 0 ; ci < n_callers ; ci ++ ) {
830- for (int hi = 0 ; hi < handles_count ; hi ++ ) {
831- int rc = try_create_data_flow (gb , callers [ci ].source_id , handles_edges [hi ]-> source_id ,
832- route , callers [ci ].edge_type , callers [ci ].props , false);
833- if (rc > 0 ) {
834- (* flows )++ ;
835- } else if (rc < 0 ) {
836- (* skipped )++ ;
837- }
838- }
839- for (int xi = 0 ; xi < n_extra ; xi ++ ) {
840- int rc = try_create_data_flow (gb , callers [ci ].source_id , extra_handlers [xi ], route ,
841- callers [ci ].edge_type , callers [ci ].props , true);
842- if (rc > 0 ) {
843- (* flows )++ ;
844- } else if (rc < 0 ) {
845- (* skipped )++ ;
846- }
847- }
835+ cbm_gbuf_find_edges_by_target_type (gb , route -> id , "ASYNC_CALLS" , & async_edges , & async_count );
836+ for (int i = 0 ; i < async_count ; i ++ ) {
837+ caller_data_flows (& rf , async_edges [i ], "ASYNC_CALLS" );
848838 }
839+ * flows += rf .flows ;
840+ * skipped += rf .skipped ;
849841}
850842
851843/* Find the enclosing proto service for a function by file + line range. */
@@ -952,9 +944,7 @@ static void create_data_flows(cbm_gbuf_t *gb) {
952944 int skipped = 0 ;
953945
954946 for (int ri = 0 ; ri < route_count ; ri ++ ) {
955- caller_edge_ref_t caller_edges [CBM_SZ_64 ];
956- int n_callers = collect_caller_edges (gb , routes [ri ]-> id , caller_edges , CBM_SZ_64 );
957- create_route_data_flows (gb , routes [ri ], caller_edges , n_callers , & flows , & skipped );
947+ create_route_data_flows (gb , routes [ri ], & flows , & skipped );
958948 }
959949
960950 if (flows > 0 || skipped > 0 ) {
0 commit comments