Commit 7564538
committed
Allocate NIC device id atomically to stop duplicate ethN on a VM
createNicForVm() reads the next free device id and persists the nic in two
separate steps:
int deviceId = _nicDao.getFreeDeviceId(vm.getId()); // reads existing nics
...
allocateNic(..., deviceId, ...); // persists much later
getFreeDeviceId() has no lock, and the nic row it is choosing an id for is not
written until the end of allocateNic(). Two nics added to the same VM at once
therefore both read the same free id and land on the same ethN.
This happens when several tiers of a VPC are brought up in parallel: each tier
attaches the *shared* redundant VR, so N concurrent createNicForVm() calls run
against one router. The result is two guest nics on one ethN (one network
blackholed) and, because the two routers of a redundant VPC end up with
different device -> network maps, divergent keepalived configs -> both routers
go PRIMARY and the VPC is dead. (issue #11710)
Fix: compute the free device id and persist the nic under the vm_instance row
lock, so device id assignment is atomic per VM. This is the same shape as the
existing persistNicAfterRaceCheck() IPv4 race guard and needs no change to job
dispatch. Serializing per router is what the non-concurrent path already does
implicitly (one tier at a time).
Fixes: #11710
Signed-off-by: Brad House <bhouse@nexthop.ai>1 parent b9a5977 commit 7564538
2 files changed
Lines changed: 70 additions & 4 deletions
File tree
- engine/orchestration/src
- main/java/org/apache/cloudstack/engine/orchestration
- test/java/org/apache/cloudstack/engine/orchestration
Lines changed: 26 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| |||
1141 | 1142 | | |
1142 | 1143 | | |
1143 | 1144 | | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
1144 | 1168 | | |
1145 | 1169 | | |
1146 | 1170 | | |
| |||
4510 | 4534 | | |
4511 | 4535 | | |
4512 | 4536 | | |
4513 | | - | |
4514 | | - | |
4515 | | - | |
| 4537 | + | |
4516 | 4538 | | |
4517 | | - | |
| 4539 | + | |
4518 | 4540 | | |
4519 | 4541 | | |
4520 | 4542 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| |||
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
1010 | 1015 | | |
1011 | 1016 | | |
1012 | 1017 | | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
1013 | 1057 | | |
0 commit comments