public SnapshotableArrayList(SnapshotManager manager, ArrayList<T> initial) { if (initial != null) { snapshot = new ArrayList<T>(initial); } else { snapshot = new ArrayList<T>(); } live = Collections.synchronizedList(new ArrayList<T>(snapshot)); manager.add(this); }
/** * Load the snapshots section from fsimage. Also convert snapshottable directories into {@link * INodeDirectorySnapshottable}. */ public void loadSnapshotSection(InputStream in) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection section = SnapshotSection.parseDelimitedFrom(in); int snum = section.getNumSnapshots(); sm.setNumSnapshots(snum); sm.setSnapshotCounter(section.getSnapshotCounter()); for (long sdirId : section.getSnapshottableDirList()) { INodeDirectory dir = fsDir.getInode(sdirId).asDirectory(); final INodeDirectorySnapshottable sdir; if (!dir.isSnapshottable()) { sdir = new INodeDirectorySnapshottable(dir); fsDir.addToInodeMap(sdir); } else { // dir is root, and admin set root to snapshottable before sdir = (INodeDirectorySnapshottable) dir; sdir.setSnapshotQuota(INodeDirectorySnapshottable.SNAPSHOT_LIMIT); } sm.addSnapshottable(sdir); } loadSnapshots(in, snum); }
/** save all the snapshottable directories and snapshots to fsimage */ public void serializeSnapshotSection(OutputStream out) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection.Builder b = SnapshotSection.newBuilder() .setSnapshotCounter(sm.getSnapshotCounter()) .setNumSnapshots(sm.getNumSnapshots()); INodeDirectorySnapshottable[] snapshottables = sm.getSnapshottableDirs(); for (INodeDirectorySnapshottable sdir : snapshottables) { b.addSnapshottableDir(sdir.getId()); } b.build().writeDelimitedTo(out); int i = 0; for (INodeDirectorySnapshottable sdir : snapshottables) { for (Snapshot s : sdir.getSnapshotsByNames()) { Root sroot = s.getRoot(); SnapshotSection.Snapshot.Builder sb = SnapshotSection.Snapshot.newBuilder().setSnapshotId(s.getId()); INodeSection.INodeDirectory.Builder db = buildINodeDirectory(sroot, parent.getSaverContext()); INodeSection.INode r = INodeSection.INode.newBuilder() .setId(sroot.getId()) .setType(INodeSection.INode.Type.DIRECTORY) .setName(ByteString.copyFrom(sroot.getLocalNameBytes())) .setDirectory(db) .build(); sb.setRoot(r).build().writeDelimitedTo(out); i++; if (i % FSImageFormatProtobuf.Saver.CHECK_CANCEL_INTERVAL == 0) { context.checkCancelled(); } } } Preconditions.checkState(i == sm.getNumSnapshots()); parent.commitSection(headers, FSImageFormatProtobuf.SectionName.SNAPSHOT); }