In E-MapReduce (EMR) 3.30.0 and later, JindoFS in block storage mode lets you dump the metadata of an entire namespace to Object Storage Service (OSS) and analyze it directly using Jindo SQL.
Background
In HDFS, metadata for the entire distributed file system is stored in a snapshot file named fsimage. The file contains metadata about the file system namespace, files, blocks, file system quotas, and other information. HDFS lets you download the entire fsimage file in XML format for offline metadata analysis, whereas JindoFS lets you analyze metadata without downloading it to your local environment.
Dump file system metadata to OSS
jindo jfs -dumpMetadata <nsName><nsName> is the name of the namespace in block storage mode.
test-block namespace:jindo jfs -dumpMetadata test-block
:bin xxx jindo jfs -dumpMetadata test-block
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/xxx/code/bigboot-3rdparty/bigboot/output/sdk/lib/bigboot-emr-cli.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/xxx/code/bigboot-3rdparty/bigboot/output/sdk/lib/jindo-auditlog-full.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/xxx/code/bigboot-3rdparty/bigboot/output/sdk/lib/jboot.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/xxx/code/bigboot-3rdparty/bigboot/output/sdk/lib/jindo-distcp-2.7.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Successfully upload namespace metadata to OSS.
Successfully upload namespace metadata to OSS.Metadata upload path
The upload path for metadata is the metadataDump subdirectory within the sysinfo directory that is configured in JindoFS.
namespace.sysinfo.oss.uri is configured as oss://abc/, JindoFS uploads the files to the oss://abc/metadataDump subdirectory.| Parameter | Description |
| namespace.sysinfo.oss.uri | The destination OSS bucket and path. |
| namespace.sysinfo.oss.endpoint | The endpoint for the OSS bucket. Cross-region access is supported. |
| namespace.sysinfo.oss.access.key | The AccessKey ID for your Alibaba Cloud account. |
| namespace.sysinfo.oss.access.secret | The AccessKey Secret for your Alibaba Cloud account. |
oss://emr-xxx-test/sysinfo/metadataDump/test-block/2020_09_14_18_58_16. In this path, oss://emr-xxx-test/sysinfo is the path configured for OSS system information, test-block is the namespace, and 2020_09_14_18_58_16 is the batch number.Metadata schema
{
"type":"string", /* inode type: FILE or DIRECTORY */
"id": "string", /* inode ID */
"parentId" :"string", /* parent node ID */
"name":"string", /* inode name */
"size": "int", /* inode size (bigint) */
"permission":"int", /* permission stored as an integer */
"owner":"string", /* owner name */
"ownerGroup":"string", /* owner group name */
"mtime":"int", /* inode modification time (bigint) */
"atime":"int", /* inode last access time (bigint) */
"attributes":"string", /* file-related attributes */
"state":"string", /* inode state */
"storagePolicy":"string", /* storage policy */
"etag":"string" /* etag */
}Analyze metadata with Jindo SQL
- Run the following command to start Jindo SQL.
[root@emr-header-1 ~]# jindo sql Spark master: yarn, Application Id: application_1603081647416_0050 jindo-sql> show tables; database tableName isTemporary default audit_log false default audit_log_source false default fs_image false Time taken: 0.33 seconds, Fetched 3 row(s) - Query the analysis tables.
- Use
show tablesto view the tables available for analysis. Jindo SQL provides the built-in audit_log and fs_image tables for analyzing audit and metadata information. - Use
show partitions fs_imageto view the partition information for thefs_imagetable. Each partition corresponds to the data from a single execution of thejindo jfs -dumpMetadatacommand.Example:jindo-sql> show partitions fs_image; partition namespace=kxxx/datetime=2020_10_20_10_47_14 namespace=kxxx/datetime=2020_10_20_10_50_36 namespace=kxxx/datetime=2020_10_20_10_52_06 Time taken: 0.045 seconds, Fetched 3 row(s)
- Use
- Query and analyze the metadata.
Jindo SQL uses Spark SQL syntax. You can use SQL to query and analyze the
fs_imagetable.Example:[root@emr-worker-2 hadoop]# jindo sql Spark master: yarn, Application Id: app jindo-sql> show tables; database tableName isTemporary default audit_log false default audit_log_source false default fs_image false Time taken: 0.345 seconds, Fetched 3 row(s) jindo-sql> select * from fs_image limit 10; atime ctime etag id mtime name owner ownerGroup parentId permission size state storagePolicy type name 0 7311076005051899448 1603084070081 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450819 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 16534448041906675495 1603084071350 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450820 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 7311076005051899470 1603084020185 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450821 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 11922762023479287249 1603084069581 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450822 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 1076984051887244l036 1603084073592 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450823 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 2699830986245l1354 1603084068996 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450824 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 1192276202347928730 1603084069875 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450825 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 1546464820l7665002 1603084072440 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450826 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 1653444804190667546 1603084071170 /tpcds/orc/5000/web_returns/wr_returned_date_sk=2450827 root root 334790833296 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 0 7311076005051899544 1603084070572 /tpcds/orc/5000/web_returns/wr_returned_date_sk=xxx root root 5855433 489 0 Finalized WARM Directory kugou 2020_10_20_10_50_36 Time taken: 6.764 seconds, Fetched 10 row(s)Jindo SQL adds two columns,
namespaceanddatetime, which correspond to the namespace name and the metadata upload timestamp, respectively.For example, to count the number of directories in a namespace based on a specific metadata dump:jindo-sql> select count(*) from fs_image where type = "Directory" and namespace="kugou" and datetime="2020_10_20_10_47_14"; count(1) 11837 Time taken: 6.852 seconds, Fetched 1 row(s)
Analyze metadata with Hive
- Create a Hive table.
In Hive, create an external table to query the metadata. You can use the following DDL statement as a template to create the file system metadata table.
CREATE EXTERNAL TABLE `table_name` (`type` string, `id` string, `parentId` string, `name` string, `size` bigint, `permission` int, `owner` string, `ownerGroup` string, `mtime` bigint, `atime` bigint, `attr` string, `state` string, `storagePolicy` string, `etag` string) ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' STORED AS TEXTFILE LOCATION 'OSS_PATH_TO_UPLOADED_FILES'; - Analyze the data using Hive.
After you create the Hive table, you can use Hive SQL to analyze the metadata.
select * from table_name limit 200;Example:hive> select * from inode_metadata_test8 limit 100; WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases. Query ID = root_xxx Total jobs = 1 Launching Job 1 out of 1 Number of reduce tasks is set to 0 since there's no reduce operator Starting Job = job_xxx, Tracking URL = http://emr-heade xxx:20888/proxy/applicxxx Kill Command = /usr/lib/hadoop-current/bin/hadoop job -kill job_159xxx Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0 2020-09-08 14:57:26,112 Stage-1 map = 0%, reduce = 0% 2020-09-08 14:57:31,263 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 1.22 sec MapReduce Total cumulative CPU time: 1 seconds 220 msec Ended Job = job_xxx MapReduce Jobs Launched: Stage-Stage-1: Map: 1 Cumulative CPU: 1.22 sec HDFS Read: 6867 HDFS Write: 1524 SUCCESS Total MapReduce CPU Time Spent: 1 seconds 220 msec OK Directory 11274334386847219714 11274334386847219713 /uttest/oss 0 511 caojie staff 1599545017615 1599545017615 Finalized WARM Directory 11274334386847219719 11274334386847219713 /uttest/oss2 0 511 caojie staff 1599545017654 1599545017654 Finalized WARM Directory 11274334386847219716 11274334386847219714 /uttest/oss/dir 0 511 caojie staff 1599545017636 1599545017636 Finalized WARM File 11274334386847219715 11274334386847219714 /uttest/oss/file1 0 420 caojie staff 1599545017632 1599545017632 Finalized WARM File 11274334386847219717 11274334386847219716 /uttest/oss/dir/file2 0 420 caojie staff 1599545017642 1599545017642 Finalized WARM File 11274334386847219718 11274334386847219716 /uttest/oss/dir/file3 0 420 caojie staff 1599545017651 1599545017651 Finalized WARM Directory 11274334386847219720 11274334386847219719 /uttest/oss2/dir 0 511 caojie staff 1599545017654 1599545017654 Finalized WARM File 11274334386847219721 11274334386847219720 /uttest/oss2/dir/file2 0 420 caojie staff 1599545017658 1599545017658 Finalized WARM File 11274334386847219722 11274334386847219720 /uttest/oss2/dir/file3 0 420 caojie staff 1599545017666 1599545017666 Finalized WARM Directory 11274334386847219713 17672823557438351905 /uttest 0 511 caojie staff 1599545017615 1599545017615 Finalized WARM Time taken: 10.734 seconds