This store's adjacency layer, or NULL for the SQL path; tried once per * store. The layer's version is the store generation plus the file state, and * both — like a miss's edge scan — are read inside one read transaction, so a * layer holds exactly the edges of the version it is keyed to. */
| 6711 | * both — like a miss's edge scan — are read inside one read transaction, so a |
| 6712 | * layer holds exactly the edges of the version it is keyed to. */ |
| 6713 | static cbm_graph_mem_t *store_graph_mem(cbm_store_t *s) { |
| 6714 | if (s->graph_mem_tried) { |
| 6715 | return s->graph_mem; |
| 6716 | } |
| 6717 | s->graph_mem_tried = true; |
| 6718 | if (!s->query_store || !s->db || !s->db_path) { |
| 6719 | return NULL; |
| 6720 | } |
| 6721 | bool own_txn = sqlite3_get_autocommit(s->db) != 0; |
| 6722 | if (own_txn && sqlite3_exec(s->db, "BEGIN DEFERRED;", NULL, NULL, NULL) != SQLITE_OK) { |
| 6723 | return NULL; |
| 6724 | } |
| 6725 | char generation[CBM_SZ_128]; |
| 6726 | char state[CBM_SZ_64]; |
| 6727 | char version[CBM_SZ_256]; |
| 6728 | /* The generation read is the transaction's first read: the SHARED lock |
| 6729 | * the file-state read relies on is held from here on. */ |
| 6730 | if (cbm_store_generation(s, generation, sizeof(generation)) == CBM_STORE_OK && |
| 6731 | strcmp(generation, "legacy") != 0 && store_rollback_file_state(s, state, sizeof(state))) { |
| 6732 | snprintf(version, sizeof(version), "%s/%s", generation, state); |
| 6733 | s->graph_mem = cbm_graph_mem_acquire(s->db, s->db_path, version); |
| 6734 | } |
| 6735 | if (own_txn) { |
| 6736 | (void)sqlite3_exec(s->db, "COMMIT;", NULL, NULL, NULL); |
| 6737 | } |
| 6738 | if (s->graph_mem && |
| 6739 | sqlite3_create_function(s->db, "cbm_adj_degree", ST_COL_2, |
| 6740 | SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY, s, |
| 6741 | sqlite_graph_mem_degree, NULL, NULL) != SQLITE_OK) { |
| 6742 | cbm_graph_mem_release(s->graph_mem); |
| 6743 | s->graph_mem = NULL; |
| 6744 | } |
| 6745 | if (s->graph_mem) { |
| 6746 | s->graph_mem_degree_mask = |
| 6747 | cbm_graph_mem_type_mask(s->graph_mem, st_degree_types, |
| 6748 | (int)(sizeof(st_degree_types) / sizeof(st_degree_types[0]))); |
| 6749 | } |
| 6750 | return s->graph_mem; |
| 6751 | } |
| 6752 | |
| 6753 | /* ── Search ─────────────────────────────────────────────────────── */ |
| 6754 |
no test coverage detected