Esempio n. 1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.HA.ServiceFailedException"/>
        private int Failover(CommandLine cmd)
        {
            bool forceFence  = cmd.HasOption(Forcefence);
            bool forceActive = cmd.HasOption(Forceactive);
            int  numOpts     = cmd.GetOptions() == null ? 0 : cmd.GetOptions().Length;

            string[] args = cmd.GetArgs();
            if (numOpts > 3 || args.Length != 2)
            {
                errOut.WriteLine("failover: incorrect arguments");
                PrintUsage(errOut, "-failover");
                return(-1);
            }
            HAServiceTarget fromNode = ResolveTarget(args[0]);
            HAServiceTarget toNode   = ResolveTarget(args[1]);

            // Check that auto-failover is consistently configured for both nodes.
            Preconditions.CheckState(fromNode.IsAutoFailoverEnabled() == toNode.IsAutoFailoverEnabled
                                         (), "Inconsistent auto-failover configs between %s and %s!", fromNode, toNode);
            if (fromNode.IsAutoFailoverEnabled())
            {
                if (forceFence || forceActive)
                {
                    // -forceActive doesn't make sense with auto-HA, since, if the node
                    // is not healthy, then its ZKFC will immediately quit the election
                    // again the next time a health check runs.
                    //
                    // -forceFence doesn't seem to have any real use cases with auto-HA
                    // so it isn't implemented.
                    errOut.WriteLine(Forcefence + " and " + Forceactive + " flags not " + "supported with auto-failover enabled."
                                     );
                    return(-1);
                }
                try
                {
                    return(GracefulFailoverThroughZKFCs(toNode));
                }
                catch (NotSupportedException e)
                {
                    errOut.WriteLine("Failover command is not supported with " + "auto-failover enabled: "
                                     + e.GetLocalizedMessage());
                    return(-1);
                }
            }
            FailoverController fc = new FailoverController(GetConf(), requestSource);

            try
            {
                fc.Failover(fromNode, toNode, forceFence, forceActive);
                @out.WriteLine("Failover from " + args[0] + " to " + args[1] + " successful");
            }
            catch (FailoverFailedException ffe)
            {
                errOut.WriteLine("Failover failed: " + ffe.GetLocalizedMessage());
                return(-1);
            }
            return(0);
        }
Esempio n. 2
0
 /// <summary>
 /// Ensure that we are allowed to manually manage the HA state of the target
 /// service.
 /// </summary>
 /// <remarks>
 /// Ensure that we are allowed to manually manage the HA state of the target
 /// service. If automatic failover is configured, then the automatic
 /// failover controllers should be doing state management, and it is generally
 /// an error to use the HAAdmin command line to do so.
 /// </remarks>
 /// <param name="target">the target to check</param>
 /// <returns>true if manual state management is allowed</returns>
 private bool CheckManualStateManagementOK(HAServiceTarget target)
 {
     if (target.IsAutoFailoverEnabled())
     {
         if (requestSource != HAServiceProtocol.RequestSource.RequestByUserForced)
         {
             errOut.WriteLine("Automatic failover is enabled for " + target + "\n" + "Refusing to manually manage HA state, since it may cause\n"
                              + "a split-brain scenario or other incorrect state.\n" + "If you are very sure you know what you are doing, please \n"
                              + "specify the --" + Forcemanual + " flag.");
             return(false);
         }
         else
         {
             Log.Warn("Proceeding with manual HA state management even though\n" + "automatic failover is enabled for "
                      + target);
             return(true);
         }
     }
     return(true);
 }