fix(shadow): repair UTC sampling and persist v3 diagnostics

This commit is contained in:
zgw
2026-09-07 10:12:41 +08:00
parent 5ce6393337
commit 79e0db29f9
15 changed files with 678 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "PUSHD_ACTIVE=0"
if "%~1"=="" goto :usage
if "%~2"=="" goto :usage
@@ -41,15 +42,20 @@ if exist "%OUTPUT_DIR%" (
pushd "%REPO_ROOT%" >nul
if errorlevel 1 (call :fail "cannot enter REPO_ROOT" & exit /b 1)
set "PUSHD_ACTIVE=1"
(
echo export_started_utc=%DATE% %TIME%
echo export_started_local=%DATE% %TIME%
echo expected_branch=test/ft546wms-shadow-v3-20260903
git branch --show-current
git rev-parse HEAD
git status --porcelain
) > "%OUTPUT_DIR%\deployment.txt" 2>&1
if errorlevel 1 (call :fail "cannot create deployment evidence" & exit /b 1)
git branch --show-current >> "%OUTPUT_DIR%\deployment.txt" 2>&1
if errorlevel 1 (call :fail "cannot collect Git branch evidence" & exit /b 1)
git rev-parse HEAD >> "%OUTPUT_DIR%\deployment.txt" 2>&1
if errorlevel 1 (call :fail "cannot collect Git commit evidence" & exit /b 1)
git status --porcelain >> "%OUTPUT_DIR%\deployment.txt" 2>&1
if errorlevel 1 (call :fail "cannot collect Git deployment evidence" & exit /b 1)
popd >nul
set "PUSHD_ACTIVE=0"
jps -lv > "%OUTPUT_DIR%\runtime-processes.txt" 2>&1
if errorlevel 1 (call :fail "cannot collect JVM process evidence" & exit /b 1)
@@ -61,8 +67,14 @@ if errorlevel 1 (call :fail "cannot collect environment variable evidence" & exi
call :require_output "environment-variable-names.txt"
if errorlevel 1 exit /b 1
sqlcmd -S "%SQL_SERVER%" -d "%DATABASE%" -E -b -r1 -w 65535 -y 0 -Y 0 -v WarehouseId="%WAREHOUSE_ID%" StartUtc="%START_UTC%" OutputDir="%OUTPUT_DIR%" -i "%SQL_FILE%"
rem sqlcmd 13 does not reliably expand variables in :out paths. Use literal names under OUTPUT_DIR.
pushd "%OUTPUT_DIR%" >nul
if errorlevel 1 (call :fail "cannot enter OUTPUT_DIR" & exit /b 1)
set "PUSHD_ACTIVE=1"
sqlcmd -S "%SQL_SERVER%" -d "%DATABASE%" -E -b -r1 -w 65535 -y 0 -Y 0 -v WarehouseId="%WAREHOUSE_ID%" StartUtc="%START_UTC%" -i "%SQL_FILE%"
if errorlevel 1 (call :fail "read-only SQL export failed" & exit /b 1)
popd >nul
set "PUSHD_ACTIVE=0"
set "LOG_CANDIDATE="
for /f "delims=" %%L in ('dir /s /b "%LOG_DIR%\*.log" "%LOG_DIR%\*.txt" 2^>nul') do set "LOG_CANDIDATE=%%L"
@@ -82,6 +94,7 @@ call :require_output "shadow-warnings.txt"
if errorlevel 1 exit /b 1
echo EXPORT_OK output=%OUTPUT_DIR%
echo EXPORT_OK means files were collected, not approval to switch algorithms.
exit /b 0
:require_output
@@ -94,5 +107,6 @@ exit /b 2
:fail
echo EXPORT_FAILED %~1 1>&2
popd >nul 2>nul
if "%PUSHD_ACTIVE%"=="1" popd >nul 2>nul
set "PUSHD_ACTIVE=0"
exit /b 1

View File

@@ -1,6 +1,7 @@
:on error exit
:out "$(OutputDir)\sql-diagnostics.txt"
-- Run via shadow-v3-export.cmd: literal output names are relative to its OUTPUT_DIR.
:out "sql-diagnostics.txt"
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
@@ -73,7 +74,7 @@ WHERE request.database_id = DB_ID()
ORDER BY request.session_id;
GO
:out "$(OutputDir)\comparison-detail.txt"
:out "comparison-detail.txt"
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
@@ -108,19 +109,23 @@ WHERE warehouse_id = '$(WarehouseId)'
AND created_at >= CONVERT(datetime2(3), '$(StartUtc)', 127)
ORDER BY created_at, decision_id;
SELECT SUM(CASE WHEN decision_type = 'INBOUND' THEN 1 ELSE 0 END) AS inbound_plan_count,
SUM(CASE WHEN decision_type = 'INBOUND_COMPARE' THEN 1 ELSE 0 END) AS inbound_compare_count,
SUM(CASE WHEN decision_type = 'OUTBOUND' THEN 1 ELSE 0 END) AS outbound_plan_count,
SUM(CASE WHEN decision_type = 'OUTBOUND_COMPARE' THEN 1 ELSE 0 END) AS outbound_compare_count
SELECT COUNT_BIG(CASE WHEN decision_type = 'INBOUND' THEN 1 END) AS inbound_plan_count,
COUNT_BIG(CASE WHEN decision_type = 'INBOUND_COMPARE' THEN 1 END) AS inbound_compare_count,
COUNT_BIG(CASE WHEN decision_type = 'OUTBOUND' THEN 1 END) AS outbound_plan_count,
COUNT_BIG(CASE WHEN decision_type = 'OUTBOUND_COMPARE' THEN 1 END) AS outbound_compare_count,
CASE WHEN COUNT_BIG(CASE WHEN decision_type IN ('INBOUND_COMPARE', 'OUTBOUND_COMPARE') THEN 1 END) = 0
THEN 'NO_COMPARISONS' ELSE 'COMPARISONS_PRESENT_NOT_APPROVED' END AS sample_status
FROM alg.decision_log
WHERE warehouse_id = '$(WarehouseId)'
AND created_at >= CONVERT(datetime2(3), '$(StartUtc)', 127);
GO
:out "$(OutputDir)\runtime-metrics.txt"
:out "runtime-metrics.txt"
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT 'Counters are cumulative, not filtered by StartUtc; pre-V3.2 flushed_at may use JVM local time until next flush.' AS metric_scope;
SELECT warehouse_id, metric_name, bucket_upper_micros, metric_count,
metric_total_micros, metric_max_micros, flushed_at
FROM alg.shadow_runtime_metric
@@ -146,7 +151,7 @@ GROUP BY CASE
ORDER BY metric_group;
GO
:out "$(OutputDir)\inventory-parity.txt"
:out "inventory-parity.txt"
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;