hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ruyue Ma (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HDFS-923) libhdfs hdfs_read example uses hdfsRead wrongly
Date Tue, 26 Jan 2010 11:16:34 GMT

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

Ruyue Ma commented on HDFS-923:
-------------------------------

Our modification for hdfs.c is: 

{noformat}

tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
{
    // JAVA EQUIVALENT:
    //  byte [] bR = new byte[length];
    //  fis.read(bR);

    //Get the JNIEnv* corresponding to current thread
    JNIEnv* env = getJNIEnv();
    if (env == NULL) {
      errno = EINTERNAL;
      return -1;
    }

    //Parameters
    jobject jInputStream = (jobject)(f ? f->file : NULL);

    jbyteArray jbRarray;
    jint noReadBytes = 0;
    jvalue jVal;
    jthrowable jExc = NULL;

    int hasReadBytes = 0;

    //Sanity check
    if (!f || f->type == UNINITIALIZED) {
        errno = EBADF;
        return -1;
    }

    //Error checking... make sure that this file is 'readable'
    if (f->type != INPUT) {
        fprintf(stderr, "Cannot read from a non-InputStream object!\n");
        errno = EINVAL;
        return -1;
    }

     /////////////////////////////////////////////////////////////////////////////////////////////////
    // > OUR MODIFICATION
    jbRarray = (*env)->NewByteArray(env, length);
    while (hasReadBytes < length) {
        if (invokeMethod(env, &jVal, &jExc, INSTANCE, jInputStream, HADOOP_ISTRM,
                         "read", JMETHOD3("[B", "I", "I", "I") , jbRarray, hasReadBytes, length-hasReadBytes)
!= 0) {
            errno = errnoFromException(jExc, env, "org.apache.hadoop.fs."
                                       "FSDataInputStream::read");
            noReadBytes = -1;
        }
        else {
            noReadBytes = jVal.i;
            if (noReadBytes >= 0) {
                (*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer+hasReadBytes);
                hasReadBytes += noReadBytes;
            }  else {
                //This is a valid case: there aren't any bytes left to read!
                break;
            }
            errno = 0;
        }

     // > OUR MODIFICATION
    ///////////////////////////////////////////////////////////////////////////////////////

    }

    destroyLocalReference(env, jbRarray);
    return hasReadBytes;
}


{noformat}

> libhdfs hdfs_read example uses hdfsRead wrongly
> -----------------------------------------------
>
>                 Key: HDFS-923
>                 URL: https://issues.apache.org/jira/browse/HDFS-923
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: contrib/libhdfs
>    Affects Versions: 0.20.1
>            Reporter: Ruyue Ma
>            Assignee: Ruyue Ma
>             Fix For: 0.21.0
>
>
> In the examples of libhdfs,  the hdfs_read.c uses hdfsRead wrongly. 
> {noformat}
>     // read from the file
>     tSize curSize = bufferSize;
>     for (; curSize == bufferSize;) {
>         curSize = hdfsRead(fs, readFile, (void*)buffer, curSize);
>     }
> {noformat} 
> the condition curSize == bufferSize has problem.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message