@Override public String toString() { return getClass().getSimpleName() + "." + root.getLocalName() + "(id=" + id + ")"; }
final String dirName = s.getRoot().getRootFullPathName(); if (!file.startsWith(dirName)) { String snapname = s.getRoot().getFullPathName(); if (dirName.equals(Path.SEPARATOR)) { // handle rootDir snapname += Path.SEPARATOR;
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);
Snapshot.Root sRoot = snapshots.get(i + skipSize).getRoot(); INodeAttributes nodeAttrs = getINodeAttributes( fsd, src, sRoot.getLocalNameBytes(), node, Snapshot.CURRENT_STATE_ID); listing[i] = createFileStatus( fsd, sRoot.getLocalNameBytes(), nodeAttrs, BlockStoragePolicySuite.ID_UNSPECIFIED, Snapshot.CURRENT_STATE_ID, false,
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);
Snapshot.Root sRoot = snapshots.get(i + skipSize).getRoot(); INodeAttributes nodeAttrs = getINodeAttributes( fsd, src, sRoot.getLocalNameBytes(), node, Snapshot.CURRENT_STATE_ID); listing[i] = createFileStatus( fsd, sRoot.getLocalNameBytes(), nodeAttrs, BlockStoragePolicySuite.ID_UNSPECIFIED, Snapshot.CURRENT_STATE_ID, false,
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);
final int expected = s.getRoot().getLocalName().compareTo( t.getRoot().getLocalName()); final int computed = Snapshot.ID_COMPARATOR.compare(s, t); Assert.assertEquals(expected > 0, computed > 0);
/** Add a snapshot. */ public Snapshot addSnapshot(INodeDirectory snapshotRoot, int id, String name) throws SnapshotException, QuotaExceededException { //check snapshot quota final int n = getNumSnapshots(); if (n + 1 > snapshotQuota) { throw new SnapshotException("Failed to add snapshot: there are already " + n + " snapshot(s) and the snapshot quota is " + snapshotQuota); } final Snapshot s = new Snapshot(id, name, snapshotRoot); final byte[] nameBytes = s.getRoot().getLocalNameBytes(); final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\"."); } final DirectoryDiff d = getDiffs().addDiff(id, snapshotRoot); d.setSnapshotRoot(s.getRoot()); snapshotsByNames.add(-i - 1, s); // set modification time final long now = Time.now(); snapshotRoot.updateModificationTime(now, Snapshot.CURRENT_STATE_ID); s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID); return s; }
/** Add a snapshot. */ public Snapshot addSnapshot(INodeDirectory snapshotRoot, int id, String name) throws SnapshotException, QuotaExceededException { //check snapshot quota final int n = getNumSnapshots(); if (n + 1 > snapshotQuota) { throw new SnapshotException("Failed to add snapshot: there are already " + n + " snapshot(s) and the snapshot quota is " + snapshotQuota); } final Snapshot s = new Snapshot(id, name, snapshotRoot); final byte[] nameBytes = s.getRoot().getLocalNameBytes(); final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\"."); } final DirectoryDiff d = getDiffs().addDiff(id, snapshotRoot); d.setSnapshotRoot(s.getRoot()); snapshotsByNames.add(-i - 1, s); // set modification time final long now = Time.now(); snapshotRoot.updateModificationTime(now, Snapshot.CURRENT_STATE_ID); s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID); return s; }
/** * Check the correctness of snapshot list within snapshottable dir */ private void checkSnapshotList(INodeDirectory srcRoot, String[] sortedNames, String[] names) { assertTrue(srcRoot.isSnapshottable()); ReadOnlyList<Snapshot> listByName = srcRoot .getDirectorySnapshottableFeature().getSnapshotList(); assertEquals(sortedNames.length, listByName.size()); for (int i = 0; i < listByName.size(); i++) { assertEquals(sortedNames[i], listByName.get(i).getRoot().getLocalName()); } List<DirectoryDiff> listByTime = srcRoot.getDiffs().asList(); assertEquals(names.length, listByTime.size()); for (int i = 0; i < listByTime.size(); i++) { Snapshot s = srcRoot.getDirectorySnapshottableFeature().getSnapshotById( listByTime.get(i).getSnapshotId()); assertEquals(names[i], s.getRoot().getLocalName()); } }
@Override public INode getChild(byte[] name, int snapshotId) { return getParent().getChild(name, snapshotId); }
@Override public ReadOnlyList<INode> getChildrenList(int snapshotId) { return getParent().getChildrenList(snapshotId); }
@Override public int compareTo(byte[] bytes) { return root.compareTo(bytes); }
@Override public ReadOnlyList<INode> getChildrenList(int snapshotId) { return getParent().getChildrenList(snapshotId); }
@Override public int compareTo(byte[] bytes) { return root.compareTo(bytes); }
Snapshot(int id, String name, INodeDirectory dir) { this(id, dir, dir); this.root.setLocalName(DFSUtil.string2Bytes(name)); }
Snapshot(int id, String name, INodeDirectory dir) { this(id, dir, dir); this.root.setLocalName(DFSUtil.string2Bytes(name)); }
@Override public INode getChild(byte[] name, int snapshotId) { return getParent().getChild(name, snapshotId); }
/** * Get the name of the given snapshot. * @param s The given snapshot. * @return The name of the snapshot, or an empty string if {@code s} is null */ static String getSnapshotName(Snapshot s) { return s != null ? s.getRoot().getLocalName() : ""; }