コード例 #1
0
        internal virtual void AddReplicaIfNotPresent(DatanodeStorageInfo storage, Block block
                                                     , HdfsServerConstants.ReplicaState rState)
        {
            IEnumerator <BlockInfoContiguousUnderConstruction.ReplicaUnderConstruction> it = replicas
                                                                                             .GetEnumerator();

            while (it.HasNext())
            {
                BlockInfoContiguousUnderConstruction.ReplicaUnderConstruction r = it.Next();
                DatanodeStorageInfo expectedLocation = r.GetExpectedStorageLocation();
                if (expectedLocation == storage)
                {
                    // Record the gen stamp from the report
                    r.SetGenerationStamp(block.GetGenerationStamp());
                    return;
                }
                else
                {
                    if (expectedLocation != null && expectedLocation.GetDatanodeDescriptor() == storage
                        .GetDatanodeDescriptor())
                    {
                        // The Datanode reported that the block is on a different storage
                        // than the one chosen by BlockPlacementPolicy. This can occur as
                        // we allow Datanodes to choose the target storage. Update our
                        // state by removing the stale entry and adding a new one.
                        it.Remove();
                        break;
                    }
                }
            }
            replicas.AddItem(new BlockInfoContiguousUnderConstruction.ReplicaUnderConstruction
                                 (block, storage, rState));
        }