T-215: M2.5 — Execute host/quant M2 preflight, observed split-boundary & latency checks, and desktop Claude Code EC-1 sign-off
This commit is contained in:
parent
51165adfeb
commit
87ae19e5f9
2 changed files with 922 additions and 195 deletions
|
|
@ -7,16 +7,23 @@
|
|||
* `bar_revisions` present, `suspended = false`, `writerTxn >= sequencerTxn`),
|
||||
* and exits 0 without querying table contents.
|
||||
* - Full verification mode (default): Verifies Milestone M2 Exit Criterion 3 fail-closed:
|
||||
* 1. Validates the Vault-fenced 1-year benchmark window (`>= 365` days after Vault
|
||||
* clamping with `vaultOperatorAuthorized: false`) and measures the 1-year
|
||||
* single-listing `1m` PGWire cold read (`< 1000 ms`) and warm reads (`< 250 ms`)
|
||||
* BEFORE any verifier query scans `bars_1m`.
|
||||
* 2. Verifies `wal_tables()` health, before-and-after WAL advancement against
|
||||
* `--load-receipt`, non-zero finite `0x10` binary-double commits across all three
|
||||
* shard prefixes (`bars_1m`, `bars_1m_qm`, `fx_1m`), exact expected key/close
|
||||
* probes, EOD/QM deduplication accounting, and optional idempotent resend
|
||||
* verification (`--resend-baseline`).
|
||||
* 3. Verifies observed split-boundary close agreement (`<= 0.5%`) between QuestDB
|
||||
* 1. Validates the load receipt (canonical ETL sources `eod_unadj`, `qm_raw`, `eod`;
|
||||
* shard SHA-256 hashes; independent settled before/after WAL windows per shard
|
||||
* prefix `bars_1m`, `bars_1m_qm`, `fx_1m`), optional resend baseline, and the
|
||||
* Vault-fenced 1-year benchmark window (`>= 365` days after Vault clamping with
|
||||
* `vaultOperatorAuthorized: false`) before any DB or store I/O.
|
||||
* 2. Polls `wal_tables()` (metadata only, zero bar-table scans) until `bars_1m`,
|
||||
* `fx_1m`, and `bar_revisions` are healthy, settled (`writerTxn >= sequencerTxn`),
|
||||
* and have applied all expected load-receipt transactions BEFORE starting the
|
||||
* timed benchmark.
|
||||
* 3. Measures the 1-year single-listing `1m` PGWire cold read (`< 1000 ms`) and warm
|
||||
* reads (`< 250 ms`) BEFORE any verifier query scans `bars_1m` or `fx_1m`.
|
||||
* 4. Verifies non-zero finite `0x10` binary-double commits across all three shard
|
||||
* prefixes (`bars_1m`, `bars_1m_qm`, `fx_1m`), exact shard-derived key/close
|
||||
* probes, EOD/QM deduplication accounting, stable retained-row content digests,
|
||||
* and optional idempotent resend verification (`--resend-baseline`, bound to shard
|
||||
* hashes and retained-row content digests).
|
||||
* 5. Verifies observed split-boundary close agreement (`<= 0.5%`) between QuestDB
|
||||
* `bars_1m` (`session = 'RTH'`, latest `ts` per `America/New_York` session
|
||||
* date) and retained raw `bars_1d/year=<YYYY>/part.parquet` across `NVDA.US`
|
||||
* (`2024-06-06..2024-06-12`, ex-date `2024-06-10`, `10:1`) and `NEXM.V`
|
||||
|
|
@ -60,6 +67,7 @@ const STRICT_SIGNED_INT_RE = /^-?(?:0|[1-9]\d*)$/;
|
|||
const STRICT_UTC_INSTANT_RE =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?Z$/;
|
||||
const DATE_ONLY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const SHA256_HEX_RE = /^[0-9a-f]{64}$/;
|
||||
const URL_CREDENTIAL_RE = /([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^:@/\s]+):([^@/\s]+)@/g;
|
||||
const POSTGRES_URL_RE = /postgres(?:ql)?:\/\/[^\s'"]+/gi;
|
||||
|
||||
|
|
@ -71,6 +79,10 @@ export const MAX_COLD_READ_MS = 1_000;
|
|||
export const MAX_WARM_READ_MS = 250;
|
||||
export const MIN_ONE_YEAR_WINDOW_MS = 365 * 24 * 60 * 60 * 1000;
|
||||
export const DEFAULT_PROBE_CLOSE_TOLERANCE = 1e-9;
|
||||
export const BARS_1M_SOURCE_EOD = 'eod_unadj' as const;
|
||||
export const BARS_1M_SOURCE_QM = 'qm_raw' as const;
|
||||
export const FX_1M_SOURCE_EOD = 'eod' as const;
|
||||
export type Bars1mSource = typeof BARS_1M_SOURCE_EOD | typeof BARS_1M_SOURCE_QM;
|
||||
export const REQUIRED_SHARD_PREFIXES = ['bars_1m', 'bars_1m_qm', 'fx_1m'] as const;
|
||||
export type RequiredShardPrefix = (typeof REQUIRED_SHARD_PREFIXES)[number];
|
||||
|
||||
|
|
@ -180,17 +192,11 @@ export interface WalTxnPair {
|
|||
readonly sequencerTxn: string;
|
||||
}
|
||||
|
||||
export interface LoadReceiptWalSnapshot {
|
||||
readonly bars_1m: WalTxnPair;
|
||||
readonly fx_1m: WalTxnPair;
|
||||
readonly bar_revisions?: WalTxnPair;
|
||||
}
|
||||
|
||||
export interface Bars1mProbeExpectation {
|
||||
readonly listingId: number;
|
||||
readonly tsUs: string;
|
||||
readonly expectedClose: number;
|
||||
readonly expectedSource: 'eod' | 'qm';
|
||||
readonly expectedSource: Bars1mSource;
|
||||
readonly expectedKnownAtUs?: string;
|
||||
readonly closeTolerance?: number;
|
||||
}
|
||||
|
|
@ -199,40 +205,49 @@ export interface Fx1mProbeExpectation {
|
|||
readonly pair: string;
|
||||
readonly tsUs: string;
|
||||
readonly expectedClose: number;
|
||||
readonly expectedSource: string;
|
||||
readonly expectedSource: typeof FX_1M_SOURCE_EOD;
|
||||
readonly closeTolerance?: number;
|
||||
}
|
||||
|
||||
export interface ShardPrefixLoadReceipt<TProbe> {
|
||||
readonly shardSha256: readonly string[];
|
||||
readonly beforeWal: WalTxnPair;
|
||||
readonly afterWal: WalTxnPair;
|
||||
readonly probes: readonly TProbe[];
|
||||
}
|
||||
|
||||
export interface LoadReceiptDedupExpectation {
|
||||
readonly eodSentRows: number;
|
||||
readonly qmSentRows: number;
|
||||
readonly overlapRows: number;
|
||||
readonly overlapWinnerSource: 'eod' | 'qm';
|
||||
readonly overlapWinnerSource: Bars1mSource;
|
||||
readonly overlapProbes?: readonly Bars1mProbeExpectation[];
|
||||
}
|
||||
|
||||
export interface M2LoadReceipt {
|
||||
readonly beforeWal: LoadReceiptWalSnapshot;
|
||||
readonly shards: {
|
||||
readonly bars_1m: {
|
||||
readonly probes: readonly Bars1mProbeExpectation[];
|
||||
};
|
||||
readonly bars_1m_qm: {
|
||||
readonly probes: readonly Bars1mProbeExpectation[];
|
||||
};
|
||||
readonly fx_1m: {
|
||||
readonly probes: readonly Fx1mProbeExpectation[];
|
||||
};
|
||||
readonly bars_1m: ShardPrefixLoadReceipt<Bars1mProbeExpectation>;
|
||||
readonly bars_1m_qm: ShardPrefixLoadReceipt<Bars1mProbeExpectation>;
|
||||
readonly fx_1m: ShardPrefixLoadReceipt<Fx1mProbeExpectation>;
|
||||
};
|
||||
readonly dedup: LoadReceiptDedupExpectation;
|
||||
}
|
||||
|
||||
export interface WalAdvancementEntry {
|
||||
export interface PrefixWalAdvancementEntry {
|
||||
readonly shardPrefix: RequiredShardPrefix;
|
||||
readonly table: 'bars_1m' | 'fx_1m';
|
||||
readonly beforeWriterTxn: string;
|
||||
readonly afterWriterTxn: string;
|
||||
readonly beforeSequencerTxn: string;
|
||||
readonly afterSequencerTxn: string;
|
||||
readonly liveWriterTxn: string;
|
||||
readonly liveSequencerTxn: string;
|
||||
}
|
||||
|
||||
export interface ShardHashesByPrefix {
|
||||
readonly bars_1m: readonly string[];
|
||||
readonly bars_1m_qm: readonly string[];
|
||||
readonly fx_1m: readonly string[];
|
||||
}
|
||||
|
||||
export interface ProbeCheckResult {
|
||||
|
|
@ -246,12 +261,13 @@ export interface ProbeCheckResult {
|
|||
}
|
||||
|
||||
export interface LoadReceiptVerificationResult {
|
||||
readonly walAdvancement: readonly WalAdvancementEntry[];
|
||||
readonly walAdvancement: readonly PrefixWalAdvancementEntry[];
|
||||
readonly shardHashes: ShardHashesByPrefix;
|
||||
readonly dedupAccounting: {
|
||||
readonly eodSentRows: number;
|
||||
readonly qmSentRows: number;
|
||||
readonly overlapRows: number;
|
||||
readonly overlapWinnerSource: 'eod' | 'qm';
|
||||
readonly overlapWinnerSource: Bars1mSource;
|
||||
readonly minExpectedEodRows: number;
|
||||
readonly minExpectedQmRows: number;
|
||||
readonly minExpectedTotalBars1mRows: number;
|
||||
|
|
@ -264,9 +280,12 @@ export interface LoadReceiptVerificationResult {
|
|||
|
||||
export interface ResendVerificationResult {
|
||||
readonly ok: true;
|
||||
readonly walAdvancement: readonly WalAdvancementEntry[];
|
||||
readonly walAdvancement: readonly PrefixWalAdvancementEntry[];
|
||||
readonly shardHashesMatched: true;
|
||||
readonly bars1mRowCountsUnchanged: true;
|
||||
readonly fx1mRowCountsUnchanged: true;
|
||||
readonly bars1mContentDigestMatched: true;
|
||||
readonly fx1mContentDigestMatched: true;
|
||||
}
|
||||
|
||||
export interface WalTableStatusRow {
|
||||
|
|
@ -370,6 +389,8 @@ export interface VerifyM2QuantReport {
|
|||
readonly walTables: readonly WalTableStatusRow[];
|
||||
readonly bars1mSummary: readonly Bars1mSourceSummaryRow[];
|
||||
readonly fx1mSummary: readonly Fx1mPairSourceSummaryRow[];
|
||||
readonly bars1mContentDigest: string;
|
||||
readonly fx1mContentDigest: string;
|
||||
readonly loadVerification: LoadReceiptVerificationResult;
|
||||
readonly resendVerification?: ResendVerificationResult;
|
||||
readonly splitChecks: readonly SplitBoundaryCheckResult[];
|
||||
|
|
@ -404,8 +425,9 @@ export const VERIFY_M2_QUANT_USAGE = [
|
|||
' --bench-from <iso-or-date> Benchmark window start (must be < --vault-cutoff-ts)',
|
||||
' --bench-to <iso-or-date> Benchmark window end (effective fenced span must be >= 365 days)',
|
||||
' --bench-as-of <iso-or-date> Benchmark point-in-time as-of bound',
|
||||
' --load-receipt <path> JSON load receipt with beforeWal, per-prefix (bars_1m, bars_1m_qm,',
|
||||
' fx_1m) expected keys/closes, and EOD/QM dedup expectations',
|
||||
' --load-receipt <path> JSON load receipt with per-prefix (bars_1m, bars_1m_qm, fx_1m)',
|
||||
' shard SHA-256 hashes, settled beforeWal/afterWal, expected keys/closes,',
|
||||
' and EOD/QM dedup expectations',
|
||||
'',
|
||||
'Optional options:',
|
||||
' --questdb-database <name> QuestDB PGWire database name (host/port mode)',
|
||||
|
|
@ -908,12 +930,18 @@ function describeSafeQuestDbTarget(config: QuestDbPgExecutorConfig): string {
|
|||
return `${config.host ?? 'localhost'}:${config.port ?? 8812}`;
|
||||
}
|
||||
|
||||
interface RequiredMinWalByTable {
|
||||
readonly bars_1m: WalTxnPair;
|
||||
readonly fx_1m: WalTxnPair;
|
||||
}
|
||||
|
||||
async function waitForHealthyWalTables(
|
||||
executor: QuestDbPgQueryExecutor,
|
||||
timeoutMs: number,
|
||||
pollIntervalMs: number,
|
||||
nowMs: () => number,
|
||||
sleepMs: (ms: number) => Promise<void>
|
||||
sleepMs: (ms: number) => Promise<void>,
|
||||
requiredMinWal?: RequiredMinWalByTable
|
||||
): Promise<readonly WalTableStatusRow[]> {
|
||||
const deadline = nowMs() + timeoutMs;
|
||||
const sql =
|
||||
|
|
@ -959,9 +987,30 @@ async function waitForHealthyWalTables(
|
|||
);
|
||||
}
|
||||
|
||||
if (requiredMinWal !== undefined) {
|
||||
for (const table of ['bars_1m', 'fx_1m'] as const) {
|
||||
const status = byName.get(table)!;
|
||||
const minReqSeq = BigInt(requiredMinWal[table].sequencerTxn);
|
||||
if (status.sequencerTxn < minReqSeq) {
|
||||
throw new VerifyM2QuantError(
|
||||
`QuestDB WAL for '${table}' sequencerTxn=${status.sequencerTxn.toString()} is behind expected load receipt sequencerTxn=${minReqSeq.toString()}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unsettled = M2_INTRADAY_TABLE_NAMES.filter(name => {
|
||||
const status = byName.get(name)!;
|
||||
return status.writerTxn < status.sequencerTxn;
|
||||
if (status.writerTxn < status.sequencerTxn) {
|
||||
return true;
|
||||
}
|
||||
if (requiredMinWal !== undefined && (name === 'bars_1m' || name === 'fx_1m')) {
|
||||
const minReqWriter = BigInt(requiredMinWal[name].writerTxn);
|
||||
if (status.writerTxn < minReqWriter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (unsettled.length === 0) {
|
||||
|
|
@ -980,7 +1029,11 @@ async function waitForHealthyWalTables(
|
|||
const details = unsettled
|
||||
.map(name => {
|
||||
const status = byName.get(name)!;
|
||||
return `${name}(writerTxn=${status.writerTxn.toString()}<sequencerTxn=${status.sequencerTxn.toString()})`;
|
||||
const minReq =
|
||||
requiredMinWal !== undefined && (name === 'bars_1m' || name === 'fx_1m')
|
||||
? `,requiredWriterTxn=${requiredMinWal[name].writerTxn}`
|
||||
: '';
|
||||
return `${name}(writerTxn=${status.writerTxn.toString()}<sequencerTxn=${status.sequencerTxn.toString()}${minReq})`;
|
||||
})
|
||||
.join(', ');
|
||||
throw new VerifyM2QuantError(
|
||||
|
|
@ -1253,6 +1306,23 @@ function formatUtcIsoMicros(tsUs: bigint): string {
|
|||
return `${isoMs.slice(0, -1)}${String(subMsMicros).padStart(3, '0')}Z`;
|
||||
}
|
||||
|
||||
function parseSha256Hex(value: unknown, field: string): string {
|
||||
const raw = parseRequiredStringCell(value, field).toLowerCase();
|
||||
if (!SHA256_HEX_RE.test(raw)) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Invalid SHA-256 hex digest for '${field}': expected 64 hex characters.`
|
||||
);
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
function parseSha256List(value: unknown, field: string): readonly string[] {
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
throw new VerifyM2QuantError(`Expected non-empty SHA-256 array for '${field}'.`);
|
||||
}
|
||||
return value.map((entry, idx) => parseSha256Hex(entry, `${field}[${idx}]`));
|
||||
}
|
||||
|
||||
function parseWalTxnPair(value: unknown, field: string): WalTxnPair {
|
||||
if (!isPlainObject(value)) {
|
||||
throw new VerifyM2QuantError(`Expected object for '${field}'.`);
|
||||
|
|
@ -1265,10 +1335,18 @@ function parseWalTxnPair(value: unknown, field: string): WalTxnPair {
|
|||
};
|
||||
}
|
||||
|
||||
function assertSettledWalPair(pair: WalTxnPair, field: string): void {
|
||||
if (BigInt(pair.writerTxn) < BigInt(pair.sequencerTxn)) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Unsettled WAL snapshot for '${field}' (writerTxn=${pair.writerTxn} < sequencerTxn=${pair.sequencerTxn}).`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function parseBars1mProbe(
|
||||
value: unknown,
|
||||
field: string,
|
||||
requiredSource: 'eod' | 'qm'
|
||||
requiredSource: Bars1mSource
|
||||
): Bars1mProbeExpectation {
|
||||
if (!isPlainObject(value)) {
|
||||
throw new VerifyM2QuantError(`Expected probe object for '${field}'.`);
|
||||
|
|
@ -1320,6 +1398,11 @@ function parseFx1mProbe(value: unknown, field: string): Fx1mProbeExpectation {
|
|||
throw new VerifyM2QuantError(`${field}.expectedClose must be positive.`);
|
||||
}
|
||||
const expectedSource = parseRequiredStringCell(value.expectedSource, `${field}.expectedSource`);
|
||||
if (expectedSource !== FX_1M_SOURCE_EOD) {
|
||||
throw new VerifyM2QuantError(
|
||||
`${field}.expectedSource must be '${FX_1M_SOURCE_EOD}' (received '${expectedSource}').`
|
||||
);
|
||||
}
|
||||
let closeTolerance: number | undefined;
|
||||
if (value.closeTolerance !== undefined) {
|
||||
closeTolerance = parseFiniteNumberCell(value.closeTolerance, `${field}.closeTolerance`);
|
||||
|
|
@ -1336,6 +1419,37 @@ function parseFx1mProbe(value: unknown, field: string): Fx1mProbeExpectation {
|
|||
};
|
||||
}
|
||||
|
||||
function parseShardPrefixEntry<TProbe>(
|
||||
shardsObj: Record<string, unknown>,
|
||||
prefix: RequiredShardPrefix,
|
||||
parseProbe: (entry: unknown, field: string) => TProbe
|
||||
): ShardPrefixLoadReceipt<TProbe> {
|
||||
const entry = shardsObj[prefix];
|
||||
if (!isPlainObject(entry)) {
|
||||
throw new VerifyM2QuantError(`Load receipt missing required object "shards.${prefix}".`);
|
||||
}
|
||||
const shardSha256 = parseSha256List(entry.shardSha256, `shards.${prefix}.shardSha256`);
|
||||
const beforeWal = parseWalTxnPair(entry.beforeWal, `shards.${prefix}.beforeWal`);
|
||||
const afterWal = parseWalTxnPair(entry.afterWal, `shards.${prefix}.afterWal`);
|
||||
assertSettledWalPair(beforeWal, `shards.${prefix}.beforeWal`);
|
||||
assertSettledWalPair(afterWal, `shards.${prefix}.afterWal`);
|
||||
if (
|
||||
BigInt(afterWal.writerTxn) <= BigInt(beforeWal.writerTxn) ||
|
||||
BigInt(afterWal.sequencerTxn) <= BigInt(beforeWal.sequencerTxn)
|
||||
) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Load receipt WAL for shard prefix '${prefix}' did not advance (before writerTxn=${beforeWal.writerTxn}/sequencerTxn=${beforeWal.sequencerTxn}, after writerTxn=${afterWal.writerTxn}/sequencerTxn=${afterWal.sequencerTxn}).`
|
||||
);
|
||||
}
|
||||
if (!Array.isArray(entry.probes) || entry.probes.length === 0) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Load receipt shards.${prefix}.probes must be a non-empty array.`
|
||||
);
|
||||
}
|
||||
const probes = entry.probes.map((p, idx) => parseProbe(p, `shards.${prefix}.probes[${idx}]`));
|
||||
return { shardSha256, beforeWal, afterWal, probes };
|
||||
}
|
||||
|
||||
export function parseLoadReceiptJson(rawJson: string): M2LoadReceipt {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
|
|
@ -1348,44 +1462,36 @@ export function parseLoadReceiptJson(rawJson: string): M2LoadReceipt {
|
|||
throw new VerifyM2QuantError('Load receipt JSON must be a top-level object.');
|
||||
}
|
||||
|
||||
if (!isPlainObject(parsed.beforeWal)) {
|
||||
throw new VerifyM2QuantError('Load receipt missing required object "beforeWal".');
|
||||
}
|
||||
const beforeWal: LoadReceiptWalSnapshot = {
|
||||
bars_1m: parseWalTxnPair(parsed.beforeWal.bars_1m, 'beforeWal.bars_1m'),
|
||||
fx_1m: parseWalTxnPair(parsed.beforeWal.fx_1m, 'beforeWal.fx_1m'),
|
||||
...(parsed.beforeWal.bar_revisions !== undefined
|
||||
? {
|
||||
bar_revisions: parseWalTxnPair(
|
||||
parsed.beforeWal.bar_revisions,
|
||||
'beforeWal.bar_revisions'
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
|
||||
if (!isPlainObject(parsed.shards)) {
|
||||
throw new VerifyM2QuantError('Load receipt missing required object "shards".');
|
||||
}
|
||||
const parseShardProbesRaw = (prefix: RequiredShardPrefix): readonly unknown[] => {
|
||||
const entry = (parsed.shards as Record<string, unknown>)[prefix];
|
||||
if (!isPlainObject(entry) || !Array.isArray(entry.probes) || entry.probes.length === 0) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Load receipt shards.${prefix}.probes must be a non-empty array.`
|
||||
);
|
||||
}
|
||||
return entry.probes;
|
||||
};
|
||||
const shardsObj = parsed.shards as Record<string, unknown>;
|
||||
const bars1mShard = parseShardPrefixEntry(shardsObj, 'bars_1m', (p, f) =>
|
||||
parseBars1mProbe(p, f, BARS_1M_SOURCE_EOD)
|
||||
);
|
||||
const bars1mQmShard = parseShardPrefixEntry(shardsObj, 'bars_1m_qm', (p, f) =>
|
||||
parseBars1mProbe(p, f, BARS_1M_SOURCE_QM)
|
||||
);
|
||||
const fx1mShard = parseShardPrefixEntry(shardsObj, 'fx_1m', (p, f) => parseFx1mProbe(p, f));
|
||||
|
||||
const bars1mProbes = parseShardProbesRaw('bars_1m').map((p, idx) =>
|
||||
parseBars1mProbe(p, `shards.bars_1m.probes[${idx}]`, 'eod')
|
||||
);
|
||||
const bars1mQmProbes = parseShardProbesRaw('bars_1m_qm').map((p, idx) =>
|
||||
parseBars1mProbe(p, `shards.bars_1m_qm.probes[${idx}]`, 'qm')
|
||||
);
|
||||
const fx1mProbes = parseShardProbesRaw('fx_1m').map((p, idx) =>
|
||||
parseFx1mProbe(p, `shards.fx_1m.probes[${idx}]`)
|
||||
);
|
||||
// Both bars_1m and bars_1m_qm write to the QuestDB bars_1m table; require disjoint
|
||||
// settled WAL windows so EOD advancement can never mask a failed/rejected QM send.
|
||||
const eodBeforeW = BigInt(bars1mShard.beforeWal.writerTxn);
|
||||
const eodBeforeS = BigInt(bars1mShard.beforeWal.sequencerTxn);
|
||||
const eodAfterW = BigInt(bars1mShard.afterWal.writerTxn);
|
||||
const eodAfterS = BigInt(bars1mShard.afterWal.sequencerTxn);
|
||||
const qmBeforeW = BigInt(bars1mQmShard.beforeWal.writerTxn);
|
||||
const qmBeforeS = BigInt(bars1mQmShard.beforeWal.sequencerTxn);
|
||||
const qmAfterW = BigInt(bars1mQmShard.afterWal.writerTxn);
|
||||
const qmAfterS = BigInt(bars1mQmShard.afterWal.sequencerTxn);
|
||||
|
||||
const eodBeforeQm = qmBeforeW >= eodAfterW && qmBeforeS >= eodAfterS;
|
||||
const qmBeforeEod = eodBeforeW >= qmAfterW && eodBeforeS >= qmAfterS;
|
||||
if (!eodBeforeQm && !qmBeforeEod) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Load receipt shards.bars_1m [${bars1mShard.beforeWal.writerTxn}..${bars1mShard.afterWal.writerTxn}] and shards.bars_1m_qm [${bars1mQmShard.beforeWal.writerTxn}..${bars1mQmShard.afterWal.writerTxn}] have overlapping WAL windows; send and capture each prefix separately.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!isPlainObject(parsed.dedup)) {
|
||||
throw new VerifyM2QuantError('Load receipt missing required object "dedup".');
|
||||
|
|
@ -1402,12 +1508,15 @@ export function parseLoadReceiptJson(rawJson: string): M2LoadReceipt {
|
|||
parsed.dedup.overlapWinnerSource,
|
||||
'dedup.overlapWinnerSource'
|
||||
);
|
||||
if (overlapWinnerSourceRaw !== 'eod' && overlapWinnerSourceRaw !== 'qm') {
|
||||
if (
|
||||
overlapWinnerSourceRaw !== BARS_1M_SOURCE_EOD &&
|
||||
overlapWinnerSourceRaw !== BARS_1M_SOURCE_QM
|
||||
) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Load receipt dedup.overlapWinnerSource must be 'eod' or 'qm' (received '${overlapWinnerSourceRaw}').`
|
||||
`Load receipt dedup.overlapWinnerSource must be '${BARS_1M_SOURCE_EOD}' or '${BARS_1M_SOURCE_QM}' (received '${overlapWinnerSourceRaw}').`
|
||||
);
|
||||
}
|
||||
const overlapWinnerSource: 'eod' | 'qm' = overlapWinnerSourceRaw;
|
||||
const overlapWinnerSource: Bars1mSource = overlapWinnerSourceRaw;
|
||||
|
||||
let overlapProbes: readonly Bars1mProbeExpectation[] | undefined;
|
||||
if (parsed.dedup.overlapProbes !== undefined) {
|
||||
|
|
@ -1420,11 +1529,10 @@ export function parseLoadReceiptJson(rawJson: string): M2LoadReceipt {
|
|||
}
|
||||
|
||||
return {
|
||||
beforeWal,
|
||||
shards: {
|
||||
bars_1m: { probes: bars1mProbes },
|
||||
bars_1m_qm: { probes: bars1mQmProbes },
|
||||
fx_1m: { probes: fx1mProbes },
|
||||
bars_1m: bars1mShard,
|
||||
bars_1m_qm: bars1mQmShard,
|
||||
fx_1m: fx1mShard,
|
||||
},
|
||||
dedup: {
|
||||
eodSentRows,
|
||||
|
|
@ -1436,10 +1544,27 @@ export function parseLoadReceiptJson(rawJson: string): M2LoadReceipt {
|
|||
};
|
||||
}
|
||||
|
||||
function getRequiredMinWalFromReceipt(receipt: M2LoadReceipt): RequiredMinWalByTable {
|
||||
const eodAfterW = BigInt(receipt.shards.bars_1m.afterWal.writerTxn);
|
||||
const eodAfterS = BigInt(receipt.shards.bars_1m.afterWal.sequencerTxn);
|
||||
const qmAfterW = BigInt(receipt.shards.bars_1m_qm.afterWal.writerTxn);
|
||||
const qmAfterS = BigInt(receipt.shards.bars_1m_qm.afterWal.sequencerTxn);
|
||||
return {
|
||||
bars_1m: {
|
||||
writerTxn: (eodAfterW >= qmAfterW ? eodAfterW : qmAfterW).toString(),
|
||||
sequencerTxn: (eodAfterS >= qmAfterS ? eodAfterS : qmAfterS).toString(),
|
||||
},
|
||||
fx_1m: receipt.shards.fx_1m.afterWal,
|
||||
};
|
||||
}
|
||||
|
||||
interface ParsedResendBaseline {
|
||||
readonly walTables: ReadonlyMap<M2IntradayTableName, WalTxnPair>;
|
||||
readonly bars1mSummary: readonly Bars1mSourceSummaryRow[];
|
||||
readonly fx1mSummary: readonly Fx1mPairSourceSummaryRow[];
|
||||
readonly shardHashes: ShardHashesByPrefix;
|
||||
readonly bars1mContentDigest: string;
|
||||
readonly fx1mContentDigest: string;
|
||||
}
|
||||
|
||||
function parseResendBaselineJson(rawJson: string): ParsedResendBaseline {
|
||||
|
|
@ -1512,44 +1637,181 @@ function parseResendBaselineJson(rawJson: string): ParsedResendBaseline {
|
|||
};
|
||||
});
|
||||
|
||||
return { walTables: walMap, bars1mSummary, fx1mSummary };
|
||||
if (!isPlainObject(parsed.loadVerification) || !isPlainObject(parsed.loadVerification.shardHashes)) {
|
||||
throw new VerifyM2QuantError(
|
||||
'Resend baseline missing required "loadVerification.shardHashes" object.'
|
||||
);
|
||||
}
|
||||
const rawHashes = parsed.loadVerification.shardHashes as Record<string, unknown>;
|
||||
const shardHashes: ShardHashesByPrefix = {
|
||||
bars_1m: parseSha256List(rawHashes.bars_1m, 'resendBaseline.loadVerification.shardHashes.bars_1m'),
|
||||
bars_1m_qm: parseSha256List(
|
||||
rawHashes.bars_1m_qm,
|
||||
'resendBaseline.loadVerification.shardHashes.bars_1m_qm'
|
||||
),
|
||||
fx_1m: parseSha256List(rawHashes.fx_1m, 'resendBaseline.loadVerification.shardHashes.fx_1m'),
|
||||
};
|
||||
|
||||
const bars1mContentDigest = parseSha256Hex(
|
||||
parsed.bars1mContentDigest,
|
||||
'resendBaseline.bars1mContentDigest'
|
||||
);
|
||||
const fx1mContentDigest = parseSha256Hex(
|
||||
parsed.fx1mContentDigest,
|
||||
'resendBaseline.fx1mContentDigest'
|
||||
);
|
||||
|
||||
return {
|
||||
walTables: walMap,
|
||||
bars1mSummary,
|
||||
fx1mSummary,
|
||||
shardHashes,
|
||||
bars1mContentDigest,
|
||||
fx1mContentDigest,
|
||||
};
|
||||
}
|
||||
|
||||
function verifyWalAdvancement(
|
||||
beforeMap: Readonly<Record<'bars_1m' | 'fx_1m', WalTxnPair>>,
|
||||
afterTables: readonly WalTableStatusRow[],
|
||||
contextLabel: string
|
||||
): readonly WalAdvancementEntry[] {
|
||||
const afterByName = new Map<M2IntradayTableName, WalTableStatusRow>(
|
||||
afterTables.map(row => [row.name, row])
|
||||
function verifyPerPrefixWalAdvancement(
|
||||
receipt: M2LoadReceipt,
|
||||
liveWalTables: readonly WalTableStatusRow[],
|
||||
baselineWal?: ReadonlyMap<M2IntradayTableName, WalTxnPair>,
|
||||
contextLabel = 'Load receipt WAL check'
|
||||
): readonly PrefixWalAdvancementEntry[] {
|
||||
const liveByName = new Map<M2IntradayTableName, WalTableStatusRow>(
|
||||
liveWalTables.map(row => [row.name, row])
|
||||
);
|
||||
const results: WalAdvancementEntry[] = [];
|
||||
for (const table of ['bars_1m', 'fx_1m'] as const) {
|
||||
const before = beforeMap[table];
|
||||
const after = afterByName.get(table);
|
||||
if (after === undefined) {
|
||||
const prefixSpecs: readonly { readonly prefix: RequiredShardPrefix; readonly table: 'bars_1m' | 'fx_1m' }[] = [
|
||||
{ prefix: 'bars_1m', table: 'bars_1m' },
|
||||
{ prefix: 'bars_1m_qm', table: 'bars_1m' },
|
||||
{ prefix: 'fx_1m', table: 'fx_1m' },
|
||||
];
|
||||
|
||||
const results: PrefixWalAdvancementEntry[] = [];
|
||||
for (const { prefix, table } of prefixSpecs) {
|
||||
const shard = receipt.shards[prefix];
|
||||
const live = liveByName.get(table);
|
||||
if (live === undefined) {
|
||||
throw new VerifyM2QuantError(`${contextLabel}: missing table '${table}' in settled wal_tables().`);
|
||||
}
|
||||
const beforeWriter = BigInt(before.writerTxn);
|
||||
const afterWriter = BigInt(after.writerTxn);
|
||||
const beforeSeq = BigInt(before.sequencerTxn);
|
||||
const afterSeq = BigInt(after.sequencerTxn);
|
||||
const beforeWriter = BigInt(shard.beforeWal.writerTxn);
|
||||
const afterWriter = BigInt(shard.afterWal.writerTxn);
|
||||
const beforeSeq = BigInt(shard.beforeWal.sequencerTxn);
|
||||
const afterSeq = BigInt(shard.afterWal.sequencerTxn);
|
||||
const liveWriter = BigInt(live.writerTxn);
|
||||
const liveSeq = BigInt(live.sequencerTxn);
|
||||
|
||||
if (afterWriter <= beforeWriter || afterSeq <= beforeSeq) {
|
||||
throw new VerifyM2QuantError(
|
||||
`${contextLabel}: WAL for '${table}' did not advance (before writerTxn=${before.writerTxn}/sequencerTxn=${before.sequencerTxn}, after writerTxn=${after.writerTxn}/sequencerTxn=${after.sequencerTxn}).`
|
||||
`${contextLabel}: WAL for shard prefix '${prefix}' (${table}) did not advance.`
|
||||
);
|
||||
}
|
||||
if (liveWriter < afterWriter || liveSeq < afterSeq) {
|
||||
throw new VerifyM2QuantError(
|
||||
`${contextLabel}: live QuestDB WAL for '${table}' (writerTxn=${live.writerTxn}/sequencerTxn=${live.sequencerTxn}) is behind shard prefix '${prefix}' afterWal (writerTxn=${shard.afterWal.writerTxn}/sequencerTxn=${shard.afterWal.sequencerTxn}).`
|
||||
);
|
||||
}
|
||||
if (baselineWal !== undefined) {
|
||||
const base = baselineWal.get(table)!;
|
||||
const baseWriter = BigInt(base.writerTxn);
|
||||
const baseSeq = BigInt(base.sequencerTxn);
|
||||
if (beforeWriter < baseWriter || beforeSeq < baseSeq) {
|
||||
throw new VerifyM2QuantError(
|
||||
`${contextLabel}: shard prefix '${prefix}' beforeWal (writerTxn=${shard.beforeWal.writerTxn}/sequencerTxn=${shard.beforeWal.sequencerTxn}) predates resend baseline WAL (writerTxn=${base.writerTxn}/sequencerTxn=${base.sequencerTxn}).`
|
||||
);
|
||||
}
|
||||
if (liveWriter <= baseWriter || liveSeq <= baseSeq) {
|
||||
throw new VerifyM2QuantError(
|
||||
`${contextLabel}: live QuestDB WAL for '${table}' did not advance past resend baseline (baseline writerTxn=${base.writerTxn}/sequencerTxn=${base.sequencerTxn}, live writerTxn=${live.writerTxn}/sequencerTxn=${live.sequencerTxn}).`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
results.push({
|
||||
shardPrefix: prefix,
|
||||
table,
|
||||
beforeWriterTxn: before.writerTxn,
|
||||
afterWriterTxn: after.writerTxn,
|
||||
beforeSequencerTxn: before.sequencerTxn,
|
||||
afterSequencerTxn: after.sequencerTxn,
|
||||
beforeWriterTxn: shard.beforeWal.writerTxn,
|
||||
afterWriterTxn: shard.afterWal.writerTxn,
|
||||
beforeSequencerTxn: shard.beforeWal.sequencerTxn,
|
||||
afterSequencerTxn: shard.afterWal.sequencerTxn,
|
||||
liveWriterTxn: live.writerTxn,
|
||||
liveSequencerTxn: live.sequencerTxn,
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
async function computeBars1mContentDigest(executor: QuestDbPgQueryExecutor): Promise<string> {
|
||||
const sql =
|
||||
'SELECT source, utc_day, count() AS row_count, ' +
|
||||
'sum(open) AS sum_open, sum(high) AS sum_high, sum(low) AS sum_low, ' +
|
||||
'sum(close) AS sum_close, sum(volume) AS sum_volume, sum(close_sq) AS sum_close_sq, ' +
|
||||
'min(close) AS min_close, max(close) AS max_close, ' +
|
||||
'CAST(min(ts) AS LONG) AS min_ts_us, CAST(max(ts) AS LONG) AS max_ts_us ' +
|
||||
'FROM (SELECT source, CAST(ts AS LONG) / 86400000000 AS utc_day, ' +
|
||||
'open, high, low, close, volume, close * close AS close_sq, ts FROM bars_1m) ' +
|
||||
'GROUP BY source, utc_day ORDER BY source, utc_day';
|
||||
const res = await executor.query(sql);
|
||||
if (res.rows.length === 0) {
|
||||
throw new VerifyM2QuantError('QuestDB bars_1m content digest query returned zero buckets.');
|
||||
}
|
||||
const hash = createHash('sha256');
|
||||
for (const row of res.rows) {
|
||||
const source = parseRequiredStringCell(row.source, 'bars_1m_digest.source');
|
||||
const utcDay = parseBigIntCell(row.utc_day, 'bars_1m_digest.utc_day');
|
||||
const rowCount = parseBigIntCell(row.row_count, 'bars_1m_digest.row_count');
|
||||
const sumOpen = parseFiniteNumberCell(row.sum_open, 'bars_1m_digest.sum_open');
|
||||
const sumHigh = parseFiniteNumberCell(row.sum_high, 'bars_1m_digest.sum_high');
|
||||
const sumLow = parseFiniteNumberCell(row.sum_low, 'bars_1m_digest.sum_low');
|
||||
const sumClose = parseFiniteNumberCell(row.sum_close, 'bars_1m_digest.sum_close');
|
||||
const sumVolume = parseFiniteNumberCell(row.sum_volume, 'bars_1m_digest.sum_volume');
|
||||
const sumCloseSq = parseFiniteNumberCell(row.sum_close_sq, 'bars_1m_digest.sum_close_sq');
|
||||
const minClose = parseFiniteNumberCell(row.min_close, 'bars_1m_digest.min_close');
|
||||
const maxClose = parseFiniteNumberCell(row.max_close, 'bars_1m_digest.max_close');
|
||||
const minTsUs = parseBigIntCell(row.min_ts_us, 'bars_1m_digest.min_ts_us');
|
||||
const maxTsUs = parseBigIntCell(row.max_ts_us, 'bars_1m_digest.max_ts_us');
|
||||
hash.update(
|
||||
`${source}|${utcDay.toString()}|${rowCount.toString()}|${sumOpen}|${sumHigh}|${sumLow}|${sumClose}|${sumVolume}|${sumCloseSq}|${minClose}|${maxClose}|${minTsUs.toString()}|${maxTsUs.toString()}\n`
|
||||
);
|
||||
}
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
async function computeFx1mContentDigest(executor: QuestDbPgQueryExecutor): Promise<string> {
|
||||
const sql =
|
||||
'SELECT pair, source, utc_day, count() AS row_count, ' +
|
||||
'sum(open) AS sum_open, sum(high) AS sum_high, sum(low) AS sum_low, ' +
|
||||
'sum(close) AS sum_close, sum(close_sq) AS sum_close_sq, ' +
|
||||
'min(close) AS min_close, max(close) AS max_close, ' +
|
||||
'CAST(min(ts) AS LONG) AS min_ts_us, CAST(max(ts) AS LONG) AS max_ts_us ' +
|
||||
'FROM (SELECT pair, source, CAST(ts AS LONG) / 86400000000 AS utc_day, ' +
|
||||
'open, high, low, close, close * close AS close_sq, ts FROM fx_1m) ' +
|
||||
'GROUP BY pair, source, utc_day ORDER BY pair, source, utc_day';
|
||||
const res = await executor.query(sql);
|
||||
if (res.rows.length === 0) {
|
||||
throw new VerifyM2QuantError('QuestDB fx_1m content digest query returned zero buckets.');
|
||||
}
|
||||
const hash = createHash('sha256');
|
||||
for (const row of res.rows) {
|
||||
const pair = parseRequiredStringCell(row.pair, 'fx_1m_digest.pair');
|
||||
const source = parseRequiredStringCell(row.source, 'fx_1m_digest.source');
|
||||
const utcDay = parseBigIntCell(row.utc_day, 'fx_1m_digest.utc_day');
|
||||
const rowCount = parseBigIntCell(row.row_count, 'fx_1m_digest.row_count');
|
||||
const sumOpen = parseFiniteNumberCell(row.sum_open, 'fx_1m_digest.sum_open');
|
||||
const sumHigh = parseFiniteNumberCell(row.sum_high, 'fx_1m_digest.sum_high');
|
||||
const sumLow = parseFiniteNumberCell(row.sum_low, 'fx_1m_digest.sum_low');
|
||||
const sumClose = parseFiniteNumberCell(row.sum_close, 'fx_1m_digest.sum_close');
|
||||
const sumCloseSq = parseFiniteNumberCell(row.sum_close_sq, 'fx_1m_digest.sum_close_sq');
|
||||
const minClose = parseFiniteNumberCell(row.min_close, 'fx_1m_digest.min_close');
|
||||
const maxClose = parseFiniteNumberCell(row.max_close, 'fx_1m_digest.max_close');
|
||||
const minTsUs = parseBigIntCell(row.min_ts_us, 'fx_1m_digest.min_ts_us');
|
||||
const maxTsUs = parseBigIntCell(row.max_ts_us, 'fx_1m_digest.max_ts_us');
|
||||
hash.update(
|
||||
`${pair}|${source}|${utcDay.toString()}|${rowCount.toString()}|${sumOpen}|${sumHigh}|${sumLow}|${sumClose}|${sumCloseSq}|${minClose}|${maxClose}|${minTsUs.toString()}|${maxTsUs.toString()}\n`
|
||||
);
|
||||
}
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
async function verifyBars1mProbe(
|
||||
executor: QuestDbPgQueryExecutor,
|
||||
shardPrefix: 'bars_1m' | 'bars_1m_qm' | 'dedup_overlap',
|
||||
|
|
@ -1650,25 +1912,26 @@ async function verifyLoadReceipt(
|
|||
bars1mSummary: readonly Bars1mSourceSummaryRow[],
|
||||
fx1mSummary: readonly Fx1mPairSourceSummaryRow[]
|
||||
): Promise<LoadReceiptVerificationResult> {
|
||||
const walAdvancement = verifyWalAdvancement(
|
||||
{ bars_1m: receipt.beforeWal.bars_1m, fx_1m: receipt.beforeWal.fx_1m },
|
||||
const walAdvancement = verifyPerPrefixWalAdvancement(
|
||||
receipt,
|
||||
walTables,
|
||||
undefined,
|
||||
'Load receipt WAL check'
|
||||
);
|
||||
|
||||
const bySource = new Map<string, Bars1mSourceSummaryRow>(
|
||||
bars1mSummary.map(row => [row.source, row])
|
||||
);
|
||||
const eodGroup = bySource.get('eod');
|
||||
const qmGroup = bySource.get('qm');
|
||||
const eodGroup = bySource.get(BARS_1M_SOURCE_EOD);
|
||||
const qmGroup = bySource.get(BARS_1M_SOURCE_QM);
|
||||
if (eodGroup === undefined) {
|
||||
throw new VerifyM2QuantError(
|
||||
"Load receipt verification failed: QuestDB bars_1m is missing required source='eod' group (bars_1m shard prefix)."
|
||||
`Load receipt verification failed: QuestDB bars_1m is missing required source='${BARS_1M_SOURCE_EOD}' group (bars_1m shard prefix).`
|
||||
);
|
||||
}
|
||||
if (qmGroup === undefined) {
|
||||
throw new VerifyM2QuantError(
|
||||
"Load receipt verification failed: QuestDB bars_1m is missing required source='qm' group (bars_1m_qm shard prefix)."
|
||||
`Load receipt verification failed: QuestDB bars_1m is missing required source='${BARS_1M_SOURCE_QM}' group (bars_1m_qm shard prefix).`
|
||||
);
|
||||
}
|
||||
if (fx1mSummary.length === 0) {
|
||||
|
|
@ -1679,20 +1942,20 @@ async function verifyLoadReceipt(
|
|||
|
||||
const { eodSentRows, qmSentRows, overlapRows, overlapWinnerSource } = receipt.dedup;
|
||||
const minExpectedEodRows =
|
||||
overlapWinnerSource === 'qm' ? eodSentRows - overlapRows : eodSentRows;
|
||||
overlapWinnerSource === BARS_1M_SOURCE_QM ? eodSentRows - overlapRows : eodSentRows;
|
||||
const minExpectedQmRows =
|
||||
overlapWinnerSource === 'eod' ? qmSentRows - overlapRows : qmSentRows;
|
||||
overlapWinnerSource === BARS_1M_SOURCE_EOD ? qmSentRows - overlapRows : qmSentRows;
|
||||
const minExpectedTotalBars1mRows = eodSentRows + qmSentRows - overlapRows;
|
||||
const observedTotalBars1mRows = eodGroup.rowCount + qmGroup.rowCount;
|
||||
|
||||
if (eodGroup.rowCount < minExpectedEodRows) {
|
||||
throw new VerifyM2QuantError(
|
||||
`EOD/QM dedup accounting failed: observed bars_1m source='eod' rowCount=${eodGroup.rowCount} < expected minimum ${minExpectedEodRows}.`
|
||||
`EOD/QM dedup accounting failed: observed bars_1m source='${BARS_1M_SOURCE_EOD}' rowCount=${eodGroup.rowCount} < expected minimum ${minExpectedEodRows}.`
|
||||
);
|
||||
}
|
||||
if (qmGroup.rowCount < minExpectedQmRows) {
|
||||
throw new VerifyM2QuantError(
|
||||
`EOD/QM dedup accounting failed: observed bars_1m source='qm' rowCount=${qmGroup.rowCount} < expected minimum ${minExpectedQmRows}.`
|
||||
`EOD/QM dedup accounting failed: observed bars_1m source='${BARS_1M_SOURCE_QM}' rowCount=${qmGroup.rowCount} < expected minimum ${minExpectedQmRows}.`
|
||||
);
|
||||
}
|
||||
if (observedTotalBars1mRows < minExpectedTotalBars1mRows) {
|
||||
|
|
@ -1719,6 +1982,11 @@ async function verifyLoadReceipt(
|
|||
|
||||
return {
|
||||
walAdvancement,
|
||||
shardHashes: {
|
||||
bars_1m: receipt.shards.bars_1m.shardSha256,
|
||||
bars_1m_qm: receipt.shards.bars_1m_qm.shardSha256,
|
||||
fx_1m: receipt.shards.fx_1m.shardSha256,
|
||||
},
|
||||
dedupAccounting: {
|
||||
eodSentRows,
|
||||
qmSentRows,
|
||||
|
|
@ -1735,18 +2003,46 @@ async function verifyLoadReceipt(
|
|||
};
|
||||
}
|
||||
|
||||
function assertShardHashesMatch(
|
||||
prefix: RequiredShardPrefix,
|
||||
baselineHashes: readonly string[],
|
||||
currentHashes: readonly string[]
|
||||
): void {
|
||||
if (baselineHashes.length !== currentHashes.length) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Idempotent resend failed: shard hash count diverged for '${prefix}' (${baselineHashes.length} -> ${currentHashes.length}).`
|
||||
);
|
||||
}
|
||||
for (let i = 0; i < baselineHashes.length; i += 1) {
|
||||
if (baselineHashes[i] !== currentHashes[i]) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Idempotent resend failed: shard SHA-256 diverged for '${prefix}'[${i}] (${baselineHashes[i]} -> ${currentHashes[i]}).`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verifyIdempotentResend(
|
||||
baseline: ParsedResendBaseline,
|
||||
receipt: M2LoadReceipt,
|
||||
walTables: readonly WalTableStatusRow[],
|
||||
bars1mSummary: readonly Bars1mSourceSummaryRow[],
|
||||
fx1mSummary: readonly Fx1mPairSourceSummaryRow[]
|
||||
fx1mSummary: readonly Fx1mPairSourceSummaryRow[],
|
||||
bars1mContentDigest: string,
|
||||
fx1mContentDigest: string
|
||||
): ResendVerificationResult {
|
||||
const walAdvancement = verifyWalAdvancement(
|
||||
{
|
||||
bars_1m: baseline.walTables.get('bars_1m')!,
|
||||
fx_1m: baseline.walTables.get('fx_1m')!,
|
||||
},
|
||||
for (const prefix of REQUIRED_SHARD_PREFIXES) {
|
||||
assertShardHashesMatch(
|
||||
prefix,
|
||||
baseline.shardHashes[prefix],
|
||||
receipt.shards[prefix].shardSha256
|
||||
);
|
||||
}
|
||||
|
||||
const walAdvancement = verifyPerPrefixWalAdvancement(
|
||||
receipt,
|
||||
walTables,
|
||||
baseline.walTables,
|
||||
'Idempotent resend WAL check'
|
||||
);
|
||||
|
||||
|
|
@ -1795,11 +2091,25 @@ function verifyIdempotentResend(
|
|||
}
|
||||
}
|
||||
|
||||
if (bars1mContentDigest !== baseline.bars1mContentDigest) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Idempotent resend failed: bars_1m retained row content digest diverged (${baseline.bars1mContentDigest} -> ${bars1mContentDigest}).`
|
||||
);
|
||||
}
|
||||
if (fx1mContentDigest !== baseline.fx1mContentDigest) {
|
||||
throw new VerifyM2QuantError(
|
||||
`Idempotent resend failed: fx_1m retained row content digest diverged (${baseline.fx1mContentDigest} -> ${fx1mContentDigest}).`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
walAdvancement,
|
||||
shardHashesMatched: true,
|
||||
bars1mRowCountsUnchanged: true,
|
||||
fx1mRowCountsUnchanged: true,
|
||||
bars1mContentDigestMatched: true,
|
||||
fx1mContentDigestMatched: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -2071,42 +2381,48 @@ export async function runVerifyM2QuantCli(deps: VerifyM2QuantCliDeps = {}): Prom
|
|||
|
||||
// Validate Vault fence and 1-year effective window before any DB/store I/O.
|
||||
const fence = validateBenchmarkFence(parsed);
|
||||
const requiredMinWal = getRequiredMinWalFromReceipt(receipt);
|
||||
|
||||
let ddlResult: {
|
||||
readonly applied: boolean;
|
||||
readonly appliedTables: readonly M2IntradayTableName[];
|
||||
} = { applied: false, appliedTables: [] };
|
||||
let walTables: readonly WalTableStatusRow[];
|
||||
|
||||
if (parsed.applyDdl) {
|
||||
const ddlPgHandle = await openPg(parsed.questdb);
|
||||
try {
|
||||
const applied = await applyDdlFn(ddlPgHandle.executor);
|
||||
// Poll wal_tables() (metadata only, zero bar-table scans) and confirm all expected
|
||||
// load transactions are applied BEFORE starting the timed cold benchmark read.
|
||||
const preBenchPgHandle = await openPg(parsed.questdb);
|
||||
try {
|
||||
if (parsed.applyDdl) {
|
||||
const applied = await applyDdlFn(preBenchPgHandle.executor);
|
||||
ddlResult = { applied: true, appliedTables: applied.appliedTables };
|
||||
} finally {
|
||||
await ddlPgHandle.close();
|
||||
}
|
||||
walTables = await waitForHealthyWalTables(
|
||||
preBenchPgHandle.executor,
|
||||
parsed.walSettleTimeoutMs,
|
||||
walPollIntervalMs,
|
||||
nowMs,
|
||||
sleepMs,
|
||||
requiredMinWal
|
||||
);
|
||||
} finally {
|
||||
await preBenchPgHandle.close();
|
||||
}
|
||||
|
||||
// Measure the cold 1-year 1m benchmark read BEFORE any verifier query scans bars_1m
|
||||
// so QuestDB and OS page caches are not pre-warmed after restart.
|
||||
// or fx_1m so QuestDB and OS page caches are not pre-warmed after restart.
|
||||
const benchmark = await runIntradayLatencyBenchmark(parsed, fence, openStore, perfNowMs);
|
||||
|
||||
let walTables: readonly WalTableStatusRow[];
|
||||
let bars1mSummary: readonly Bars1mSourceSummaryRow[];
|
||||
let fx1mSummary: readonly Fx1mPairSourceSummaryRow[];
|
||||
let bars1mContentDigest: string;
|
||||
let fx1mContentDigest: string;
|
||||
let loadVerification: LoadReceiptVerificationResult;
|
||||
let resendVerification: ResendVerificationResult | undefined;
|
||||
const splitChecks: SplitBoundaryCheckResult[] = [];
|
||||
|
||||
const pgHandle = await openPg(parsed.questdb);
|
||||
try {
|
||||
walTables = await waitForHealthyWalTables(
|
||||
pgHandle.executor,
|
||||
parsed.walSettleTimeoutMs,
|
||||
walPollIntervalMs,
|
||||
nowMs,
|
||||
sleepMs
|
||||
);
|
||||
bars1mSummary = await verifyBars1mCommits(pgHandle.executor);
|
||||
fx1mSummary = await verifyFx1mCommits(pgHandle.executor);
|
||||
loadVerification = await verifyLoadReceipt(
|
||||
|
|
@ -2116,12 +2432,17 @@ export async function runVerifyM2QuantCli(deps: VerifyM2QuantCliDeps = {}): Prom
|
|||
bars1mSummary,
|
||||
fx1mSummary
|
||||
);
|
||||
bars1mContentDigest = await computeBars1mContentDigest(pgHandle.executor);
|
||||
fx1mContentDigest = await computeFx1mContentDigest(pgHandle.executor);
|
||||
if (resendBaseline !== undefined) {
|
||||
resendVerification = verifyIdempotentResend(
|
||||
resendBaseline,
|
||||
receipt,
|
||||
walTables,
|
||||
bars1mSummary,
|
||||
fx1mSummary
|
||||
fx1mSummary,
|
||||
bars1mContentDigest,
|
||||
fx1mContentDigest
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -2161,6 +2482,8 @@ export async function runVerifyM2QuantCli(deps: VerifyM2QuantCliDeps = {}): Prom
|
|||
walTables,
|
||||
bars1mSummary,
|
||||
fx1mSummary,
|
||||
bars1mContentDigest,
|
||||
fx1mContentDigest,
|
||||
loadVerification,
|
||||
...(resendVerification !== undefined ? { resendVerification } : {}),
|
||||
splitChecks,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue