Commit 5805663
committed
[iris] Lift transactions to entrypoints; ControllerTransitions methods take cur
Transactions used to be opened ~22 times inside ControllerTransitions
methods. That had three problems: (1) RPC handlers couldn't compose
multiple transitions atomically — the read-validate-then-write pattern
left a TOCTOU window; (2) transitions.py had a self._db backdoor next
to its self._store, blurring the layering rule; (3) the per-method
``with self._db.transaction()`` boilerplate said the same thing 22
times.
Move tx scope to the caller. Every "one-event" transition now takes a
``cur: TransactionCursor`` (or ``snap: Tx`` for read paths); the
RPC handlers in service.py and the loop iterations in controller.py
each open exactly one ``with self._store.transaction() as cur:``
around their work. Multi-tx orchestrators (``fail_workers`` chunked,
``prune_old_data`` per-row) keep their own internal tx loops because
that's their reason for existing. Test helpers prefixed
``_for_test`` keep their auto-tx wrappers since tests call them ad-hoc.
Post-commit work that used to live at the tail of methods (attribute
cache invalidation in register/remove worker, the ``worker_registered``
audit log) moves into ``cur.on_commit(...)`` hooks so it only fires
once the data is durable — and a rolled-back transaction can't leave
the in-memory scheduling cache ahead of the DB row.
The ``self._db`` field on ``ControllerTransitions`` becomes a thin
``@property`` that delegates to ``self._store._db``. Production code
in transitions.py never touches it; the property only exists so
existing test helpers that read directly via ``state._db.snapshot()``
keep working. ``ControllerStore.optimize()`` is added so transitions'
post-prune ``self._store.optimize()`` call has a place to land.
Tests: ~190 call sites in tests/ updated to the cur-passing form (most
mechanically via a regex-based transformer). conftest helpers
``submit_job`` / ``submit_direct_job`` / ``register_worker`` /
``dispatch_task`` / ``transition_task`` / ``sync_k8s`` open a tx and
pass cur. ``state._db.snapshot()`` reads in conftest switch to
``state._db.read_snapshot()`` so they don't try to BEGIN on the writer
connection from inside an open writer tx.
Verification: 850 controller-suite tests pass (one pre-existing
failure unchanged); pyrefly clean for the controller package; full
iris test suite green.1 parent edac00f commit 5805663
18 files changed
Lines changed: 1942 additions & 1631 deletions
File tree
- lib/iris
- src/iris/cluster/controller
- tests
- cluster
- controller
- e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1456 | 1456 | | |
1457 | 1457 | | |
1458 | 1458 | | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
1462 | 1464 | | |
1463 | 1465 | | |
1464 | 1466 | | |
1465 | | - | |
| 1467 | + | |
| 1468 | + | |
1466 | 1469 | | |
1467 | 1470 | | |
1468 | 1471 | | |
| |||
1625 | 1628 | | |
1626 | 1629 | | |
1627 | 1630 | | |
1628 | | - | |
| 1631 | + | |
| 1632 | + | |
1629 | 1633 | | |
1630 | 1634 | | |
1631 | 1635 | | |
| |||
1673 | 1677 | | |
1674 | 1678 | | |
1675 | 1679 | | |
1676 | | - | |
| 1680 | + | |
| 1681 | + | |
1677 | 1682 | | |
1678 | 1683 | | |
1679 | 1684 | | |
| |||
1769 | 1774 | | |
1770 | 1775 | | |
1771 | 1776 | | |
1772 | | - | |
| 1777 | + | |
| 1778 | + | |
1773 | 1779 | | |
1774 | 1780 | | |
1775 | 1781 | | |
| |||
1982 | 1988 | | |
1983 | 1989 | | |
1984 | 1990 | | |
1985 | | - | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
1986 | 1995 | | |
1987 | 1996 | | |
1988 | 1997 | | |
| |||
2052 | 2061 | | |
2053 | 2062 | | |
2054 | 2063 | | |
2055 | | - | |
| 2064 | + | |
| 2065 | + | |
2056 | 2066 | | |
2057 | 2067 | | |
2058 | 2068 | | |
| |||
2067 | 2077 | | |
2068 | 2078 | | |
2069 | 2079 | | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
2073 | | - | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
2074 | 2086 | | |
2075 | 2087 | | |
2076 | 2088 | | |
| |||
2099 | 2111 | | |
2100 | 2112 | | |
2101 | 2113 | | |
2102 | | - | |
2103 | | - | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
2104 | 2117 | | |
2105 | 2118 | | |
2106 | 2119 | | |
| |||
2116 | 2129 | | |
2117 | 2130 | | |
2118 | 2131 | | |
2119 | | - | |
| 2132 | + | |
| 2133 | + | |
2120 | 2134 | | |
2121 | 2135 | | |
2122 | 2136 | | |
| |||
2245 | 2259 | | |
2246 | 2260 | | |
2247 | 2261 | | |
2248 | | - | |
| 2262 | + | |
| 2263 | + | |
2249 | 2264 | | |
2250 | 2265 | | |
2251 | 2266 | | |
| |||
2268 | 2283 | | |
2269 | 2284 | | |
2270 | 2285 | | |
2271 | | - | |
| 2286 | + | |
| 2287 | + | |
2272 | 2288 | | |
2273 | 2289 | | |
2274 | 2290 | | |
| |||
2296 | 2312 | | |
2297 | 2313 | | |
2298 | 2314 | | |
2299 | | - | |
| 2315 | + | |
| 2316 | + | |
2300 | 2317 | | |
2301 | 2318 | | |
2302 | 2319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1161 | 1161 | | |
1162 | 1162 | | |
1163 | 1163 | | |
1164 | | - | |
| 1164 | + | |
| 1165 | + | |
1165 | 1166 | | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
1169 | 1171 | | |
1170 | 1172 | | |
1171 | 1173 | | |
1172 | 1174 | | |
1173 | 1175 | | |
1174 | 1176 | | |
1175 | 1177 | | |
1176 | | - | |
| 1178 | + | |
| 1179 | + | |
1177 | 1180 | | |
1178 | 1181 | | |
1179 | 1182 | | |
| |||
1228 | 1231 | | |
1229 | 1232 | | |
1230 | 1233 | | |
1231 | | - | |
| 1234 | + | |
| 1235 | + | |
1232 | 1236 | | |
1233 | 1237 | | |
1234 | 1238 | | |
| |||
1380 | 1384 | | |
1381 | 1385 | | |
1382 | 1386 | | |
1383 | | - | |
| 1387 | + | |
| 1388 | + | |
1384 | 1389 | | |
1385 | 1390 | | |
1386 | 1391 | | |
| |||
1625 | 1630 | | |
1626 | 1631 | | |
1627 | 1632 | | |
1628 | | - | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
1632 | | - | |
1633 | | - | |
1634 | | - | |
1635 | | - | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
1636 | 1643 | | |
1637 | 1644 | | |
1638 | 1645 | | |
| |||
1711 | 1718 | | |
1712 | 1719 | | |
1713 | 1720 | | |
1714 | | - | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
1715 | 1724 | | |
1716 | 1725 | | |
1717 | 1726 | | |
| |||
1725 | 1734 | | |
1726 | 1735 | | |
1727 | 1736 | | |
1728 | | - | |
| 1737 | + | |
| 1738 | + | |
1729 | 1739 | | |
1730 | 1740 | | |
1731 | 1741 | | |
| |||
2683 | 2693 | | |
2684 | 2694 | | |
2685 | 2695 | | |
2686 | | - | |
2687 | | - | |
2688 | | - | |
2689 | | - | |
2690 | | - | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
2691 | 2704 | | |
2692 | | - | |
2693 | 2705 | | |
2694 | 2706 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2070 | 2070 | | |
2071 | 2071 | | |
2072 | 2072 | | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
0 commit comments