소스 검색

HDFS-6283. Write end user documentation for xattrs. (wang)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2006@1594443 13f79535-47bb-0310-9956-ffa450edef68
Andrew Wang 11 년 전
부모
커밋
b9d21efbc5

+ 8 - 8
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/XAttrCommands.java

@@ -56,14 +56,14 @@ class XAttrCommands extends FsCommand {
     public static final String DESCRIPTION =
       "Displays the extended attribute names and values (if any) for a " +
       "file or directory.\n" +
-      "-R: Recurisively list the attributes for all files and directories.\n" +
-      "-n name: Dump the named extended attribute value.\n" + 
-      "-d: Dump all extended attribute values associated with " +
-      "pathname.\n" +
-      "-e <encoding>: Encode values after retrieving them. Valid encodings " +
-      "are \"text\", \"hex\", and \"base64\". Values encoded as text " +
-      "strings are enclosed in double quotes (\"), and values encoded" +
-      " as hexadecimal and base64 are prefixed with 0x and 0s, respectively.\n" +
+      "-R: Recursively list the attributes for all files and directories.\n" +
+      "-n name: Dump the named extended attribute value.\n" +
+      "-d: Dump all extended attribute values associated with pathname.\n" +
+      "-e <encoding>: Encode values after retrieving them.\n" +
+      "Valid encodings are \"text\", \"hex\", and \"base64\".\n" +
+      "Values encoded as text strings are enclosed in double quotes (\"),\n" +
+      " and values encoded as hexadecimal and base64 are prefixed with\n" +
+      "0x and 0s, respectively.\n" +
       "<path>: The file or directory.\n";
     private final static Function<String, XAttrCodec> enValueOfFunc =
         Enums.valueOfFunction(XAttrCodec.class);

+ 59 - 0
hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm

@@ -254,6 +254,35 @@ getfacl
 
    Returns 0 on success and non-zero on error.
 
+getfattr
+
+   Usage: <<<hdfs dfs -getfattr [-R] {-n name | -d} [-e en] <path> >>>
+
+   Displays the extended attribute names and values (if any) for a file or
+   directory.
+
+   Options:
+
+     * -R: Recursively list the attributes for all files and directories.
+
+     * -n name: Dump the named extended attribute value.
+
+     * -d: Dump all extended attribute values associated with pathname.
+
+     * -e <encoding>: Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
+
+     * <path>: The file or directory.
+
+   Examples:
+
+     * <<<hdfs dfs -getfattr -d /file>>>
+
+     * <<<hdfs dfs -getfattr -R -n user.myAttr /dir>>>
+
+   Exit Code:
+
+   Returns 0 on success and non-zero on error.
+
 getmerge
 
    Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>>
@@ -450,6 +479,36 @@ setfacl
 
    Returns 0 on success and non-zero on error.
 
+setfattr
+
+   Usage: <<<hdfs dfs -setfattr {-n name [-v value] | -x name} <path> >>>
+
+   Sets an extended attribute name and value for a file or directory.
+
+   Options:
+
+     * -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
+
+     * -n name: The extended attribute name.
+
+     * -v value: The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding.
+
+     * -x name: Remove the extended attribute.
+
+     * <path>: The file or directory.
+
+   Examples:
+
+      * <<<hdfs dfs -setfattr -n user.myAttr -v myValue /file>>>
+
+      * <<<hdfs dfs -setfattr -n user.noValue /file>>>
+
+      * <<<hdfs dfs -setfattr -x user.myAttr /file>>>
+
+   Exit Code:
+
+   Returns 0 on success and non-zero on error.
+
 setrep
 
    Usage: <<<hdfs dfs -setrep [-R] [-w] <numReplicas> <path> >>>

+ 3 - 1
hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-2006.txt

@@ -31,7 +31,9 @@ HDFS-2006 (Unreleased)
 
     HDFS-6377. Unify xattr name and value limits into a single limit. (wang)
 
-    HDFS-6373. Remove support for extended attributes on symlinks (Charles Lamb via wang)
+    HDFS-6373. Remove support for extended attributes on symlinks. (Charles Lamb via wang)
+
+    HDFS-6283. Write end user documentation for xattrs. (wang)
 
   OPTIMIZATIONS
 

+ 25 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml

@@ -1895,4 +1895,28 @@
   </description>
 </property>
 
-</configuration>
+<property>
+  <name>dfs.namenode.xattrs.enabled</name>
+  <value>true</value>
+  <description>
+    Whether support for extended attributes is enabled on the NameNode.
+  </description>
+</property>
+
+<property>
+  <name>dfs.namenode.fs-limits.max-xattrs-per-inode</name>
+  <value>32</value>
+  <description>
+    Maximum number of extended attributes per inode.
+  </description>
+</property>
+
+<property>
+  <name>dfs.namenode.fs-limits.max-xattr-size</name>
+  <value>16384</value>
+  <description>
+    The maximum combined size of the name and value of an extended attribute in bytes.
+  </description>
+</property>
+
+</configuration>

+ 98 - 0
hadoop-hdfs-project/hadoop-hdfs/src/site/apt/ExtendedAttributes.apt.vm

@@ -0,0 +1,98 @@
+~~ Licensed under the Apache License, Version 2.0 (the "License");
+~~ you may not use this file except in compliance with the License.
+~~ You may obtain a copy of the License at
+~~
+~~   http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~ Unless required by applicable law or agreed to in writing, software
+~~ distributed under the License is distributed on an "AS IS" BASIS,
+~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+~~ See the License for the specific language governing permissions and
+~~ limitations under the License. See accompanying LICENSE file.
+
+  ---
+  Hadoop Distributed File System-${project.version} - Extended Attributes
+  ---
+  ---
+  ${maven.build.timestamp}
+
+Extended Attributes in HDFS
+
+  \[ {{{../../index.html}Go Back}} \]
+
+%{toc|section=1|fromDepth=2|toDepth=4}
+
+* {Overview}
+
+  <Extended attributes> (abbreviated as <xattrs>) are a filesystem feature that allow user applications to associate additional metadata with a file or directory. Unlike system-level inode metadata such as file permissions or modification time, extended attributes are not interpreted by the system and are instead used by applications to store additional information about an inode. Extended attributes could be used, for instance, to specify the character encoding of a plain-text document.
+
+** {HDFS extended attributes}
+
+  Extended attributes in HDFS are modeled after extended attributes in Linux (see the Linux manpage for {{{http://www.bestbits.at/acl/man/man5/attr.txt}attr(5)}} and {{{http://www.bestbits.at/acl/}related documentation}}). An extended attribute is a <name-value pair>, with a string name and binary value. Xattrs names must also be prefixed with a <namespace>. For example, an xattr named <myXattr> in the <user> namespace would be specified as <<user.myXattr>>. Multiple xattrs can be associated with a single inode.
+
+** {Namespaces and Permissions}
+
+  In HDFS, as in Linux, there are four valid namespaces: <<<user>>>, <<<trusted>>>, <<<system>>>, and <<<security>>>. Each of these namespaces have different access restrictions.
+
+  The <<<user>>> namespace is the namespace that will commonly be used by client applications. Access to extended attributes in the user namespace is controlled by the corresponding file permissions.
+
+  The <<<trusted>>> namespace is available only to HDFS superusers.
+
+  The <<<system>>> namespace is reserved for internal HDFS use. This namespace is not accessible through userspace methods, and is reserved for implementing internal HDFS features.
+
+  The <<<security>>> namespace is reserved for internal HDFS use. This namespace is not accessible through userspace methods. It is currently unused.
+
+* {Interacting with extended attributes}
+
+  The Hadoop shell has support for interacting with extended attributes via <<<hadoop fs -getfattr>>> and <<<hadoop fs -setfattr>>>. These commands are styled after the Linux {{{http://www.bestbits.at/acl/man/man1/getfattr.txt}getfattr(1)}} and {{{http://www.bestbits.at/acl/man/man1/setfattr.txt}setfattr(1)}} commands.
+
+** {getfattr}
+
+  <<<hadoop fs -getfattr [-R] {-n name | -d} [-e en] <path>>>>
+
+  Displays the extended attribute names and values (if any) for a file or directory.
+
+*--+--+
+-R | Recursively list the attributes for all files and directories.
+*--+--+
+-n name | Dump the named extended attribute value.
+*--+--+
+-d | Dump all extended attribute values associated with pathname.
+*--+--+
+-e \<encoding\> | Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
+*--+--+
+\<path\> | The file or directory.
+*--+--+
+
+** {setfattr}
+
+  <<<hadoop fs -setfattr {-n name [-v value] | -x name} <path>>>>
+
+  Sets an extended attribute name and value for a file or directory.
+
+*--+--+
+-n name | The extended attribute name.
+*--+--+
+-v value | The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding.
+*--+--+
+-x name | Remove the extended attribute.
+*--+--+
+\<path\> | The file or directory.
+*--+--+
+
+* {Configuration options}
+
+
+  HDFS supports extended attributes out of the box, without additional configuration. Administrators could potentially be interested in the options limiting the number of xattrs per inode and the size of xattrs, since xattrs increase the on-disk and in-memory space consumption of an inode.
+
+  * <<<dfs.namenode.xattrs.enabled>>>
+
+  Whether support for extended attributes is enabled on the NameNode. By default, extended attributes are enabled.
+
+  * <<<dfs.namenode.fs-limits.max-xattrs-per-inode>>>
+
+  The maximum number of extended attributes per inode. By default, this limit is 32.
+
+  * <<<dfs.namenode.fs-limits.max-xattr-size>>>
+
+  The maximum combined size of the name and value of an extended attribute in bytes. By default, this limit is 16384 bytes.

+ 1 - 0
hadoop-project/src/site/site.xml

@@ -86,6 +86,7 @@
       <item name="Centralized Cache Management" href="hadoop-project-dist/hadoop-hdfs/CentralizedCacheManagement.html"/>
       <item name="HDFS NFS Gateway" href="hadoop-project-dist/hadoop-hdfs/HdfsNfsGateway.html"/>
       <item name="HDFS Rolling Upgrade" href="hadoop-project-dist/hadoop-hdfs/HdfsRollingUpgrade.html"/>
+      <item name="Extended Attributes" href="hadoop-project-dist/hadoop-hdfs/ExtendedAttributes.html"/>
     </menu>
 
     <menu name="MapReduce" inherit="top">