Skip to content

Commit 7f622b1

Browse files
fix(pipeline): preserve ADR across full re-index (DeusData#516)
manage_adr stores ADRs in project_summaries, but a full re-index (triggered by file changes or new files) deletes the DB in try_incremental_or_delete_db and rebuilds it from the graph buffer, which writes an empty project_summaries table. file_hashes were re-persisted after the rebuild but project_summaries were not, so the ADR was silently lost. Fix: capture the ADR before the DB is unlinked, stash it on the pipeline struct, and restore it after the rebuilt DB is reopened in dump_and_persist_hashes. The incremental path is unaffected (it never rewrites the DB). Verified: ADR now survives a full re-index. Signed-off-by: RithvikReddy0-0 <rithvikreddymukkara@gmail.com>
1 parent 170d5a8 commit 7f622b1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/pipeline/pipeline.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ struct cbm_pipeline {
9797
/* Committed graph size at dump time (-1 = dump did not run). #334 gate axis. */
9898
int committed_nodes;
9999
int committed_edges;
100+
101+
/* ADR (project_summaries) captured before a full-reindex DB delete, so it
102+
* can be restored after the rebuild. NULL when no ADR existed. Issue #516. */
103+
char *saved_adr;
100104
};
101105

102106
/* ── Global pkgmap (one active pipeline at a time) ─────────────── */
@@ -810,6 +814,22 @@ static int try_incremental_or_delete_db(cbm_pipeline_t *p, cbm_file_info_t *file
810814
cbm_store_close(check_store);
811815
}
812816
cbm_log_info("pipeline.route", "path", "reindex", "action", "deleting old db");
817+
/* Capture any ADR before deleting the DB so the full-reindex rebuild can
818+
* restore it (project_summaries is otherwise lost). Issue #516. */
819+
{
820+
cbm_store_t *adr_store = cbm_store_open_path(db_path);
821+
if (adr_store) {
822+
cbm_adr_t existing;
823+
if (cbm_store_adr_get(adr_store, p->project_name, &existing) == CBM_STORE_OK) {
824+
if (existing.content) {
825+
free(p->saved_adr);
826+
p->saved_adr = strdup(existing.content);
827+
}
828+
cbm_store_adr_free(&existing);
829+
}
830+
cbm_store_close(adr_store);
831+
}
832+
}
813833
cbm_unlink(db_path);
814834
char wal[PL_WAL_BUF];
815835
char shm[PL_WAL_BUF];
@@ -869,6 +889,11 @@ static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *fil
869889
cbm_store_t *hash_store = cbm_store_open_path(db_path);
870890
if (hash_store) {
871891
cbm_store_delete_file_hashes(hash_store, p->project_name);
892+
893+
/* Restore the ADR captured before the dump. Issue #516. */
894+
if (p->saved_adr) {
895+
cbm_store_adr_store(hash_store, p->project_name, p->saved_adr);
896+
}
872897
for (int i = 0; i < file_count; i++) {
873898
struct stat fst;
874899
if (stat(files[i].path, &fst) == 0) {
@@ -895,6 +920,8 @@ static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *fil
895920
cbm_store_close(hash_store);
896921
cbm_log_info("pass.timing", "pass", "persist_hashes", "files", itoa_buf(file_count));
897922
}
923+
free(p->saved_adr);
924+
p->saved_adr = NULL;
898925

899926
/* Export persistent artifact if enabled */
900927
if (p->persistence) {

0 commit comments

Comments
 (0)