예제 #1
0
        /// <exception cref="System.Exception"/>
        protected override void ServiceInit(Configuration conf)
        {
            conf = conf is YarnConfiguration ? conf : new YarnConfiguration(conf);
            string zkQuorum = conf.Get(YarnConfiguration.RmZkAddress);

            if (zkQuorum == null)
            {
                throw new YarnRuntimeException("Embedded automatic failover " + "is enabled, but "
                                               + YarnConfiguration.RmZkAddress + " is not set");
            }
            string rmId      = HAUtil.GetRMHAId(conf);
            string clusterId = YarnConfiguration.GetClusterId(conf);

            localActiveNodeInfo = CreateActiveNodeInfo(clusterId, rmId);
            string zkBasePath = conf.Get(YarnConfiguration.AutoFailoverZkBasePath, YarnConfiguration
                                         .DefaultAutoFailoverZkBasePath);
            string electionZNode    = zkBasePath + "/" + clusterId;
            long   zkSessionTimeout = conf.GetLong(YarnConfiguration.RmZkTimeoutMs, YarnConfiguration
                                                   .DefaultRmZkTimeoutMs);
            IList <ACL> zkAcls = RMZKUtils.GetZKAcls(conf);
            IList <ZKUtil.ZKAuthInfo> zkAuths = RMZKUtils.GetZKAuths(conf);
            int maxRetryNum = conf.GetInt(CommonConfigurationKeys.HaFcElectorZkOpRetriesKey,
                                          CommonConfigurationKeys.HaFcElectorZkOpRetriesDefault);

            elector = new ActiveStandbyElector(zkQuorum, (int)zkSessionTimeout, electionZNode
                                               , zkAcls, zkAuths, this, maxRetryNum);
            elector.EnsureParentZNode();
            if (!IsParentZnodeSafe(clusterId))
            {
                NotifyFatalError(electionZNode + " znode has invalid data! " + "Might need formatting!"
                                 );
            }
            base.ServiceInit(conf);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestHandleSessionExpiration()
        {
            ActiveStandbyElector.ActiveStandbyElectorCallback cb = cbs[0];
            byte[] appData = appDatas[0];
            ActiveStandbyElector elector = electors[0];

            // Let the first elector become active
            elector.EnsureParentZNode();
            elector.JoinElection(appData);
            ZooKeeperServer zks = GetServer(serverFactory);

            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, appData);
            Org.Mockito.Mockito.Verify(cb, Org.Mockito.Mockito.Timeout(1000)).BecomeActive();
            CheckFatalsAndReset();
            Log.Info("========================== Expiring session");
            zks.CloseSession(elector.GetZKSessionIdForTests());
            // Should enter neutral mode when disconnected
            Org.Mockito.Mockito.Verify(cb, Org.Mockito.Mockito.Timeout(1000)).EnterNeutralMode
                ();
            // Should re-join the election and regain active
            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, appData);
            Org.Mockito.Mockito.Verify(cb, Org.Mockito.Mockito.Timeout(1000)).BecomeActive();
            CheckFatalsAndReset();
            Log.Info("========================== Quitting election");
            elector.QuitElection(false);
            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, null);
            // Double check that we don't accidentally re-join the election
            // due to receiving the "expired" event.
            Thread.Sleep(1000);
            Org.Mockito.Mockito.Verify(cb, Org.Mockito.Mockito.Never()).BecomeActive();
            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, null);
            CheckFatalsAndReset();
        }
 /// <exception cref="System.Exception"/>
 public override void SetUp()
 {
     base.SetUp();
     zkServer = GetServer(serverFactory);
     for (int i = 0; i < NumElectors; i++)
     {
         cbs[i] = Org.Mockito.Mockito.Mock <ActiveStandbyElector.ActiveStandbyElectorCallback
                                            >();
         appDatas[i] = Ints.ToByteArray(i);
         electors[i] = new ActiveStandbyElector(hostPort, 5000, ParentDir, ZooDefs.Ids.OpenAclUnsafe
                                                , Collections.EmptyList <ZKUtil.ZKAuthInfo>(), cbs[i], CommonConfigurationKeys.HaFcElectorZkOpRetriesDefault
                                                );
     }
 }
예제 #4
0
        /// <summary>Randomly expire the ZK sessions of the two ZKFCs.</summary>
        /// <remarks>
        /// Randomly expire the ZK sessions of the two ZKFCs. This differs
        /// from the above test in that it is not a controlled failover -
        /// we just do random expirations and expect neither one to ever
        /// generate fatal exceptions.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestRandomExpirations()
        {
            cluster.Start();
            long   st     = Time.Now();
            long   runFor = StressRuntimeSecs * 1000;
            Random r      = new Random();

            while (Time.Now() - st < runFor)
            {
                cluster.GetTestContext().CheckException();
                int targetIdx = r.Next(2);
                ActiveStandbyElector target = cluster.GetElector(targetIdx);
                long sessId = target.GetZKSessionIdForTests();
                if (sessId != -1)
                {
                    Log.Info(string.Format("Expiring session %x for svc %d", sessId, targetIdx));
                    GetServer(serverFactory).CloseSession(sessId);
                }
                Thread.Sleep(r.Next(300));
            }
        }
예제 #5
0
        /// <exception cref="Org.Apache.Hadoop.HadoopIllegalArgumentException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Zookeeper.KeeperException"/>
        private void InitZK()
        {
            zkQuorum = conf.Get(ZkQuorumKey);
            int zkTimeout = conf.GetInt(ZkSessionTimeoutKey, ZkSessionTimeoutDefault);
            // Parse ACLs from configuration.
            string zkAclConf = conf.Get(ZkAclKey, ZkAclDefault);

            zkAclConf = ZKUtil.ResolveConfIndirection(zkAclConf);
            IList <ACL> zkAcls = ZKUtil.ParseACLs(zkAclConf);

            if (zkAcls.IsEmpty())
            {
                zkAcls = ZooDefs.Ids.CreatorAllAcl;
            }
            // Parse authentication from configuration.
            string zkAuthConf = conf.Get(ZkAuthKey);

            zkAuthConf = ZKUtil.ResolveConfIndirection(zkAuthConf);
            IList <ZKUtil.ZKAuthInfo> zkAuths;

            if (zkAuthConf != null)
            {
                zkAuths = ZKUtil.ParseAuth(zkAuthConf);
            }
            else
            {
                zkAuths = Collections.EmptyList();
            }
            // Sanity check configuration.
            Preconditions.CheckArgument(zkQuorum != null, "Missing required configuration '%s' for ZooKeeper quorum"
                                        , ZkQuorumKey);
            Preconditions.CheckArgument(zkTimeout > 0, "Invalid ZK session timeout %s", zkTimeout
                                        );
            int maxRetryNum = conf.GetInt(CommonConfigurationKeys.HaFcElectorZkOpRetriesKey,
                                          CommonConfigurationKeys.HaFcElectorZkOpRetriesDefault);

            elector = new ActiveStandbyElector(zkQuorum, zkTimeout, GetParentZnode(), zkAcls,
                                               zkAuths, new ZKFailoverController.ElectorCallbacks(this), maxRetryNum);
        }
 /// <exception cref="System.Exception"/>
 public static void WaitForElectorState(MultithreadedTestUtil.TestContext ctx, ActiveStandbyElector
                                        elector, ActiveStandbyElector.State state)
 {
     while (elector.GetStateForTests() != state)
     {
         if (ctx != null)
         {
             ctx.CheckException();
         }
         Thread.Sleep(50);
     }
 }