Repository navigation
A parallel query waiting on itself is no longer counted as blocking (#6645) - #6663
Conversation
| SELECT | ||
| COALESCE(NULLIF( | ||
| (SELECT COUNT(*) FROM " + StoredEventCopies.BlockedProcessReports("server_id = $1 AND event_time >= $2 AND event_time < $3{SCOPE}") + @" AS ev), 0), | ||
| (SELECT COUNT(*) FROM " + StoredEventCopies.BlockedProcessReports("server_id = $1 AND event_time >= $2 AND event_time < $3 AND NOT COALESCE(blocked_spid = blocking_spid, FALSE){SCOPE}") + @" AS ev), 0), |
There was a problem hiding this comment.
The blocking anomaly's current window and its baseline are now in different units.
currentBlocking here (and in PgAnomalyDetector.BlockingWindowSql / BlockingSkippingSeparateCountSql) counts blocked-process report rows minus self-waits. The baseline it is divided by at Lite/Analysis/AnomalyDetector.cs:855 (currentBlockingPerHour / Math.Max(baselineBlockingRate, 1) >= 3) is MetricNames.Blocking, which is still a count of every report row:
- Lite:
Lite/Analysis/BaselineProvider.cs:716-717—EventBaselineSql("blocked_process_report", …, StoredEventCopies.BlockedProcessReports("server_id = $1 AND event_time >= $2 AND event_time < $3"), "COUNT(*)"), no spid predicate. - Darling:
PgBaselineProvider.cs:1424readsblocked_process_baseline, whose body iscount(*)overcollect.blocked_process_reportswith no row-level filter (TimescaleSupport.cs:797-806, and its own doc line says "both have NO row-level filter").
Failure scenario: a server where a parallel query's self-waits are most of the reports (the #6645 server) keeps a 30-day baseline mean built from all of them, while the current window now counts only the real ones. If 80% of reports were self-waits, the ratio is deflated ~5x and a genuine blocking storm no longer reaches the 3x spike bar — the detector goes quiet on exactly the servers this fix was written for, and stays quiet for as long as the self-waits keep being written (the baseline never washes out).
The same file already documents the one place it accepts a skew of this shape, deliberately and with its direction stated (:790-793, the separately-monitored-databases filter: "Only the current-window counts are filtered; the baseline stays server-wide, which can only make a master spike less likely, an accepted trade"). This one is not mentioned anywhere in the diff or the PR body, and unlike the master case it applies to every server. Either filter the baseline arms too, or state the trade and its direction here and in the body.
| /* #6645: a parallel query's threads write reports with blocked_spid = blocking_spid (different ecid). That is | ||
| the query waiting on itself, not blocking: it is no wait, no head blocker and no report. A report that | ||
| names no session (NULL spids) is kept: the comparison is not true for it. */ | ||
| WHERE NOT COALESCE(s.blocked_spid = s.blocking_spid, FALSE) |
There was a problem hiding this comment.
The two forms of the rule disagree on the report that names no session — and it is the SQL form's comment that is wrong about why.
The comment above says a report naming no session "is kept: the comparison is not true for it", and Collapse at :97 keeps it by an explicit && blockedSpid(row) != 0. That holds only when the store actually has NULL in both columns. The collector writes 0, never NULL: BlockedProcessReportCollector.cs:1115 / :1117 are int.TryParse(...) ? bs : 0 on a non-nullable int BlockedSpid, and the writer binds it straight through (:1050 .Value(row.BlockedSpid)).
So for a stored (0, 0) row: 0 = 0 is TRUE here and the row is dropped, while Collapse keeps it. That is the one thing the design says cannot happen — "The same rule is written twice … A test runs both over the same rows and checks they agree" (:42-44) — and the agreement tests do not cover it: PostgresSql_AgreesWithTheCSharpRule_OnTheSameReports, …OnSubMillisecondStartsAndNullTimes and …OnDmvSnapshotRows carry no row with both spids 0, and the new ParallelQuerySelfWaits_AreNotWaits pins only the C# side of the 0/0 case (BlockingWaitCountTests.cs:113). The hand-check in the test plan ("self row dropped, NULL/NULL row kept") tested NULL/NULL, which is the shape only the test fixtures produce (e.g. Lite.Tests/AnomalyTileWindowEndTests.cs:71, which omits the spid columns).
Consequence if such a row is ever written: the alert value counts it as one blocking event while the overview tile, the fleet tile, the BLOCKING_EVENTS fact and the daily summary do not. Either add the 0 exception to the SQL (NOT COALESCE(s.blocked_spid = s.blocking_spid AND s.blocked_spid <> 0, FALSE)) or drop it from Collapse and say the marker row is not a wait — but not one each way, and the comment should name 0, not NULL, as the shape the collector stores.
The alert's XE-or-DMV choice is still made on the self-waits, so the DMV arm it is supposed to fall back to is suppressedThis is the one finding I'd call blocking. It sits in a file the diff does not touch, which is why it is here rather than inline.
var hasXeReports = events.Any(r => r.Source == BlockedProcessAlertRow.XeReportSource); // :502
var waits = BlockingWaits.Collapse(FilterBlocking(events, excludedDatabases), …); // :504 — self-waits dropped here
return hasXeReports
? waits.Where(r => r.Source == BlockedProcessAlertRow.XeReportSource).ToList() // :516-518
: waits;A parallel query's self-wait reports are blocked-process reports, so they still set Failure scenario. A server whose blocked-process-report session captures a parallel query waiting on itself (the #6645 shape), and whose real lock blocking in the same hour is shorter than the blocked process threshold, so only Why I read this as a defect rather than the intended trade. Every SQL surface in this same diff falls back correctly, because there the filter is inside the counted subquery and
So after this PR the alert engine is the only surface that answers 0 where the overview card, the fleet tile and the anomaly count all answer with the DMV waits — the exact disagreement #5644 W1/W2 set out to make impossible ("BlockingWaitRows is the one place that set is built", The excluded-database case that No behaviour test covers it: Non-blocking notes1. The DMV-side half of this change cannot bite on anything the collector writes. 2. A comment the change falsified. 3. Nine copies of one predicate. 4. Dead guard. 5. For the checklist, not a finding: the blocking grids still list self-wait rows (no filter on the grid reads at |
There was a problem hiding this comment.
Verdict: CHANGES REQUESTED
Two inline comments and one top-level note carry the detail.
Claims
- VERIFIED — "
WaitsCteSqlfiltersNOT COALESCE(blocked_spid = blocking_spid, FALSE)in the_markedCTE (both dialects; also lowerswait_reports)" —BlockingWaits.cs:200-203;wait_reportsdescends from the filtered_marked(:190,:218-226) andPgFactCollector.Waits.cs:307readswaits_marked. - VERIFIED — "
Collapse<T>skips equal non-zero spids" —BlockingWaits.cs:97-100, pinned byBlockingWaitCountTests.ParallelQuerySelfWaits_AreNotWaits. - VERIFIED — "covers BLOCKING_EVENTS (Pg and DuckDB),
BlockingWaitRows, fleet tile, daily summary, health reader, Overview, LiteLocalDataService.Blocking.cs" — all elevenWaitsCteSqlcall sites go through that one CTE (PgFactCollector.Waits.cs:278,DuckDbFactCollector.Waits.cs:257,DarlingFleetReader.cs:373,DailySummarySql.cs:243,LocalDataService.DailySummary.cs:55,DarlingHealthReader.cs:93,ViewerDataService.Overview.cs:166,.Fleet.cs:92,.AzureMasterScope.cs:189,LocalDataService.Overview.cs:127,.Blocking.cs:619). - VERIFIED — "
Reconstructskips a row with equal spids before any node is added, so no chain and no cycle" —BlockingChainReconstructor.cs:215-218, above theallNodesadds;BlockingChainReconstructorTests.ParallelQuerySelfWaits_MakeNoChainAndNoCycle. - VERIFIED — "all four COUNT subqueries in Pg, and the two in Lite" —
PgAnomalyDetector.cs:315, 318, 331, 335;Lite/Analysis/AnomalyDetector.cs:805, 807. - VERIFIED — "
FILTER (WHERE …)on the SUM and the COUNT(DISTINCT), not a WHERE" —DarlingAlertReadAdapter.cs:592-593,LocalDataService.Blocking.cs:54-55; the snapshot stays present with 0 blocked, whichAlertEngine.cs:1739-1789reads as a fresh non-breaching sample, asBlockingWaitDuckDbTests.cs:154-157asserts. - VERIFIED — "
get_blockingkeeps the rows unchanged" — no MCP/grid blocking reader in the diff;LocalDataService.Blocking.cs:772/:896andDarlingAlertReadAdapter.cs:521carry no spid predicate. - VERIFIED — the CHANGELOG's "could draw a false cycle" — the old loop skipped only identical
SessionKeys (:233-234), so59:2 ← 59:1plus59:1 ← 59:2made two edges andHasCyclefired. - UNVERIFIED — "each failing on the old code and passing on the fix (source reverted, rebuilt)" — needs a build and two runs.
- UNVERIFIED — "Darling … Total 1580, Failed 0, Skipped 1" — needs a live store;
DARLING_TEST_PGis unset here, so everyPostgresSql_*test self-skips (BlockingWaitCountTests.cs:298, 328, 406, 482, 522). - UNVERIFIED — "Lite … Total 479, Failed 0" — needs the run.
- UNVERIFIED — "the Darling FILTER aggregate checked by hand (self row dropped, NULL/NULL row kept)" — a live read; it checked NULL/NULL, not the 0/0 the collector stores.
- UNVERIFIED —
PostgresSql_LeavesOutParallelQuerySelfWaits_AndCountsTheRealOne's "1 wait, 1 head blocker, wait_reports 5" — PostgreSQL-only, skipped. - REFUTED — "rows with no spid … stored with NULL spids and read as 0 … are still blocking events", and
BlockingWaits.cs:200-202's "A report that names no session (NULL spids) is kept" — the collector stores 0, never NULL (BlockedProcessReportCollector.cs:1115, 1117areint.TryParse(…) ? x : 0on non-nullableint, bound at:1050), and0 = 0is TRUE, so the SQL drops whatCollapsekeeps. NULL spids are the fixtures' shape (Lite.Tests/AnomalyTileWindowEndTests.cs:71). Inline onBlockingWaits.cs:203. - REFUTED — "a newest snapshot made only of self-wait rows" as reachable state —
DmvBlockingSnapshotCollector.cs:207is alreadyAND wt.blocking_session_id <> wt.session_id, so the DMV-side predicates bite only on rows already stored.
Riskiest lines
PerformanceMonitor.Common/BlockingWaits.cs:203— oneWHEREre-defines eleven read surfaces at once — covered byPerformanceMonitorLite.Tests.BlockingWaitDuckDbTests.ParallelQuerySelfWaits_AreNotBlocking(real DuckDB: factevent_count,distinct_head_blockers, overview count, current-wait snapshot).PerformanceMonitor.Common/BlockingWaits.cs:97— the!= 0exception the SQL half lacks; the C# side is covered byDarling.Tests.BlockingWaitCountTests.ParallelQuerySelfWaits_AreNotWaits, the C#-vs-SQL disagreement on a stored(0, 0)row is UNCOVERED (noPostgresSql_AgreesWithTheCSharpRule_*case carries one).Lite/Analysis/AnomalyDetector.cs:805(twinsPgAnomalyDetector.cs:315, 331) — filtered numerator over the unfilteredMetricNames.Blockingbaseline (BaselineProvider.cs:716-717,TimescaleSupport.cs:797-806) in the 3x ratio at:855— UNCOVERED (DarlingAnomalyBaselineTests.cs:91is a string pin, not coverage).
Traps near this diff
- "Two copies of one definition pinned EQUAL to each other fail only after BOTH have drifted (#3684). Alias, do not copy." — applies — nine spellings (
BlockingWaits.cs:203,LocalDataService.Blocking.cs:54-55,DarlingAlertReadAdapter.cs:592-593,AnomalyDetector.cs:805, 807,PgAnomalyDetector.cs:315, 318, 331, 335) plus a tenth, different one in C# atBlockingWaits.cs:97— and the two already disagree. - "A threshold that means different units at different surfaces … State the unit at every surface that shows the number (#3631)." — applies —
AnomalyDetector.cs:805/PgAnomalyDetector.cs:315count non-self reports against a baseline of all reports; the health band's tiers readwait_reports/report_count(PgFactCollector.Waits.cs:305-307,ViewerDataService.Overview.cs:180-181), measured in the unfiltered unit. - "A test that constructs a … fixture is testing a shape no live run produces (#3709). Fixtures should carry the population the engine actually emits, or say they do not." — applies —
BlockingWaitDuckDbTests.cs:146seeds a self-wait DMV snapshot thatDmvBlockingSnapshotCollector.cs:207forbids. - "Lite and Darling ship in parity … a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding (#3594)." — does not apply —
AnomalyDetector.cs:805↔PgAnomalyDetector.cs:315,LocalDataService.Blocking.cs:54↔DarlingAlertReadAdapter.cs:592, rest shared. - "Ruling (#5833) … never answer a trap with a test that reads source text." — does not apply — all four new tests are behaviour tests (
BlockingWaitDuckDbTests.cs:143,BlockingWaitCountTests.cs:97/:325,BlockingChainReconstructorTests.cs:62). - "An empty analysis window is 'unavailable', not an all-clear (#3553)." — does not apply — the
FILTERkeeps the row, so the read stays non-null with itscollection_time(LocalDataService.Blocking.cs:53-55) andAlertEngine.cs:1739-1748's freeze is never entered. - "A 'latest snapshot' read anchored on
= (SELECT MAX(collection_time) …)must project the anchor (#3637)." — does not apply — both reads still project and group bycollection_time(LocalDataService.Blocking.cs:53,DarlingAlertReadAdapter.cs:591). - "Every MCP filter is part of the query, not a post-filter on the page (#3641)." — does not apply — every store surface filters in the query; the one in-memory drop runs over the engine's whole 200-row fetch, and the MCP tools are untouched by design.
Divergence (blind read vs PR body)
Four, all the same direction — the body describes the rows dropped, not what the surfaces around them then do.
- The alert's XE-or-DMV choice still counts the dropped rows.
AlertContextBuilders.cs:502computeshasXeReportsbefore the collapse, so self-wait reports still elect the XE arm and:516-518then discards the merged DMV waits. An hour whose only blocked-process reports are self-waits, with real DMV-only blocking beside them, now counts 0 where every SQL surface in this diff falls back throughNULLIF(…, 0)(LocalDataService.Overview.cs:134-136,AnomalyDetector.cs:804-807,ViewerDataService.Overview.cs:173-181). That leaves the alert engine the only surface disagreeing with the overview card and the fleet tile — what #5644 W1/W2 exists to prevent (AlertEngine.cs:1419-1433). Suggested predicate in the top-level note; no test covers it. - The anomaly baseline goes unmentioned — filtered current window, unfiltered 30-day mean. Inline on
AnomalyDetector.cs:805. - The DMV premise — the
FILTER-over-WHERErationale describes a stateDmvBlockingSnapshotCollector.cs:207prevents. - NULL versus 0 — the body and two new comments name NULL as the stored shape; the collector writes 0, and the two forms of the rule part ways there.
Reviewer checklist
- Run the two live-PostgreSQL tests with
DARLING_TEST_PGset, and confirmCOUNT(DISTINCT blocked_spid) FILTER (…)plans and returns as expected against the realdmv_blocking_snapshots(the FILTER form is new here). - On a store that already holds self-wait rows, read the blocking anomaly fact before and after: how far does
current_blockingfall while the baseline mean stays put? That number decides whether the baseline arms need the filter or a documented trade. - In the real app, click a self-wait row in the blocking grid (Lite and Viewer):
BuildModelForSessionnow returns null, so the window says "No blocking was captured for this session in the selected time range" about a row on screen. - Check a live server's health band:
wait_reports/report_countnow exclude self-waits, so a band sized on the old report volume can change tier with no workload change.
…ng baseline the same way (#6645) The collector stores 0, never NULL, for a report that names no session. The C# rule keeps those rows, but the SQL predicate dropped them (0 = 0 is true). One BlockingWaits.NotSelfWaitSql now carries the rule for every SQL surface. The Lite blocking baseline counts the same reports as the current window.
|
Follow-up review (range That commit does exactly what round 1 asked for the spid-0-vs-NULL defect: Verified the collector claim at the source: New tests are solid, real behaviour tests, not spelling pins: The Darling anomaly-baseline parity gap round 1 flagged is not closed here — the stored continuous aggregate still counts self-waits until a migration rebuilds it — but this round is honest about that: the Lite twin ( The No new defects found in this round's commit. |
There was a problem hiding this comment.
Verdict: LGTM
Claims
- VERIFIED — "the SQL dropped (0, 0) rows (0 = 0 is true) that Collapse keeps" —
BlockingWaits.cs:97-100(C# keeps(0,0)) vs. the old SQLNOT COALESCE(blocked_spid = blocking_spid, FALSE)(0=0 true, dropped); fixed by the new predicate atBlockingWaits.cs:56. - VERIFIED — "BlockingWaits.NotSelfWaitSql is now
NOT COALESCE(blocked_spid = blocking_spid AND blocked_spid <> 0, FALSE), used by WaitsCteSql (all eleven surfaces), both FILTER current-wait reads, the Pg BlockingWindowSql / BlockingSkippingSeparateCountSql (now $@ const strings) and the Lite AnomalyDetector window" —BlockingWaits.cs:56,213,PgAnomalyDetector.cs:315,318,331,335,DarlingAlertReadAdapter.cs:592-593,Lite/Analysis/AnomalyDetector.cs:805,807. - VERIFIED — "New behaviour tests: (0,0) and an equal-spid wait added to PostgresSql_AgreesWithTheCSharpRule_OnTheSameReports (7 waits, PostgreSQL)… AReportThatNamedNoSession_StoredAsSpidZeroZero_IsStillAWait… ADmvSnapshotOfSpidZeroZero_IsStillBlockedInTheCurrentWaitRead" —
BlockingWaitCountTests.cs:307-310,321-322;Lite.Tests/BlockingWaitDuckDbTests.cs:162-182. - VERIFIED — "Lite BaselineProvider Blocking baseline is a query, so it now filters with the same predicate" —
Lite/Analysis/BaselineProvider.cs:716-719. - VERIFIED — "The Darling baseline is the stored continuous aggregate… changing it needs a store migration… this PR does not add [it]… a comment at PgAnomalyDetector.BlockingWindowSql says so" —
PgAnomalyDetector.cs:308-312(new comment), no migration file in this diff. - VERIFIED — "The Lite BlockingPerMinute baseline (a chart series, not used by the anomaly ratio) is left as it was" —
BaselineProvider.cs:773-783carries noNotSelfWaitSqlfilter. - VERIFIED — "spid 0, not NULL, is what the collector stores" —
BlockedProcessReportCollector.cs:1115,1117(int.TryParse(...) ? x : 0into non-nullableint); comments corrected atBlockingWaits.cs:102-106,210-213. - VERIFIED — "Not changed (outside this round's list): the alert's XE-or-DMV choice in AlertContextBuilders.cs:502…" —
AlertContextBuilders.csis absent from this commit's changed-file list. - UNVERIFIED — "source reverted, rebuilt, both suites run"; Darling/Lite test totals — need a build and a live run.
- UNVERIFIED — "the Darling FILTER aggregate checked by hand on the throwaway PostgreSQL" — a live read this tree can't reproduce.
Riskiest lines
PerformanceMonitor.Common/BlockingWaits.cs:56— the one predicate every SQL surface now aliases; a future edit to it moves every surface at once — covered byBlockingWaitCountTests.PostgresSql_AgreesWithTheCSharpRule_OnTheSameReports(live Postgres, 7 waits) andBlockingWaitDuckDbTests.AReportThatNamedNoSession_StoredAsSpidZeroZero_IsStillAWait.Darling/PerformanceMonitor.Darling.Analysis/PgAnomalyDetector.cs:331,335(BlockingSkippingSeparateCountSql) — same substitution asBlockingWindowSqlbut over the excluded-database arm — UNCOVERED (no live-PG test seeds a(0,0)row through this specific statement; it was already a string-pin-only surface before this round per the prior review).Lite/Services/LocalDataService.Blocking.cs:54-55—COUNT(DISTINCT blocked_spid) FILTER (WHERE NotSelfWaitSql)now can countblocked_spid = 0as a distinct "session" — covered byADmvSnapshotOfSpidZeroZero_IsStillBlockedInTheCurrentWaitRead, which assertsBlockedSessionCount == 1for a(0,0)snapshot, so the behaviour is intentional and pinned, not accidental.
Traps near this diff
- "Two copies of one definition pinned EQUAL to each other fail only after BOTH have drifted (#3684). Alias, do not copy." — does not apply (anymore) — this commit is the fix for exactly that trap: nine inline spellings collapse to one
BlockingWaits.NotSelfWaitSqlconstant (BlockingWaits.cs:56) referenced from both SKUs. - "A test that constructs a … fixture is testing a shape no live run produces (#3709). Fixtures should carry the population the engine actually emits, or say they do not." — applies, pre-existing and unchanged by this round —
BlockingWaitDuckDbTests.csseedsdmv: trueself-wait/(0,0)snapshot rows thatDmvBlockingSnapshotCollector.cs:207's own join predicate never produces; this round adds one more such fixture (ADmvSnapshotOfSpidZeroZero_IsStillBlockedInTheCurrentWaitRead) without a note saying so, same as the pre-existing(59,59)DMV fixture already flagged in round 1. - "Lite and Darling ship in parity … a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding (#3594)." — does not apply — every surface touched has its twin touched in the same commit (
AnomalyDetector.cs:805,807↔PgAnomalyDetector.cs:315,318,331,335;LocalDataService.Blocking.cs:54-55↔DarlingAlertReadAdapter.cs:592-593;BlockingWaitDuckDbTests.cs↔BlockingWaitCountTests.cs), and the one deliberately-NOT-ported piece (Darling's stored baseline aggregate) is called out in a comment rather than silently skipped. - "Ruling (#5833) … never answer a trap with a test that reads source text." — does not apply — all four new/changed assertions in this round are behaviour tests over real DuckDB/Postgres reads, not text pins.
Divergence (blind read vs PR body)
None — the PR body's "Bot review round 1" section describes exactly what this commit's diff does (the NotSelfWaitSql constant, the corrected 0-vs-NULL comments, the Lite baseline fix, the documented-not-fixed Darling baseline gap, and the explicit "not changed" list for AlertContextBuilders.cs/BlockingChainReconstructor), and nothing in the diff goes further than that account.
Reviewer checklist
- Run the two live-PostgreSQL tests with
DARLING_TEST_PGset (PostgresSql_AgreesWithTheCSharpRule_OnTheSameReports,PostgresSql_LeavesOutParallelQuerySelfWaits_AndCountsTheRealOne) and the Darling/Lite suites named in the PR body, since none of them ran in this read-only tree. - The
hasXeReports/AlertContextBuilders.cs:502defect and the Darling stored-baseline parity gap from round 1 remain open by the author's own account — track them for a follow-up commit or issue; they are unaffected (neither fixed nor worsened) by this round's diff.
Lite's blocking baseline arm now filters self-waits with BlockingWaits.NotSelfWaitSql (6d29768), so the expected event source at line 228 of DarlingEventBaselineCoveredDaysTests.cs follows it. Test expectation only; no behavior change.
|
Claude posting for Erik Darling. Lane report for the one-line pin behind the CI failure in
For the coordinator: check CI on |
Claude posting for Erik Darling.
Closes #6645.
Why
The threads of a parallel query write blocked-process reports with blocked_spid = blocking_spid (different ecid): the query waiting on itself. Nothing dropped them, so the wait counts, the head-blocker count, the chain and the anomaly count all included them.
What changes
A report whose blocked and blocking spid are the same is not a blocking wait. Rows with no spid (the collector stores 0, never NULL, for a report that names no session; NULL spids appear only in some test fixtures) are still blocking events, so the rule is "equal and not 0 (and not NULL)", not
IS DISTINCT FROMas the brief wrote (that would drop NULL/NULL marker rows; an existing Lite fixture with unset spids also caught it).PerformanceMonitor.Common/BlockingWaits.cs:WaitsCteSqlfiltersBlockingWaits.NotSelfWaitSql(NOT COALESCE(blocked_spid = blocking_spid AND blocked_spid <> 0, FALSE), one constant every SQL surface uses) in the_markedCTE (PostgreSQL and DuckDB; also lowerswait_reports);Collapse<T>skips equal non-zero spids. This covers BLOCKING_EVENTS (Pg and DuckDB),BlockingWaitRows, fleet tile, daily summary, health reader, Overview, LiteLocalDataService.Blocking.cs.PerformanceMonitor.Analysis/BlockingChainReconstructor.cs:Reconstructskips a row with equal spids before any node is added, so no chain and no cycle (Pg, Lite and the Viewer share the file).PgAnomalyDetector.BlockingWindowSql/BlockingSkippingSeparateCountSql, and the two inLite/Analysis/AnomalyDetector.cs.DarlingAlertReadAdapter.CurrentBlockingWaitSqland LiteGetCurrentBlockingWaitAsyncuseFILTER (WHERE ...)on the SUM and the COUNT(DISTINCT), not a WHERE, so a stored snapshot made only of self-wait rows still reads as a snapshot (its time and freshness) with nothing blocked, instead of as no snapshot. The DMV collector (DmvBlockingSnapshotCollector.cs:207) already refuses to write self-wait rows, so this only matters for rows stored before; the state is not reachable from new collection.Test plan
BlockingWaitCountTests.ParallelQuerySelfWaits_AreNotWaits(Collapse andBlockingWaitRows, plus a spid 0/0 report kept),BlockingWaitCountTests.PostgresSql_LeavesOutParallelQuerySelfWaits_AndCountsTheRealOne(live PG: 1 wait, 1 head blocker, wait_reports 5),BlockingWaitDuckDbTests.ParallelQuerySelfWaits_AreNotBlocking(fact event_count 1, distinct_head_blockers 1, overview 1, current-wait snapshot 0 sessions),BlockingChainReconstructorTests.ParallelQuerySelfWaits_MakeNoChainAndNoCycle(no chain,CycleDetectedfalse; real chain beside it unchanged).*BlockingWaitCountTests*,*Census*,*Ratchet*,*Anomaly*,*AlertEngineTests*,*DarlingSelfAlertTests*,*BlockingChain*,*DarlingFleetReader*,*Blocking*on a throwaway PostgreSQL: Total 1580, Failed 0, Skipped 1.*Census*,*Ratchet*,*Anomaly*,*Blocking*,*Overview*,*LiteAlert*,*McpBlocking*: Total 479, Failed 0.pre-push.sh(brief says CI decides). The PG anomaly SQL and the Darling current-wait SQL have no behavior test of their own (the anomaly SQL is only pinned as a string by an existing test); their Lite twins are exercised.Considered, not added
intra_query = trueonget_blockingrows (optional in the brief):get_blockingkeeps the rows unchanged; adding the flag needs a column through three readers, more than a few lines.CHANGELOG entry
SECTION: Fixed
ENTRY:
REF:
[A parallel query waiting on itself is no longer counted as blocking (#6645) #6663]: A parallel query waiting on itself is no longer counted as blocking (#6645) #6663
Bot review round 1 (changes requested)
(0, 0)rows (0 = 0is true) thatCollapsekeeps.BlockingWaits.NotSelfWaitSqlis nowNOT COALESCE(blocked_spid = blocking_spid AND blocked_spid <> 0, FALSE), used byWaitsCteSql(all eleven surfaces), bothFILTERcurrent-wait reads, the PgBlockingWindowSql/BlockingSkippingSeparateCountSql(now$@const strings) and the LiteAnomalyDetectorwindow. The NULL comments are corrected. New behaviour tests:(0, 0)and an equal-spid wait added toPostgresSql_AgreesWithTheCSharpRule_OnTheSameReports(7 waits, PostgreSQL),BlockingWaitDuckDbTests.AReportThatNamedNoSession_StoredAsSpidZeroZero_IsStillAWait(fact, overview and C# agree) andADmvSnapshotOfSpidZeroZero_IsStillBlockedInTheCurrentWaitRead(DuckDB).BaselineProviderBlockingbaseline is a query, so it now filters with the same predicate and the 3x ratio compares like with like. The Darling baseline is the stored continuous aggregatecollect.blocked_process_baseline(TimescaleSupport.CreateBlockedProcessBaselineSql,count(*) AS event_countovercollect.blocked_process_reports); changing it needs a store migration that recreates and backfills it, which this PR does not add. Until then the Darling baseline keeps self-waits (a server with many of them has a high baseline and real blocking is under-flagged); a comment atPgAnomalyDetector.BlockingWindowSqlsays so. The LiteBlockingPerMinutebaseline (a chart series, not used by the anomaly ratio) is left as it was.DmvBlockingSnapshotCollector.cs:207); the FILTER rationale and theLocalDataService.Blocking.cscomment now say it covers stored rows only.AlertContextBuilders.BlockingWaitRowsnow decideshasXeReportsfrom XE reports that are not self-waits (equal non-zero spids), so a window whose XE reports are all self-waits falls back to the DMV waits like the SQL surfaces. Test:BlockingWaitCountTests.XeReportsThatAreAllSelfWaits_FallBackToTheDmvWaits.BlockingChainReconstructorstill compares raw spids (a(0, 0)row makes no node, as before this PR).DARLING_TEST_PG.