Example #1
0
 /// <exception cref="System.IO.IOException"/>
 private void LoadSnapshots(InputStream @in, int size)
 {
     for (int i = 0; i < size; i++)
     {
         FsImageProto.SnapshotSection.Snapshot pbs = FsImageProto.SnapshotSection.Snapshot
                                                     .ParseDelimitedFrom(@in);
         INodeDirectory root = FSImageFormatPBINode.Loader.LoadINodeDirectory(pbs.GetRoot(
                                                                                  ), parent.GetLoaderContext());
         int            sid    = pbs.GetSnapshotId();
         INodeDirectory parent = fsDir.GetInode(root.GetId()).AsDirectory();
         Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                                                 (sid, root, parent);
         // add the snapshot to parent, since we follow the sequence of
         // snapshotsByNames when saving, we do not need to sort when loading
         parent.GetDirectorySnapshottableFeature().AddSnapshot(snapshot);
         snapshotMap[sid] = snapshot;
     }
 }
Example #2
0
            /// <exception cref="System.IO.IOException"/>
            private void SerializeDirDiffList(INodeDirectory dir, IList <INodeReference> refList
                                              , OutputStream @out)
            {
                DirectoryWithSnapshotFeature sf = dir.GetDirectoryWithSnapshotFeature();

                if (sf != null)
                {
                    IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffList = sf.GetDiffs().AsList
                                                                                      ();
                    FsImageProto.SnapshotDiffSection.DiffEntry entry = ((FsImageProto.SnapshotDiffSection.DiffEntry
                                                                         )FsImageProto.SnapshotDiffSection.DiffEntry.NewBuilder().SetInodeId(dir.GetId())
                                                                        .SetType(FsImageProto.SnapshotDiffSection.DiffEntry.Type.Directorydiff).SetNumOfDiff
                                                                            (diffList.Count).Build());
                    entry.WriteDelimitedTo(@out);
                    for (int i = diffList.Count - 1; i >= 0; i--)
                    {
                        // reverse order!
                        DirectoryWithSnapshotFeature.DirectoryDiff             diff = diffList[i];
                        FsImageProto.SnapshotDiffSection.DirectoryDiff.Builder db   = FsImageProto.SnapshotDiffSection.DirectoryDiff
                                                                                      .NewBuilder().SetSnapshotId(diff.GetSnapshotId()).SetChildrenSize(diff.GetChildrenSize
                                                                                                                                                            ()).SetIsSnapshotRoot(diff.IsSnapshotRoot());
                        INodeDirectoryAttributes copy = diff.snapshotINode;
                        if (!diff.IsSnapshotRoot() && copy != null)
                        {
                            db.SetName(ByteString.CopyFrom(copy.GetLocalNameBytes())).SetSnapshotCopy(FSImageFormatPBINode.Saver.BuildINodeDirectory
                                                                                                          (copy, parent.GetSaverContext()));
                        }
                        // process created list and deleted list
                        IList <INode> created = diff.GetChildrenDiff().GetList(Diff.ListType.Created);
                        db.SetCreatedListSize(created.Count);
                        IList <INode> deleted = diff.GetChildrenDiff().GetList(Diff.ListType.Deleted);
                        foreach (INode d in deleted)
                        {
                            if (d.IsReference())
                            {
                                refList.AddItem(d.AsReference());
                                db.AddDeletedINodeRef(refList.Count - 1);
                            }
                            else
                            {
                                db.AddDeletedINode(d.GetId());
                            }
                        }
                        ((FsImageProto.SnapshotDiffSection.DirectoryDiff)db.Build()).WriteDelimitedTo(@out
                                                                                                      );
                        SaveCreatedList(created, @out);
                    }
                }
            }
Example #3
0
 /// <summary>
 /// Remove the given snapshottable directory from
 /// <see cref="snapshottables"/>
 /// .
 /// </summary>
 private void RemoveSnapshottable(INodeDirectory s)
 {
     Sharpen.Collections.Remove(snapshottables, s.GetId());
 }
Example #4
0
 /// <summary>
 /// Add the given snapshottable directory to
 /// <see cref="snapshottables"/>
 /// .
 /// </summary>
 public virtual void AddSnapshottable(INodeDirectory dir)
 {
     Preconditions.CheckArgument(dir.IsSnapshottable());
     snapshottables[dir.GetId()] = dir;
 }