This topic describes how to use JindoCache to accelerate jobs that access OSS-HDFS. JindoCache uses your cluster's storage resources to provide transparent caching for OSS-HDFS files, improving data access performance.
Prerequisites
-
You have created a cluster and selected the JindoCache service. For more information, see Create a cluster.
-
You have enabled OSS-HDFS and granted the required permissions. For more information, see Enable OSS-HDFS.
Procedure
-
Define a caching policy.
JindoCache uses CacheSets to manage caching policies. You can define one or more CacheSets to apply different policies to different paths.
-
Log on to the cluster. For more information, see Log on to a cluster.
-
Create a
cacheset.xmlfile.In this example, the
cacheset.xmlfile is in the/pathdirectory.<?xml version="1.0" encoding="UTF-8"?> <cachesets> <cacheset> <name>name1</name> <path>oss://emr-test/dir1</path> <cacheStrategy>DISTRIBUTED</cacheStrategy> <metaPolicy> <type>ALWAYS</type> </metaPolicy> <readPolicy>CACHE_ASIDE</readPolicy> <writePolicy>WRITE_AROUND</writePolicy> </cacheset> <cacheset> <name>name2</name> <path>oss://emr-test/dir2</path> <cacheStrategy>DHT</cacheStrategy> <metaPolicy> <type>ONCE</type> </metaPolicy> <readPolicy>CACHE_ASIDE</readPolicy> <writePolicy>WRITE_AROUND</writePolicy> </cacheset> </cachesets>Parameter
Description
Example
name
The name of the CacheSet. This name must be unique. A duplicate name overwrites the existing CacheSet.
name1
path
The parent path for the policy. The policy in this CacheSet is applied to all its subpaths.
oss://emr-test/dir1
cacheStrategy
The caching policy. Valid values are
DISTRIBUTEDandDHT(Distributed Hash Table). TheDHTpolicy is ideal for accelerating read-only access to small files.DISTRIBUTED
metaPolicy
The metadata caching policy. Valid values are
ALWAYSandONCE.-
ALWAYS: Does not cache metadata. All metadata operations read directly from the remote source. -
ONCE: Caches metadata. After the initial read from the remote source, subsequent metadata requests are served from the local cache.
NoteIf
cacheStrategyis set toDHT,metaPolicymust be set toONCE.ALWAYS
readPolicy
The read policy. Only
CACHE_ASIDEis currently supported, which means data is first read from the cache.CACHE_ASIDE
writePolicy
The write policy. Supported values include:
-
WRITE_AROUND: Writes data directly to the remote storage, bypassing the cache. -
CACHE_ONLY: Writes data only to the cache.NoteIf you use the
CACHE_ONLYpolicy, you must also setmetaPolicytoONCE. -
WRITE_THROUGH: Writes data to both the cache and the remote storage.
WRITE_AROUND
-
-
Run the following command to refresh the CacheSets in the JindoCache system.
jindocache -refreshCacheSet -path /path/cacheset.xmlIf the command is successful, the output includes the message
Successfully refresh cacheset !!!. For more information about JindoCache commands, see JindoCache CLI User Guide. -
Use the
listCacheSetcommand to view information about the CacheSets in the system.jindocache -listCacheSet
-
-
Configure the JindoSDK.
Configure the JindoCache implementation class for OSS-HDFS in Hadoop-Common. In the EMR console, go to the configuration page for the Hadoop-Common service, select the core-site.xml tab, and modify the configuration item. For detailed steps, see Manage configuration items.
Parameter
Description
fs.xengine
The value must be jindocache.
If you leave this parameter empty, the client does not use the cache and communicates directly with the backend.
NoteThis is a client-side configuration. You do not need to restart the JindoCache service.
After you complete these configurations, jobs that access OSS-HDFS can use the caching feature. JindoCache provides transparent caching, so you do not need to modify your jobs. When a job reads data from OSS-HDFS, the data is automatically cached in the JindoCache system. Subsequent requests for the same data are served from the cache, improving read performance.
FAQ
Configure an AccessKey for OSS-HDFS
JindoCache supports credential-free access to OSS-HDFS. However, if you need to access OSS-HDFS across different accounts, you must configure credentials, including an AccessKey ID, AccessKey secret, and an endpoint.
-
Go to the common tab for the JindoCache service.
-
Log on to the E-MapReduce console.
-
In the top navigation bar, select a region and a resource group as needed.
-
On the Clusters page, find the target cluster and click Services in the Actions column.
-
In the JindoCache service section, click Configure.
-
Click the common tab.
-
-
Add and apply the configuration items.
-
Click Add Configuration Item.
-
In the Add Configuration Item dialog box, add the following configuration items.
For detailed steps, see Manage configuration items.
NoteReplace
YYYwith the name of your OSS-HDFS bucket.Parameter
Description
jindocache.oss.bucket.YYY.accessKeyId
The AccessKey ID for OSS-HDFS access.
jindocache.oss.bucket.YYY.accessKeySecret
The AccessKey secret for OSS-HDFS access.
jindocache.oss.bucket.YYY.endpoint
The endpoint for OSS-HDFS. Example:
cn-hangzhou.oss-dls.aliyuncs.com.jindocache.oss.bucket.YYY.data.lake.storage.enable
The value must be
true.
-