Faster alias insert#1934
Conversation
Adds a test that trips an Alias insertion deadlock. Signed-off-by: Hank Donnay <hdonnay@redhat.com> Change-Id: I4f7f613f17e47c7cbcff82fbbb7674a06a6a6964
This fixes a transaction conflict where concurrent updaters could attempt to insert the same alias namespaces and cause the entire update to abort. Signed-off-by: Hank Donnay <hdonnay@redhat.com> Change-Id: I4f7f613f17e47c7cbcff82fbbb7674a06a6a6964
02f985f to
11ccd1a
Compare
Replace the per-vulnerability insertVulnerabilityAliases and insertSelfAlias batch queries — each of which did a hash-lookup subquery against the vuln table — with two single bulk INSERT statements that use unnest() + JOIN to link all vulnerabilities to their aliases and self-references in one pass. The flattened (hash_kind, hash, alias_space, alias_name) arrays accumulated during the vuln iteration are comparable in size to the arrays already built by the insertAliases pre-pass, so memory usage does not grow significantly relative to what was already held. For VEX with a 2-year lookback (~1.1M vulns), this reduces the alias-linking phase from timing out at 30 minutes to ~43 seconds. Signed-off-by: crozzy <joseph.crosland@gmail.com>
11ccd1a to
b7e27ee
Compare
|
Hey — I tested this on a GKE cluster (StackRox PR stackrox#21503, image tag The import completes fast (~10 min for all 13 bundles, rhel-vex in 2m17s, zero deadlocks) but the I think the issue is that The concurrent test doesn't hit this because it uses Here's the relevant sequence in // This consumes the iterator:
if err := s.insertAliases(ctx, vulnIter); err != nil {
return uuid.Nil, err
}
// ... later, this sees an exhausted iterator:
vulnIter(func(vuln *claircore.Vulnerability, iterErr error) bool {
// never called — iterator is already consumed
})Performance-wise the alias insertion approach looks great — just needs the iterator consumption fixed. |
|
Follow-up: I pushed a fix to jvdm/quay-claircore@ Redeployed on the same GKE cluster (1 replica,
The buggy run was fast (~10 min) only because it skipped all vuln inserts. With the fix, rhel-vex drops from ~34 min (baseline) to 12m42s and total import from ~55 min to ~34 min. |
|
Follow-up with 3 matcher replicas (same cluster, Per-bundle timing with the work distributed across 3 concurrent pods (each pod processes all bundles, but
Wall-clock from first bundle start to last pod "completed update": ~24 min (bottlenecked on lxwsx processing rhel-vex).
Zero deadlocks with 3 concurrent replicas — the outside-transaction alias namespace/alias insertion is working as intended. rhel-vex is slower per-pod (20m56s vs 12m42s) compared to the 1-replica run, but overall wall-clock improves because suse (12m23s) and rhel-vex (20m56s) run in parallel on different pods. |
|
In case you want to incorporate the fixes. |
No description provided.