Exemplo n.º 1
0
        public override QuotaCounts CleanSubtree(BlockStoragePolicySuite bsps, int snapshot
                                                 , int priorSnapshotId, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode> removedINodes
                                                 )
        {
            FileWithSnapshotFeature sf = GetFileWithSnapshotFeature();

            if (sf != null)
            {
                return(sf.CleanFile(bsps, this, snapshot, priorSnapshotId, collectedBlocks, removedINodes
                                    ));
            }
            QuotaCounts counts = new QuotaCounts.Builder().Build();

            if (snapshot == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId)
            {
                if (priorSnapshotId == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId)
                {
                    // this only happens when deleting the current file and the file is not
                    // in any snapshot
                    ComputeQuotaUsage(bsps, counts, false);
                    DestroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
                }
                else
                {
                    // when deleting the current file and the file is in snapshot, we should
                    // clean the 0-sized block if the file is UC
                    FileUnderConstructionFeature uc = GetFileUnderConstructionFeature();
                    if (uc != null)
                    {
                        uc.CleanZeroSizeBlock(this, collectedBlocks);
                    }
                }
            }
            return(counts);
        }
Exemplo n.º 2
0
 //  do not store locations of last block
 /// <summary>
 /// Serialize a
 /// <see cref="INodeFile"/>
 /// node
 /// </summary>
 /// <param name="node">The node to write</param>
 /// <param name="out">
 /// The
 /// <see cref="System.IO.DataOutputStream"/>
 /// where the fields are written
 /// </param>
 /// <param name="writeBlock">Whether to write block information</param>
 /// <exception cref="System.IO.IOException"/>
 public static void WriteINodeFile(INodeFile file, DataOutput @out, bool writeUnderConstruction
                                   )
 {
     WriteLocalName(file, @out);
     @out.WriteLong(file.GetId());
     @out.WriteShort(file.GetFileReplication());
     @out.WriteLong(file.GetModificationTime());
     @out.WriteLong(file.GetAccessTime());
     @out.WriteLong(file.GetPreferredBlockSize());
     WriteBlocks(file.GetBlocks(), @out);
     SnapshotFSImageFormat.SaveFileDiffList(file, @out);
     if (writeUnderConstruction)
     {
         if (file.IsUnderConstruction())
         {
             @out.WriteBoolean(true);
             FileUnderConstructionFeature uc = file.GetFileUnderConstructionFeature();
             WriteString(uc.GetClientName(), @out);
             WriteString(uc.GetClientMachine(), @out);
         }
         else
         {
             @out.WriteBoolean(false);
         }
     }
     WritePermissionStatus(file, @out);
 }
Exemplo n.º 3
0
        internal virtual INodeFile ToUnderConstruction(string clientName, string clientMachine
                                                       )
        {
            Preconditions.CheckState(!IsUnderConstruction(), "file is already under construction"
                                     );
            FileUnderConstructionFeature uc = new FileUnderConstructionFeature(clientName, clientMachine
                                                                               );

            AddFeature(uc);
            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert the file to a complete file, i.e., to remove the Under-Construction
        /// feature.
        /// </summary>
        public virtual INodeFile ToCompleteFile(long mtime)
        {
            Preconditions.CheckState(IsUnderConstruction(), "file is no longer under construction"
                                     );
            FileUnderConstructionFeature uc = GetFileUnderConstructionFeature();

            if (uc != null)
            {
                AssertAllBlocksComplete();
                RemoveFeature(uc);
                this.SetModificationTime(mtime);
            }
            return(this);
        }
Exemplo n.º 5
0
        // Helper function that writes an INodeUnderConstruction
        // into the output stream
        //
        /// <exception cref="System.IO.IOException"/>
        internal static void WriteINodeUnderConstruction(DataOutputStream @out, INodeFile
                                                         cons, string path)
        {
            WriteString(path, @out);
            @out.WriteLong(cons.GetId());
            @out.WriteShort(cons.GetFileReplication());
            @out.WriteLong(cons.GetModificationTime());
            @out.WriteLong(cons.GetPreferredBlockSize());
            WriteBlocks(cons.GetBlocks(), @out);
            cons.GetPermissionStatus().Write(@out);
            FileUnderConstructionFeature uc = cons.GetFileUnderConstructionFeature();

            WriteString(uc.GetClientName(), @out);
            WriteString(uc.GetClientMachine(), @out);
            @out.WriteInt(0);
        }
Exemplo n.º 6
0
 /// <summary>Load the under-construction files section, and update the lease map</summary>
 /// <exception cref="System.IO.IOException"/>
 internal void LoadFilesUnderConstructionSection(InputStream @in)
 {
     while (true)
     {
         FsImageProto.FilesUnderConstructionSection.FileUnderConstructionEntry entry = FsImageProto.FilesUnderConstructionSection.FileUnderConstructionEntry
                                                                                       .ParseDelimitedFrom(@in);
         if (entry == null)
         {
             break;
         }
         // update the lease manager
         INodeFile file = dir.GetInode(entry.GetInodeId()).AsFile();
         FileUnderConstructionFeature uc = file.GetFileUnderConstructionFeature();
         Preconditions.CheckState(uc != null);
         // file must be under-construction
         fsn.leaseManager.AddLease(uc.GetClientName(), entry.GetFullPath());
     }
 }
Exemplo n.º 7
0
            /// <exception cref="System.IO.IOException"/>
            private void Save(OutputStream @out, INodeFile n)
            {
                FsImageProto.INodeSection.INodeFile.Builder b = BuildINodeFile(n, parent.GetSaverContext
                                                                                   ());
                if (n.GetBlocks() != null)
                {
                    foreach (Block block in n.GetBlocks())
                    {
                        b.AddBlocks(PBHelper.Convert(block));
                    }
                }
                FileUnderConstructionFeature uc = n.GetFileUnderConstructionFeature();

                if (uc != null)
                {
                    FsImageProto.INodeSection.FileUnderConstructionFeature f = ((FsImageProto.INodeSection.FileUnderConstructionFeature
                                                                                 )FsImageProto.INodeSection.FileUnderConstructionFeature.NewBuilder().SetClientName
                                                                                    (uc.GetClientName()).SetClientMachine(uc.GetClientMachine()).Build());
                    b.SetFileUC(f);
                }
                FsImageProto.INodeSection.INode r = ((FsImageProto.INodeSection.INode)BuildINodeCommon
                                                         (n).SetType(FsImageProto.INodeSection.INode.Type.File).SetFile(b).Build());
                r.WriteDelimitedTo(@out);
            }