Beispiel #1
0
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotAccessControlException"/
        ///     >
        internal static Block[] UnprotectedSetReplication(FSDirectory fsd, string src, short
                                                          replication, short[] blockRepls)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INodesInPath iip   = fsd.GetINodesInPath4Write(src, true);
            INode        inode = iip.GetLastINode();

            if (inode == null || !inode.IsFile())
            {
                return(null);
            }
            INodeFile file  = inode.AsFile();
            short     oldBR = file.GetBlockReplication();

            // before setFileReplication, check for increasing block replication.
            // if replication > oldBR, then newBR == replication.
            // if replication < oldBR, we don't know newBR yet.
            if (replication > oldBR)
            {
                long dsDelta = file.StoragespaceConsumed() / oldBR;
                fsd.UpdateCount(iip, 0L, dsDelta, oldBR, replication, true);
            }
            file.SetFileReplication(replication, iip.GetLatestSnapshotId());
            short newBR = file.GetBlockReplication();

            // check newBR < oldBR case.
            if (newBR < oldBR)
            {
                long dsDelta = file.StoragespaceConsumed() / newBR;
                fsd.UpdateCount(iip, 0L, dsDelta, oldBR, newBR, true);
            }
            if (blockRepls != null)
            {
                blockRepls[0] = oldBR;
                blockRepls[1] = newBR;
            }
            return(file.GetBlocks());
        }
Beispiel #2
0
        private static QuotaCounts ComputeQuotaDeltas(FSDirectory fsd, INodeFile target,
                                                      INodeFile[] srcList)
        {
            QuotaCounts deltas     = new QuotaCounts.Builder().Build();
            short       targetRepl = target.GetBlockReplication();

            foreach (INodeFile src in srcList)
            {
                short srcRepl  = src.GetBlockReplication();
                long  fileSize = src.ComputeFileSize();
                if (targetRepl != srcRepl)
                {
                    deltas.AddStorageSpace(fileSize * (targetRepl - srcRepl));
                    BlockStoragePolicy bsp = fsd.GetBlockStoragePolicySuite().GetPolicy(src.GetStoragePolicyID
                                                                                            ());
                    if (bsp != null)
                    {
                        IList <StorageType> srcTypeChosen = bsp.ChooseStorageTypes(srcRepl);
                        foreach (StorageType t in srcTypeChosen)
                        {
                            if (t.SupportTypeQuota())
                            {
                                deltas.AddTypeSpace(t, -fileSize);
                            }
                        }
                        IList <StorageType> targetTypeChosen = bsp.ChooseStorageTypes(targetRepl);
                        foreach (StorageType t_1 in targetTypeChosen)
                        {
                            if (t_1.SupportTypeQuota())
                            {
                                deltas.AddTypeSpace(t_1, fileSize);
                            }
                        }
                    }
                }
            }
            return(deltas);
        }