def manage_nodes
      # Re-discover nodes, since the state of the world may have been changed
      # by the time we've become the primary node manager.
      discover_nodes

      # ensure that slaves are correctly pointing to this master
      redirect_slaves_to(@master)

      # Periodically update master config state.
      while running? && master_manager?
        @zk_lock.assert!
        sleep(CHECK_INTERVAL)

        @lock.synchronize do
          snapshots = current_node_snapshots
          if ensure_sufficient_node_managers(snapshots)
            snapshots.each_key do |node|
              update_master_state(node, snapshots)
            end

            # flush current master state
            write_current_redis_nodes

            # check if we've exhausted our attempts to promote a master
            unless @master
              @master_promotion_attempts += 1
              raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
            end
          end
        end
      end
    end
def manage_nodes
      # Re-discover nodes, since the state of the world may have been changed
      # by the time we've become the primary node manager.
      discover_nodes

      # ensure that slaves are correctly pointing to this master
      redirect_slaves_to(@master)

      # Periodically update master config state.
      while running? && master_manager?
        @zk_lock.assert!
        sleep(CHECK_INTERVAL)

        @lock.synchronize do
          snapshots = current_node_snapshots
          if ensure_sufficient_node_managers(snapshots)
            snapshots.each_key do |node|
              update_master_state(node, snapshots)
            end

            # flush current master state
            write_current_redis_nodes

            # check if we've exhausted our attempts to promote a master
            unless @master
              @master_promotion_attempts += 1
              raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
            end
          end
        end
      end
    end
Manages the redis nodes by periodically processing snapshots.