private boolean handleLeadershipEdgeTransitions() {
        boolean didWork = false;
        if (masterElectionHandler.isMaster()) {
            if ( ! isMaster) {
                // If we just became master, restore state from ZooKeeper
                stateChangeHandler.setStateChangedFlag();
                systemStateBroadcaster.resetBroadcastedClusterStateBundle();

                stateVersionTracker.setVersionRetrievedFromZooKeeper(database.getLatestSystemStateVersion());
                ClusterStateBundle previousBundle = database.getLatestClusterStateBundle();
                database.loadStartTimestamps(cluster);
                database.loadWantedStates(databaseContext);
                // TODO determine if we need any specialized handling here if feed block is set in the loaded bundle

                context.log(logger, Level.INFO, () -> String.format("Loaded previous cluster state bundle from ZooKeeper: %s", previousBundle));
                stateVersionTracker.setClusterStateBundleRetrievedFromZooKeeper(previousBundle);

                eventLog.add(new ClusterEvent(ClusterEvent.Type.MASTER_ELECTION, "This node just became fleetcontroller master. Bumped version to "
                        + stateVersionTracker.getCurrentVersion() + " to be in line.", timer.getCurrentTimeInMillis()));
                long currentTime = timer.getCurrentTimeInMillis();
                firstAllowedStateBroadcast = currentTime + options.minTimeBeforeFirstSystemStateBroadcast();
                isMaster = true;
                inMasterMoratorium = true;
                context.log(logger, Level.FINE, () -> "At time " + currentTime + " we set first system state broadcast time to be "
                                      + options.minTimeBeforeFirstSystemStateBroadcast() + " ms after at time " + firstAllowedStateBroadcast + ".");
                didWork = true;
            }
            if (wantedStateChanged) {
                didWork |= database.saveWantedStates(databaseContext);
                wantedStateChanged = false;
            }
        } else {
            dropLeadershipState();
        }
        metricUpdater.updateMasterState(isMaster);
        return didWork;
    }
Move tasks that are dependent on the most recently generated state being published into
a completion queue with a dependency on the provided version argument. Once that version
has been ACKed by all distributors in the system, those tasks will be marked as completed.
clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetController.java