Пример #1
0
        /// <summary>Rename a snapshot</summary>
        /// <param name="path">
        /// The directory path where the snapshot was taken. Used for
        /// generating exception message.
        /// </param>
        /// <param name="oldName">Old name of the snapshot</param>
        /// <param name="newName">New name the snapshot will be renamed to</param>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException">
        /// Throw SnapshotException when either the snapshot with the old
        /// name does not exist or a snapshot with the new name already
        /// exists
        /// </exception>
        public virtual void RenameSnapshot(string path, string oldName, string newName)
        {
            if (newName.Equals(oldName))
            {
                return;
            }
            int indexOfOld = SearchSnapshot(DFSUtil.String2Bytes(oldName));

            if (indexOfOld < 0)
            {
                throw new SnapshotException("The snapshot " + oldName + " does not exist for directory "
                                            + path);
            }
            else
            {
                byte[] newNameBytes = DFSUtil.String2Bytes(newName);
                int    indexOfNew   = SearchSnapshot(newNameBytes);
                if (indexOfNew >= 0)
                {
                    throw new SnapshotException("The snapshot " + newName + " already exists for directory "
                                                + path);
                }
                // remove the one with old name from snapshotsByNames
                Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = snapshotsByNames
                                                                                    .Remove(indexOfOld);
                INodeDirectory ssRoot = snapshot.GetRoot();
                ssRoot.SetLocalName(newNameBytes);
                indexOfNew = -indexOfNew - 1;
                if (indexOfNew <= indexOfOld)
                {
                    snapshotsByNames.Add(indexOfNew, snapshot);
                }
                else
                {
                    // indexOfNew > indexOfOld
                    snapshotsByNames.Add(indexOfNew - 1, snapshot);
                }
            }
        }