Exemplo n.º 1
0
        /// <exception cref="Org.Apache.Hadoop.HA.FailoverFailedException"/>
        private void DoFailover(HAServiceTarget tgt1, HAServiceTarget tgt2, bool forceFence
                                , bool forceActive)
        {
            FailoverController fc = new FailoverController(conf, HAServiceProtocol.RequestSource
                                                           .RequestByUser);

            fc.Failover(tgt1, tgt2, forceFence, forceActive);
        }
Exemplo n.º 2
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);
        }