Skip to content

engine/schema: tolerate a detail name stored twice when listing key pairs - #14722

Open
stag7824 wants to merge 1 commit into
apache:4.22from
stag7824:fix-detail-key-pairs-duplicate-names
Open

stag7824 wants to merge 1 commit into
apache:4.22from
stag7824:fix-detail-key-pairs-duplicate-names

Conversation

@stag7824

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • 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.

…airs

listDetailsKeyPairs(resourceId, keys) and listDetailsKeyPairsWithVisibility
collected the rows with Collectors.toMap without a merge function, so a
resource with two rows of the same name made the call throw
IllegalStateException. listDetailsKeyPairs(resourceId) already keeps the
last value in that case; do the same here.

Fixes apache#14709

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant