public void refreshPool() {
        int size = preProvisionPoolSize.value();
        long head = db.readLoadBalancerPoolHead();
        long tail = db.readLoadBalancerPoolTail();
        try (Lock lock = db.lock(preProvisionOwner)) {
            while (head - tail > size) tail = db.incrementLoadBalancerPoolTail();
            // Mark surplus load balancers, and ones we failed to move to an application, for removal.
            for (LoadBalancer lb : db.readLoadBalancers(l -> l.application().equals(preProvisionOwner)).values()) {
                long slot = slotOf(lb.id().cluster());
                if (slot < tail) db.writeLoadBalancer(lb.with(State.removable, nodeRepository.clock().instant()), lb.state());
            }
        }
        // No need for lock while we provision, since we'll write atomically only after we're done, and the job lock ensures single writer.
        while (head - tail < size) {
            ClusterSpec.Id slot = slotId(head);
            LoadBalancerId id = new LoadBalancerId(preProvisionOwner, slot);
            LoadBalancerSpec spec = preProvisionSpec(slot, nodeRepository.zone().cloud().account(), toSeed(id));
            db.writeLoadBalancer(new LoadBalancer(id,
                                                  spec.idSeed(),
                                                  Optional.of(service.provision(spec)),
                                                  State.active, // Keep the expirer away.
                                                  nodeRepository.clock().instant()),
                                 null);
            head = db.incrementLoadBalancerPoolHead();
        }
    }
Evict surplus and failed load balancers, and pre-provision deficit ones. Should only be run by a maintenance job.
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/LoadBalancerProvisioner.java