Esempio n. 1
0
        /// <returns>blocks of the file corresponding to the snapshot.</returns>
        public virtual BlockInfoContiguous[] GetBlocks(int snapshot)
        {
            if (snapshot == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId ||
                GetDiffs() == null)
            {
                return(GetBlocks());
            }
            FileDiff diff = GetDiffs().GetDiffById(snapshot);

            BlockInfoContiguous[] snapshotBlocks = diff == null?GetBlocks() : diff.GetBlocks
                                                           ();

            if (snapshotBlocks != null)
            {
                return(snapshotBlocks);
            }
            // Blocks are not in the current snapshot
            // Find next snapshot with blocks present or return current file blocks
            snapshotBlocks = GetDiffs().FindLaterSnapshotBlocks(snapshot);
            return((snapshotBlocks == null) ? GetBlocks() : snapshotBlocks);
        }
Esempio n. 2
0
        /// <summary>compute the quota usage change for a truncate op</summary>
        /// <param name="newLength">the length for truncation</param>
        /// <returns>the quota usage delta (not considering replication factor)</returns>
        internal virtual long ComputeQuotaDeltaForTruncate(long newLength)
        {
            BlockInfoContiguous[] blocks = GetBlocks();
            if (blocks == null || blocks.Length == 0)
            {
                return(0);
            }
            int  n    = 0;
            long size = 0;

            for (; n < blocks.Length && newLength > size; n++)
            {
                size += blocks[n].GetNumBytes();
            }
            bool onBoundary   = size == newLength;
            long truncateSize = 0;

            for (int i = (onBoundary ? n : n - 1); i < blocks.Length; i++)
            {
                truncateSize += blocks[i].GetNumBytes();
            }
            FileWithSnapshotFeature sf = GetFileWithSnapshotFeature();

            if (sf != null)
            {
                FileDiff diff = sf.GetDiffs().GetLast();
                BlockInfoContiguous[] sblocks = diff != null?diff.GetBlocks() : null;

                if (sblocks != null)
                {
                    for (int i_1 = (onBoundary ? n : n - 1); i_1 < blocks.Length && i_1 < sblocks.Length &&
                         blocks[i_1].Equals(sblocks[i_1]); i_1++)
                    {
                        truncateSize -= blocks[i_1].GetNumBytes();
                    }
                }
            }
            return(onBoundary ? -truncateSize : (GetPreferredBlockSize() - truncateSize));
        }