Beispiel #1
0
        /// <summary>
        /// Test replication for a file with snapshots, also including the scenario
        /// where the original file is deleted
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestReplicationAfterDeletion()
        {
            // Create file1, set its replication to 3
            DFSTestUtil.CreateFile(hdfs, file1, Blocksize, Replication, seed);
            IDictionary <Path, short> snapshotRepMap = new Dictionary <Path, short>();

            // Take 3 snapshots of sub1
            for (int i = 1; i <= 3; i++)
            {
                Path root   = SnapshotTestHelper.CreateSnapshot(hdfs, sub1, "s" + i);
                Path ssFile = new Path(root, file1.GetName());
                snapshotRepMap[ssFile] = Replication;
            }
            // Check replication
            CheckFileReplication(file1, Replication, Replication);
            CheckSnapshotFileReplication(file1, snapshotRepMap, Replication);
            // Delete file1
            hdfs.Delete(file1, true);
            // Check replication of snapshots
            foreach (Path ss in snapshotRepMap.Keys)
            {
                INodeFile ssInode = GetINodeFile(ss);
                // The replication number derived from the
                // INodeFileWithLink#getBlockReplication should always == expectedBlockRep
                NUnit.Framework.Assert.AreEqual(Replication, ssInode.GetBlockReplication());
                // Also check the number derived from INodeFile#getFileReplication
                NUnit.Framework.Assert.AreEqual(snapshotRepMap[ss], ssInode.GetFileReplication());
            }
        }
Beispiel #2
0
        /// <summary>Check the replication for both the current file and all its prior snapshots
        ///     </summary>
        /// <param name="currentFile">the Path of the current file</param>
        /// <param name="snapshotRepMap">
        /// A map maintaining all the snapshots of the current file, as well
        /// as their expected replication number stored in their corresponding
        /// INodes
        /// </param>
        /// <param name="expectedBlockRep">The expected replication number</param>
        /// <exception cref="System.Exception"/>
        private void CheckSnapshotFileReplication(Path currentFile, IDictionary <Path, short
                                                                                 > snapshotRepMap, short expectedBlockRep)
        {
            // First check the getBlockReplication for the INode of the currentFile
            INodeFile inodeOfCurrentFile = GetINodeFile(currentFile);

            NUnit.Framework.Assert.AreEqual(expectedBlockRep, inodeOfCurrentFile.GetBlockReplication
                                                ());
            // Then check replication for every snapshot
            foreach (Path ss in snapshotRepMap.Keys)
            {
                INodesInPath iip     = fsdir.GetINodesInPath(ss.ToString(), true);
                INodeFile    ssInode = iip.GetLastINode().AsFile();
                // The replication number derived from the
                // INodeFileWithLink#getBlockReplication should always == expectedBlockRep
                NUnit.Framework.Assert.AreEqual(expectedBlockRep, ssInode.GetBlockReplication());
                // Also check the number derived from INodeFile#getFileReplication
                NUnit.Framework.Assert.AreEqual(snapshotRepMap[ss], ssInode.GetFileReplication(iip
                                                                                               .GetPathSnapshotId()));
            }
        }
        public virtual QuotaCounts UpdateQuotaAndCollectBlocks(BlockStoragePolicySuite bsps
                                                               , INodeFile file, FileDiff removed, INode.BlocksMapUpdateInfo collectedBlocks, IList
                                                               <INode> removedINodes)
        {
            long oldStoragespace                  = file.StoragespaceConsumed();
            byte storagePolicyID                  = file.GetStoragePolicyID();
            BlockStoragePolicy         bsp        = null;
            EnumCounters <StorageType> typeSpaces = new EnumCounters <StorageType>(typeof(StorageType
                                                                                          ));

            if (storagePolicyID != BlockStoragePolicySuite.IdUnspecified)
            {
                bsp = bsps.GetPolicy(file.GetStoragePolicyID());
            }
            if (removed.snapshotINode != null)
            {
                short replication = removed.snapshotINode.GetFileReplication();
                short currentRepl = file.GetBlockReplication();
                if (currentRepl == 0)
                {
                    long oldFileSizeNoRep = file.ComputeFileSize(true, true);
                    oldStoragespace = oldFileSizeNoRep * replication;
                    if (bsp != null)
                    {
                        IList <StorageType> oldTypeChosen = bsp.ChooseStorageTypes(replication);
                        foreach (StorageType t in oldTypeChosen)
                        {
                            if (t.SupportTypeQuota())
                            {
                                typeSpaces.Add(t, -oldFileSizeNoRep);
                            }
                        }
                    }
                }
                else
                {
                    if (replication > currentRepl)
                    {
                        long oldFileSizeNoRep = file.StoragespaceConsumedNoReplication();
                        oldStoragespace = oldFileSizeNoRep * replication;
                        if (bsp != null)
                        {
                            IList <StorageType> oldTypeChosen = bsp.ChooseStorageTypes(replication);
                            foreach (StorageType t in oldTypeChosen)
                            {
                                if (t.SupportTypeQuota())
                                {
                                    typeSpaces.Add(t, -oldFileSizeNoRep);
                                }
                            }
                            IList <StorageType> newTypeChosen = bsp.ChooseStorageTypes(currentRepl);
                            foreach (StorageType t_1 in newTypeChosen)
                            {
                                if (t_1.SupportTypeQuota())
                                {
                                    typeSpaces.Add(t_1, oldFileSizeNoRep);
                                }
                            }
                        }
                    }
                }
                AclFeature aclFeature = removed.GetSnapshotINode().GetAclFeature();
                if (aclFeature != null)
                {
                    AclStorage.RemoveAclFeature(aclFeature);
                }
            }
            GetDiffs().CombineAndCollectSnapshotBlocks(bsps, file, removed, collectedBlocks,
                                                       removedINodes);
            long ssDelta = oldStoragespace - file.StoragespaceConsumed();

            return(new QuotaCounts.Builder().StorageSpace(ssDelta).TypeSpaces(typeSpaces).Build
                       ());
        }