Ejemplo n.º 1
0
        /// <returns>the id of the last snapshot.</returns>
        public int GetLastSnapshotId()
        {
            AbstractINodeDiff <N, A, D> last = GetLast();

            return(last == null ? Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId
                                 : last.GetSnapshotId());
        }
Ejemplo n.º 2
0
        /// <summary>Delete a snapshot.</summary>
        /// <remarks>
        /// Delete a snapshot. The synchronization of the diff list will be done
        /// outside. If the diff to remove is not the first one in the diff list, we
        /// need to combine the diff with its previous one.
        /// </remarks>
        /// <param name="snapshot">The id of the snapshot to be deleted</param>
        /// <param name="prior">The id of the snapshot taken before the to-be-deleted snapshot
        ///     </param>
        /// <param name="collectedBlocks">Used to collect information for blocksMap update</param>
        /// <returns>delta in namespace.</returns>
        public QuotaCounts DeleteSnapshotDiff(BlockStoragePolicySuite bsps, int snapshot,
                                              int prior, N currentINode, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode
                                                                                                                           > removedINodes)
        {
            int         snapshotIndex = Sharpen.Collections.BinarySearch(diffs, snapshot);
            QuotaCounts counts        = new QuotaCounts.Builder().Build();
            D           removed       = null;

            if (snapshotIndex == 0)
            {
                if (prior != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId)
                {
                    // there is still snapshot before
                    // set the snapshot to latestBefore
                    diffs[snapshotIndex].SetSnapshotId(prior);
                }
                else
                {
                    // there is no snapshot before
                    removed = diffs.Remove(0);
                    counts.Add(removed.DestroyDiffAndCollectBlocks(bsps, currentINode, collectedBlocks
                                                                   , removedINodes));
                }
            }
            else
            {
                if (snapshotIndex > 0)
                {
                    AbstractINodeDiff <N, A, D> previous = diffs[snapshotIndex - 1];
                    if (previous.GetSnapshotId() != prior)
                    {
                        diffs[snapshotIndex].SetSnapshotId(prior);
                    }
                    else
                    {
                        // combine the to-be-removed diff with its previous diff
                        removed = diffs.Remove(snapshotIndex);
                        if (previous.snapshotINode == null)
                        {
                            previous.snapshotINode = removed.snapshotINode;
                        }
                        counts.Add(previous.CombinePosteriorAndCollectBlocks(bsps, currentINode, removed,
                                                                             collectedBlocks, removedINodes));
                        previous.SetPosterior(removed.GetPosterior());
                        removed.SetPosterior(null);
                    }
                }
            }
            return(counts);
        }