You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: init mirror models eagerly and recover lost writes on reconnect
Fixes a silent startup race in CADT's MySQL mirror: if MySQL was not
yet reachable when CADT started, every mirror Model.init() call was
permanently skipped. Subsequent mirror writes threw
"Cannot read properties of undefined (reading 'constructor')" from
deep inside Sequelize and the mirror stayed non-functional for the
life of the process. Observed on the cadt-testneta-observer k8s pod.
Core fix (V1 + V2):
- safeMirrorDbHandler[V2] no longer wraps Model.init(). A new
initMirrorModel[V2] helper initialises models synchronously at
module-load time, which is safe because Sequelize.init is pure
metadata registration and does not require a live connection.
All 34 V1+V2 *.model.mirror.js files updated.
- safeMirrorDbHandler[V2] now detects disconnect->reconnect
transitions (and "setup never ran at startup") and runs
prepareMysqlMirror[V2] + backfillMirror[V2] before the current
callback, so writes dropped during an outage are recovered
without requiring a CADT restart.
- backfillMirror[V2] also sweeps orphan rows (mirror rows whose PK
no longer exists in source) so DELETEs issued during an outage
eventually propagate. Pagination now has an ORDER BY on the PK
so concurrent writes don't cause skipped rows. V1 previously
had no backfill at all - that is added.
- validateMirrorDbNames now fails loud instead of being swallowed
by the mirror-setup try/catch, so a V1/V2 DB_NAME collision
aborts startup the same way it did before this PR's refactor.
Tests:
- New integration tests: assert every mirror model is initialised
at module load (with a single-column-PK invariant guarding the
orphan sweep); orphan sweep removes source-deleted rows from
the mirror; reconnect detection runs backfill; steady-state
connects do NOT run backfill.
- V1 live-api data-short.js now verifies records land in the V1
MySQL mirror (symmetric with V2). Ports mysql-mirror-helpers to
V1 and fixes a date-then-numeric comparison fallback in both
helpers so '2024-01-01' no longer equals '2024-06-15' by
parseFloat.
CI:
- test-v2-live-api and test-v1-live-api now stop MariaDB mid-setup
and restart it ~30s after CADT starts, exercising the startup
race plus the reconnect+backfill recovery path end-to-end.
Both jobs hard-fail if MariaDB is still reachable after
service mariadb stop so a degraded race test cannot silently
pass. V1 Start CADT now polls the V1 API endpoint with
exit-on-timeout, matching V2.
Related fix (out of scope for the bug but same test surface):
- wallet-health.live.spec.js and datalayer-test-helpers.js now
honour CERTIFICATE_FOLDER_PATH via a new shared live-api helper,
matching src/datalayer/wallet.js. Previously hardcoded
\${chiaRoot}/config/ssl would false-negative in deployments
using a non-default Chia SSL directory.
0 commit comments