aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/ca-specific-schema.sql
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-11-03 16:30:22 +0100
committerThéophane Hufschmitt <theophane.hufschmitt@tweag.io>2022-04-21 10:06:39 +0200
commit92656da0b953b92228ef4a252d504c07710e4b47 (patch)
tree3e809ba1dcafd27bd8adbac5e7a2604b2091c3f5 /src/libstore/ca-specific-schema.sql
parent6ada4963111908211a4bbcc2ae65f4205cffaa18 (diff)
Fix the gc with indirect self-references via the realisations
If the derivation `foo` depends on `bar`, and they both have the same output path (because they are CA derivations), then this output path will depend both on the realisation of `foo` and of `bar`, which themselves depend on each other. This confuses SQLite which isn’t able to automatically solve this diamond dependency scheme. Help it by adding a trigger to delete all the references between the relevant realisations. Fix #5320
Diffstat (limited to 'src/libstore/ca-specific-schema.sql')
-rw-r--r--src/libstore/ca-specific-schema.sql13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstore/ca-specific-schema.sql b/src/libstore/ca-specific-schema.sql
index 64cc97fde..d2ea347fb 100644
--- a/src/libstore/ca-specific-schema.sql
+++ b/src/libstore/ca-specific-schema.sql
@@ -13,6 +13,19 @@ create table if not exists Realisations (
create index if not exists IndexRealisations on Realisations(drvPath, outputName);
+-- We can end-up in a weird edge-case where a path depends on itself because
+-- it’s an output of a CA derivation, that happens to be the same as one of its
+-- dependencies.
+-- In that case we have a dependency loop (path -> realisation1 -> realisation2
+-- -> path) that we need to break by removing the dependencies between the
+-- realisations
+create trigger if not exists DeleteSelfRefsViaRealisations before delete on ValidPaths
+ begin
+ delete from RealisationsRefs where realisationReference = (
+ select id from Realisations where outputPath = old.id
+ );
+ end;
+
create table if not exists RealisationsRefs (
referrer integer not null,
realisationReference integer,