andrijapanicsb opened a new issue, #14835:
URL: https://github.com/apache/cloudstack/issues/14835

   **In short:** three problems in the database upgrade scripts, none in a 
released version yet. A site with Netris networks that upgrades to 4.22.2 could 
have a VNET that is still in use marked as free. A site on 4.22.2 or 4.22.3 
that later upgrades to 24.0 would skip a whole upgrade step. A site on 4.23.0.0 
that upgrades to 24.0 would miss three changes.
   
   We found three issues while checking the database upgrade paths on `4.22` at 
`16238b10c3` and `main` at `caf1091aae`. The first is relevant before 4.22.2 
ships. The other two concern upgrades to 24.0, including upgrades from the 
released `4.23.0.0` tag.
   
   This was an AI-assisted review using Claude Fable 5.2 and Codex Astra 6.2. 
We ran the Netris SQL in a disposable MariaDB fixture and tested upgrade-path 
selection separately. We did not run a full CloudStack upgrade.
   
   ### 1. Netris cleanup can clear an allocation that a live network is using
   
   The migration matches a removed network to an allocation using only 
`n.broadcast_uri = CONCAT('netris://', a.vnet)`. It then clears `account_id`, 
`reservation_id`, and `taken`. The match does not establish that the allocation 
still belongs to that removed network.
   
   **Observed in MariaDB:** A removed network had `netris://42`. VNET 42 was 
reassigned to a live network in the same zone, and another live allocation used 
42 in a second zone. Running the migration cleared both live reservations. 
Adding a zone check alone would still leave the same-zone case.
   
   There is a path to this state in CloudStack. Netris setup persists the 
numeric broadcast URI. If a nonpersistent network is deleted before first use, 
shutdown can return immediately because the network is still `Allocated`. The 
VNET can then be released while the soft-deleted network row retains its URI. 
We traced that lifecycle in source.
   
   **Expected:** Preserve live allocations. If the migration cannot establish 
that an allocation still belongs to the removed network, leave it intact. 
Please cover same-zone reassignment and reuse in another zone, and check all 
three copies of the statement. [4.22 
migration](https://github.com/apache/cloudstack/blob/16238b10c3/engine/schema/src/main/resources/META-INF/db/schema-42210to42220.sql#L39-L45)
 · [4.23 cleanup on 
main](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql#L43-L49)
 · [24.0 
migration](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/resources/META-INF/db/schema-42300to2400.sql#L27-L33)
   
   ### 2. A direct upgrade from 4.22.2 or 4.22.3 to 24.0 skips the 4.23 
migration
   
   A harness using `DatabaseVersionHierarchy` from `main`, with the registered 
version ranges and stand-in upgrade steps, produced these paths:
   
   | Starting database version | Steps selected for target 24.0 |
   |---|---|
   | 4.22.1.0 or 4.22.1.1 | `Upgrade42210to42300` → `Upgrade42300to2400` |
   | 4.22.2.0 or 4.22.3.0 | `Upgrade42300to2400` only |
   | 4.23.0.0 | `Upgrade42300to2400` only, as expected |
   
   For example, the skipped step adds `nics.enabled`, which the 24.0 
`cloud.user_vm_view` references. The harness establishes the routing error. The 
first failure during a full upgrade remains unverified.
   
   **Expected:** Direct upgrades from 4.22.2 and 4.22.3 receive the required 
4.23 schema and data migrations. Please add path tests for those starting 
versions and check that overlapping SQL is safe on an existing 4.22.2 database 
before replaying it. [Registered 
chain](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java#L249-L253)
 · [Column 
creation](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql#L306-L307)
 · [View 
reference](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql#L146)
   
   ### 3. Upgrading from released 4.23.0.0 to 24.0 misses three later changes
   
   After 4.23.0.0 shipped, three changes were added to the cleanup script for 
upgrading **to** 4.23. A database already on 4.23.0.0 skips that script, and 
the current 24.0 step does not apply these changes:
   
   - Creation of `backup_usage_metric`, used when publishing backup usage.
   - Zone scoping for `ip4_guest_subnet_network_map`, including 
`data_center_id`, three data updates, and the foreign key.
   - A backfill for existing cross-zone templates missing associations with 
Edge zones.
   
   **Expected:** The 4.23.0.0→24.0 step applies the missing changes safely, 
including the subnet data updates. Open PR #14490 already adds the Edge 
template backfill to the correct step. The backup table and subnet migration 
still need coverage. [Released cleanup 
script](https://github.com/apache/cloudstack/blob/4.23.0.0/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql)
 · [Later additions on 
main](https://github.com/apache/cloudstack/blob/caf1091aae/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql#L26-L78)
 · [#14490 diff](https://github.com/apache/cloudstack/pull/14490/files)
   
   ### Versions
   
   `4.22` at `16238b10c3` (4.22.2.0-SNAPSHOT), `main` at `caf1091aae` 
(24.0.0-SNAPSHOT), and the released tag `4.23.0.0` for comparison. No released 
version is affected yet.
   
   ### Steps to reproduce
   
   1. Netris: in a scratch MariaDB, create a removed network with 
`broadcast_uri = 'netris://42'`, have VNET 42 allocated to a live network in 
the same zone and to another in a second zone, then run the statement. Both 
live allocations are cleared.
   2. Skipped step: run `DatabaseVersionHierarchy.getPath` from `main` with the 
registered chain for 4.22.2.0 and 4.22.3.0 to 24.0.0. Only `Upgrade42300to2400` 
is selected.
   3. Missed changes: compare `schema-42210to42300-cleanup.sql` at tag 
`4.23.0.0` and on `main`.
   
   ### What to do about it
   
   See "Expected" under each of the three problems above. The Netris statement 
is the urgent one, because it ships with 4.22.2.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to