public void setTargetVersion(NodeType nodeType, Version newTargetVersion, boolean force) {
        assertLegalNodeTypeForTargetVersion(nodeType);

        try (Lock lock = db.lockInfrastructureVersions()) {
            Map<NodeType, Version> infrastructureVersions = db.readInfrastructureVersions();
            Version currentTargetVersion = Optional.ofNullable(infrastructureVersions.get(nodeType))
                    .orElse(Version.emptyVersion);

            // Trying to set the version to the current version, skip
            if (currentTargetVersion.equals(newTargetVersion)) return;

            // If we don't force the set, we must set the new version to higher than the already set version
            if (!force && currentTargetVersion.isAfter(newTargetVersion)) {
                throw new IllegalArgumentException(String.format("Cannot downgrade version without setting 'force'. Current target version: %s, attempted to set target version: %s",
                        currentTargetVersion.toFullString(), newTargetVersion.toFullString()));
            }

            if (newTargetVersion.isEmpty()) {
                infrastructureVersions.remove(nodeType);
                logger.info("Removing target version for " + nodeType);
            } else {
                infrastructureVersions.put(nodeType, newTargetVersion);
                logger.info("Setting target version for " + nodeType + " to " + newTargetVersion.toFullString());
            }
            db.writeInfrastructureVersions(infrastructureVersions);
        }
    }
Multithread safe class to see and set target versions for infrastructure node types.
{@link InfrastructureProvisioner} maintainer will then allocate the nodes of given node type
with a wanted version equal to the given target version.

@author freva
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureVersions.java