private Optional<LoadBalancer> provisionFromPool(LoadBalancerSpec spec, NodeType type) {
        if (type != NodeType.tenant) return Optional.empty();
        if ( ! spec.settings().isDefault()) return Optional.empty();
        if (preProvisionPoolSize.value() == 0) return Optional.empty();

        try (Lock lock = db.lock(preProvisionOwner)) {
            long tail = db.readLoadBalancerPoolTail();
            if (tail >= db.readLoadBalancerPoolHead()) return Optional.empty();
            ClusterSpec.Id slot = slotId(tail);
            Optional<LoadBalancer> candidate = db.readLoadBalancer(new LoadBalancerId(preProvisionOwner, slot));
            if (candidate.flatMap(LoadBalancer::instance).map(instance -> ! instance.cloudAccount().equals(spec.cloudAccount())).orElse(false)) return Optional.empty();
            db.incrementLoadBalancerPoolTail(); // Acquire now; if we fail below, no one else will use the possibly inconsistent instance.
            LoadBalancer chosen = candidate.orElseThrow(() -> new IllegalStateException("could not find load balancer " + slot + " in pre-provisioned pool"));
            if (chosen.state() != State.active || chosen.instance().isEmpty())
                throw new IllegalStateException("expected active load balancer in pre-provisioned pool, but got " + chosen);
            log.log(Level.INFO, "Using " + chosen + " from pre-provisioned pool");
            service.reallocate(new LoadBalancerSpec(spec.application(), spec.cluster(), spec.reals(), spec.settings(), spec.cloudAccount(), chosen.idSeed()));
            db.removeLoadBalancer(chosen.id()); // Using a transaction to remove this, and write the instance, would be better, but much hassle.
            // Should be immediately written again outside of this!
            return Optional.of(new LoadBalancer(new LoadBalancerId(spec.application(), spec.cluster()),
                                                chosen.idSeed(),
                                                chosen.instance(),
                                                State.reserved,
                                                nodeRepository.clock().instant()));
        }
        catch (RuntimeException e) {
            log.log(Level.WARNING, "Failed to provision load balancer from pool", e);
        }
        return Optional.empty();
    }
Provision a load balancer instance, if necessary
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/LoadBalancerProvisioner.java