Ejemplo n.º 1
0
        /// <summary>Initialize lease recovery for this block.</summary>
        /// <remarks>
        /// Initialize lease recovery for this block.
        /// Find the first alive data-node starting from the previous primary and
        /// make it primary.
        /// </remarks>
        public virtual void InitializeBlockRecovery(long recoveryId)
        {
            SetBlockUCState(HdfsServerConstants.BlockUCState.UnderRecovery);
            blockRecoveryId = recoveryId;
            if (replicas.Count == 0)
            {
                NameNode.blockStateChangeLog.Warn("BLOCK*" + " BlockInfoUnderConstruction.initLeaseRecovery:"
                                                  + " No blocks found, lease removed.");
            }
            bool allLiveReplicasTriedAsPrimary = true;

            for (int i = 0; i < replicas.Count; i++)
            {
                // Check if all replicas have been tried or not.
                if (replicas[i].IsAlive())
                {
                    allLiveReplicasTriedAsPrimary = (allLiveReplicasTriedAsPrimary && replicas[i].GetChosenAsPrimary
                                                         ());
                }
            }
            if (allLiveReplicasTriedAsPrimary)
            {
                // Just set all the replicas to be chosen whether they are alive or not.
                for (int i_1 = 0; i_1 < replicas.Count; i_1++)
                {
                    replicas[i_1].SetChosenAsPrimary(false);
                }
            }
            long mostRecentLastUpdate = 0;

            BlockInfoContiguousUnderConstruction.ReplicaUnderConstruction primary = null;
            primaryNodeIndex = -1;
            for (int i_2 = 0; i_2 < replicas.Count; i_2++)
            {
                // Skip alive replicas which have been chosen for recovery.
                if (!(replicas[i_2].IsAlive() && !replicas[i_2].GetChosenAsPrimary()))
                {
                    continue;
                }
                BlockInfoContiguousUnderConstruction.ReplicaUnderConstruction ruc = replicas[i_2];
                long lastUpdate = ruc.GetExpectedStorageLocation().GetDatanodeDescriptor().GetLastUpdateMonotonic
                                      ();
                if (lastUpdate > mostRecentLastUpdate)
                {
                    primaryNodeIndex     = i_2;
                    primary              = ruc;
                    mostRecentLastUpdate = lastUpdate;
                }
            }
            if (primary != null)
            {
                primary.GetExpectedStorageLocation().GetDatanodeDescriptor().AddBlockToBeRecovered
                    (this);
                primary.SetChosenAsPrimary(true);
                NameNode.blockStateChangeLog.Info("BLOCK* {} recovery started, primary={}", this,
                                                  primary);
            }
        }