Пример #1
0
        /// <summary>Register this backup node with the active name-node.</summary>
        /// <param name="nsInfo">namespace information</param>
        /// <exception cref="System.IO.IOException"/>
        private void RegisterWith(NamespaceInfo nsInfo)
        {
            BackupImage bnImage = (BackupImage)GetFSImage();
            NNStorage   storage = bnImage.GetStorage();

            // verify namespaceID
            if (storage.GetNamespaceID() == 0)
            {
                // new backup storage
                storage.SetStorageInfo(nsInfo);
                storage.SetBlockPoolID(nsInfo.GetBlockPoolID());
                storage.SetClusterID(nsInfo.GetClusterID());
            }
            else
            {
                nsInfo.ValidateStorage(storage);
            }
            bnImage.InitEditLog(HdfsServerConstants.StartupOption.Regular);
            SetRegistration();
            NamenodeRegistration nnReg = null;

            while (!IsStopRequested())
            {
                try
                {
                    nnReg = namenode.RegisterSubordinateNamenode(GetRegistration());
                    break;
                }
                catch (SocketTimeoutException e)
                {
                    // name-node is busy
                    Log.Info("Problem connecting to name-node: " + nnRpcAddress);
                    try
                    {
                        Sharpen.Thread.Sleep(1000);
                    }
                    catch (Exception)
                    {
                        Log.Warn("Encountered exception ", e);
                    }
                }
            }
            string msg = null;

            if (nnReg == null)
            {
                // consider as a rejection
                msg = "Registration rejected by " + nnRpcAddress;
            }
            else
            {
                if (!nnReg.IsRole(HdfsServerConstants.NamenodeRole.Namenode))
                {
                    msg = "Name-node " + nnRpcAddress + " is not active";
                }
            }
            if (msg != null)
            {
                msg += ". Shutting down.";
                Log.Error(msg);
                throw new IOException(msg);
            }
            // stop the node
            nnRpcAddress = nnReg.GetAddress();
        }