<#4961 [Admin] Atomic enable/disable launch plans>...
# flyte-github
c
#4961 [Admin] Atomic enable/disable launch plans Issue created by wild-endeavor ## Description There's a corner case in the activate/archive launch plan code path right now that make the updating of the relevant launch plans not atomic. We should try to make it atomic. Roughly the code path right now is 1. Fetch the launch plan the user wants to update 2. Find the currently active one (if there is one) by doing a list 3. Update the scheduler optimistically (if the old one has a schedule then deactivate it, if the new one has a schedule then activate it) 4. Update the admin database by setting the old one to inactive and the new one to active. There's a couple corner cases we can maybe improve • The scheduler update itself is not atomic, so the second one can fail but the first one can succeed. • The set active call, which is being done in a transaction, doesn't do a compare and swap. The situation we'd like to prevent is the following: • LP v1 is currently active, and user 1 is activating v2. • The v1 schedule is successfully deactivated, and the v2 schedule is successfully activated. • Before the SetActive call is made, User 2 sets v3 to active. • This finds that v1 is still active in the database (because the first SetActive hasn't been called yet), so it will again deactivate the v1 schedule (which looking at the scheduler code should pass even though v1 has already been deactivated), and then activate the v3 schedule. • User 2's SetActive runs, setting v1 to inactive in the database and v3 to active. • User 1's SetActive runs, setting v1 to inactive (no-op), and v2 to active, ending up with two active versions. Any future trigger work should also implement any atomicity here. I think this edge case can also be mitigated if the scheduler returns an error when trying to deactivate something that's already deactivated, but not sure. ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte