INodeSymlink(long id, byte[] name, PermissionStatus permissions, long mtime, long atime, String symlink) { super(id, name, permissions, mtime, atime); this.symlink = DFSUtil.string2Bytes(symlink); }
Snapshot(int id, String name, INodeDirectory dir) { this(id, dir, dir); this.root.setLocalName(DFSUtil.string2Bytes(name)); }
/** * Convert a UTF8 string to an array of byte arrays. */ public static byte[][] getPathComponents(String path) { // avoid intermediate split to String[] final byte[] bytes = string2Bytes(path); return DFSUtilClient .bytes2byteArray(bytes, bytes.length, (byte) Path.SEPARATOR_CHAR); }
/** * Same as {@link #renameReservedPathsOnUpgrade}, but for a single * byte array path component. */ private static byte[] renameReservedComponentOnUpgrade(byte[] component, final int layoutVersion) throws IllegalReservedPathException { // If the LV doesn't support snapshots, we're doing an upgrade if (!NameNodeLayoutVersion.supports(Feature.SNAPSHOT, layoutVersion)) { if (Arrays.equals(component, HdfsServerConstants.DOT_SNAPSHOT_DIR_BYTES)) { if (!renameReservedMap.containsKey(HdfsConstants.DOT_SNAPSHOT_DIR)) { throw new IllegalReservedPathException(RESERVED_ERROR_MSG); } component = DFSUtil.string2Bytes(renameReservedMap .get(HdfsConstants.DOT_SNAPSHOT_DIR)); } } return component; }
/** * Same as {@link #renameReservedPathsOnUpgrade}, but for a single * byte array path component. */ private static byte[] renameReservedRootComponentOnUpgrade(byte[] component, final int layoutVersion) throws IllegalReservedPathException { // If the LV doesn't support inode IDs, we're doing an upgrade if (!NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, layoutVersion)) { if (Arrays.equals(component, FSDirectory.DOT_RESERVED)) { if (!renameReservedMap.containsKey(HdfsConstants.DOT_SNAPSHOT_DIR)) { throw new IllegalReservedPathException(RESERVED_ERROR_MSG); } final String renameString = renameReservedMap .get(FSDirectory.DOT_RESERVED_STRING); component = DFSUtil.string2Bytes(renameString); LOG.info("Renamed root path " + FSDirectory.DOT_RESERVED_STRING + " to " + renameString); } } return component; }
/** Verify if the snapshot name is legal. */ static void verifySnapshotName(FSDirectory fsd, String snapshotName, String path) throws FSLimitException.PathComponentTooLongException { if (snapshotName.contains(Path.SEPARATOR)) { throw new HadoopIllegalArgumentException( "Snapshot name cannot contain \"" + Path.SEPARATOR + "\""); } final byte[] bytes = DFSUtil.string2Bytes(snapshotName); fsd.verifyINodeName(bytes); fsd.verifyMaxComponentLength(bytes, path); }
/** * Find the snapshot matching the given name. * * @param snapshotRoot The directory where snapshots were taken. * @param snapshotName The name of the snapshot. * @return The corresponding snapshot. Null if snapshotName is null or empty. * @throws SnapshotException If snapshotName is not null or empty, but there * is no snapshot matching the name. */ private Snapshot getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { Snapshot s = null; if (snapshotName != null && !snapshotName.isEmpty()) { final int index = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (index < 0) { throw new SnapshotException("Cannot find the snapshot of directory " + snapshotRoot.getFullPathName() + " with name " + snapshotName); } s = snapshotsByNames.get(index); } return s; }
final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName)); if (indexOfOld < 0) { throw new SnapshotException("The snapshot " + oldName return; final byte[] newNameBytes = DFSUtil.string2Bytes(newName); int indexOfNew = searchSnapshot(newNameBytes); if (indexOfNew >= 0) {
/** * Remove the snapshot with the given name from {@link #snapshotsByNames}, * and delete all the corresponding DirectoryDiff. * * @param reclaimContext records blocks and inodes that need to be reclaimed * @param snapshotRoot The directory where we take snapshots * @param snapshotName The name of the snapshot to be removed * @return The removed snapshot. Null if no snapshot with the given name * exists. */ public Snapshot removeSnapshot( INode.ReclaimContext reclaimContext, INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName + " from path " + snapshotRoot.getFullPathName() + ": the snapshot does not exist."); } else { final Snapshot snapshot = snapshotsByNames.get(i); int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId()); snapshotRoot.cleanSubtree(reclaimContext, snapshot.getId(), prior); // remove from snapshotsByNames after successfully cleaning the subtree snapshotsByNames.remove(i); return snapshot; } }
dir.getDirectorySnapshottableFeature().getSnapshotQuota(), dir.getParent() == null ? DFSUtilClient.EMPTY_BYTES : DFSUtil.string2Bytes(dir.getParent().getFullPathName())); statusList.add(status);
components[1] = DFSUtil.bytes2String( renameReservedRootComponentOnUpgrade( DFSUtil.string2Bytes(components[1]), layoutVersion)); path = DFSUtil.strings2PathString(components); components[i] = DFSUtil.bytes2String( renameReservedComponentOnUpgrade( DFSUtil.string2Bytes(components[i]), layoutVersion));
/** * Verifies that the combined size of the name and value of an xattr is within * the configured limit. Setting a limit of zero disables this check. */ private static void checkXAttrSize(FSDirectory fsd, XAttr xAttr) { int size = DFSUtil.string2Bytes(xAttr.getName()).length; if (xAttr.getValue() != null) { size += xAttr.getValue().length; } if (size > fsd.getXattrMaxSize()) { throw new HadoopIllegalArgumentException( "The XAttr is too big. The maximum combined size of the" + " name and value is " + fsd.getXattrMaxSize() + ", but the total size is " + size); } }
INodeSymlink(long id, byte[] name, PermissionStatus permissions, long mtime, long atime, String symlink) { super(id, name, permissions, mtime, atime); this.symlink = DFSUtil.string2Bytes(symlink); }
/** Convert strings to byte arrays for path components. */ static byte[][] getPathComponents(String[] strings) { if (strings.length == 0) { return new byte[][]{null}; } byte[][] bytes = new byte[strings.length][]; for (int i = 0; i < strings.length; i++) bytes[i] = DFSUtil.string2Bytes(strings[i]); return bytes; }
/** * Set local file name */ void setLocalName(String name) { this.name = DFSUtil.string2Bytes(name); }
componentsCopy[count] = DFSUtil.string2Bytes( DFSUtil.byteArray2PathString(components, count, 2));
/** Verify if the snapshot name is legal. */ static void verifySnapshotName(FSDirectory fsd, String snapshotName, String path) throws FSLimitException.PathComponentTooLongException { if (snapshotName.contains(Path.SEPARATOR)) { throw new HadoopIllegalArgumentException( "Snapshot name cannot contain \"" + Path.SEPARATOR + "\""); } final byte[] bytes = DFSUtil.string2Bytes(snapshotName); fsd.verifyINodeName(bytes); fsd.verifyMaxComponentLength(bytes, path); }
/** Verify if the snapshot name is legal. */ static void verifySnapshotName(FSDirectory fsd, String snapshotName, String path) throws FSLimitException.PathComponentTooLongException { if (snapshotName.contains(Path.SEPARATOR)) { throw new HadoopIllegalArgumentException( "Snapshot name cannot contain \"" + Path.SEPARATOR + "\""); } final byte[] bytes = DFSUtil.string2Bytes(snapshotName); fsd.verifyINodeName(bytes); fsd.verifyMaxComponentLength(bytes, path); }
private static boolean existsInDiffReport(List<DiffReportEntry> entries, DiffType type, String sourcePath, String targetPath) { for (DiffReportEntry entry : entries) { if (entry.equals(new DiffReportEntry(type, DFSUtil .string2Bytes(sourcePath), targetPath == null ? null : DFSUtil .string2Bytes(targetPath)))) { return true; } } return false; }
static Snapshot getSnapshot(INodesInPath inodesInPath, String name, int index) { if (name == null) { return null; } final INode inode = inodesInPath.getINode(index - 1); return inode.asDirectory().getSnapshot(DFSUtil.string2Bytes(name)); }