stag7824 opened a new pull request, #14722:
URL: https://github.com/apache/cloudstack/pull/14722
### Description
Fixes #14709
`createConsoleEndpoint` fails with `Duplicate key kvm.vnc.address (attempted
merging values 10.x.x.x and 10.x.x.x)` for a VM that has two `kvm.vnc.address`
rows in `vm_instance_details`.
`ConsoleAccessManagerImpl.getConsoleConnectionDetails` reads the VM's
keyboard and VNC details with `vmInstanceDetailsDao.listDetailsKeyPairs(vmId,
keys)`, and `ResourceDetailsDaoBase` builds that map with
return results.stream().collect(Collectors.toMap(R::getName,
R::getValue));
`Collectors.toMap` without a merge function throws `IllegalStateException`
on the first duplicate name, which is exactly the message in the report. The
sibling `listDetailsKeyPairs(long resourceId)` fills a `HashMap` with `put`, so
for the same rows it keeps the last value and does not fail.
This change gives both `toMap` calls in `ResourceDetailsDaoBase` (the one
above and the one in `listDetailsKeyPairsWithVisibility`) a merge function that
keeps the last value, so all three key-pair methods behave the same. That is
the "console endpoint creation should tolerate duplicate detail keys" half of
the expected behaviour in the issue.
How the second row got there is not addressed here, and I haven't confirmed
it. One way it can happen: `ResourceDetailsDaoBase.addDetail(R)` does
`findDetail`, `remove`, `persist` with no transaction around it and there is no
unique key on `(vm_id, name)`, so two overlapping writes of the same detail can
each insert a row. Making that write atomic touches every details table, so
I've kept it out of this fix; happy to look at it separately if wanted.
### Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
### Feature/Enhancement Scale or Bug Severity
#### Bug Severity
- [x] Major
### How Has This Been Tested?
Added three tests to `ResourceDetailsDaoBaseTest`:
- `listDetailsKeyPairs(resourceId, keys)` with `kvm.vnc.address` stored
twice with the same value, as in the report, plus `kvm.vnc.port`
- the same method with a name stored twice with different values, keeping
the last one
- `listDetailsKeyPairsWithVisibility` with a name stored twice
```
mvn test -pl engine/schema -Dtest=ResourceDetailsDaoBaseTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
```
With the two merge functions removed, all three new tests fail, the first
one with the message from the report:
```
java.lang.IllegalStateException: Duplicate key kvm.vnc.address (attempted
merging values 10.0.0.1 and 10.0.0.1)
java.lang.IllegalStateException: Duplicate key key1 (attempted merging
values old and new)
java.lang.IllegalStateException: Duplicate key key1 (attempted merging
values old and new)
```
I don't have a KVM host to repeat the failed-maintenance sequence on, so
this is tested at the DAO level only.
--
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]