[ 
https://issues.apache.org/jira/browse/HDFS-5450?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13817866#comment-13817866
 ] 

Colin Patrick McCabe commented on HDFS-5450:
--------------------------------------------

I was thinking about a libhdfs API like this:

{code}
    struct hdfsBlockLocs;
    struct hdfsBlockLoc;

    /** 
     * hdfsGetFileBlockLocs - Get locations where a particular block
     * (determined by position and blocksize) of a file is stored. The last
     * element in the array is NULL. Due to replication, a single block could be
     * present on multiple hosts.
     *
     * @param fs The configured filesystem handle.
     * @param path The path of the file. 
     * @param start The start of the block.
     * @param length The length of the block.
     *
     * @return The array of block locations on success.
     *         This must be freed with hdfsFreeBlockLocs.
     *         NULL on error.  Errno will be set on error.
     */
    struct hdfsBlockLocs *hdfsGetFileBlockLocs(hdfsFS fs,
            const char* path, tOffset start, tOffset length);

    /** 
     * hdfsFreeBlockLocs - Free an array of block locations.
     *
     * @param arr The array of block locations.
     */
    void hdfsFreeBlockLocs(struct hdfsBlockLocs *arr);

    /** 
     * hdfsNumBlockLocs - Get the size of an array of block locations.
     *
     * @return The size of the array.  May be 0.
     */
    int hdfsNumBlockLocs(const struct hdfsBlockLocs *arr);

    /** 
     * hdfsGetBlockLoc - Get a block location from an array of block
     *                        locations.
     *
     * @param arr The array of block locations.
     * @param idx The entry to get.
     *
     * @return The entry.
     */
    const struct hdfsBlockLoc *hdfsGetBlockLoc(
                        const struct hdfsBlockLocs *arr, int idx);

    /** 
     * hdfsBlockLocGetHosts - Get the datanode hostnames at a
     *                             particular block location.
     *
     * @param loc The block location.
     *
     * @return A NULL-terminated array of hostnames.  This must be freed with
     *             hdfsFreeHosts.  This may be empty.
     *         NULL on error.  errno will be set on error.
     */
    char ***hdfsBlockLocGetHosts(const struct hdfsBlockLoc *loc);

    /** 
     * hdfsBlockLocGetCachedHosts - Get the cached datanode hostnames at a
     *                                   particular block location.
     *
     * @param loc The block location.
     *
     * @return A NULL-terminated array of hostnames.  This must be freed with
     *             hdfsFreeHosts.  This may be empty.
     *         NULL on error.  errno will be set on error.
     */
    char ***hdfsBlockLocGetCachedHosts(const struct hdfsBlockLoc *loc);
{code}

This would be a new addition, deprecating the existing {{hdfsGetHosts}} API.  
(However, we should leave the old API in for compatibility.)

The advantage of the new API is that using opaque data structures, we can add 
new fields later if we want to expose the other things in {{BlockLocation}}.  
We also don't have to do the work of converting everything from JNI "up front" 
if only one block location in the array is accessed.  Finally, it's easier to 
free the whole array if the array itself is represented by a single C object.

> better API for getting the cached blocks locations
> --------------------------------------------------
>
>                 Key: HDFS-5450
>                 URL: https://issues.apache.org/jira/browse/HDFS-5450
>             Project: Hadoop HDFS
>          Issue Type: Sub-task
>          Components: hdfs-client
>    Affects Versions: 3.0.0
>            Reporter: Colin Patrick McCabe
>            Assignee: Andrew Wang
>            Priority: Minor
>
> Currently, we have to downcast the {{BlockLocation}] to {{HdfsBlockLocation}} 
> to get information about whether a replica is cached.  We should have this 
> information in {{BlockLocation}} instead.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to