hdfs.c 之解析

hdfsRead
readDirect
csharp 复制代码
tSize readDirect(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
{
    // JAVA EQUIVALENT:
    //  ByteBuffer buf = ByteBuffer.allocateDirect(length) // wraps C buffer
    //  fis.read(buf);

    jobject jInputStream;
    jvalue jVal;
    jthrowable jthr;
    jobject bb;

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

    if (readPrepare(env, fs, f, &jInputStream) == -1) {
      return -1;
    }

    //Read the requisite bytes
    bb = (*env)->NewDirectByteBuffer(env, buffer, length);
    if (bb == NULL) {
        errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
            "readDirect: NewDirectByteBuffer");
        return -1;
    }

    jthr = invokeMethod(env, &jVal, INSTANCE, jInputStream,
            JC_FS_DATA_INPUT_STREAM, "read",
            "(Ljava/nio/ByteBuffer;)I", bb);
    destroyLocalReference(env, bb);
    if (jthr) {
        errno = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "readDirect: FSDataInputStream#read");
        return -1;
    }
    // Reached EOF, return 0
    if (jVal.i < 0) {
        return 0;
    }
    // 0 bytes read, return error
    if (jVal.i == 0) {
        errno = EINTR;
        return -1;
    }
    return jVal.i;
}
csharp 复制代码
org.apache.hadoop.fs.FSDataInputStream

public int read(java.nio.ByteBuffer buf) throws IOException

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSDataInputStream.java

csharp 复制代码
  @Override
  public int read(ByteBuffer buf) throws IOException {
    if (in instanceof ByteBufferReadable) {
      return ((ByteBufferReadable)in).read(buf);
    }

    throw new UnsupportedOperationException("Byte-buffer read unsupported " +
            "by " + in.getClass().getCanonicalName());
  }

https://github.com/apache/hadoop/blame/rel/release-3.3.3/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c

csharp 复制代码
    if ((flags & O_WRONLY) == 0) {
        // Check the StreamCapabilities of jFile to see if we can do direct
        // reads
        if (hdfsHasStreamCapability(jFile, "in:readbytebuffer")) {
            file->flags |= HDFS_FILE_SUPPORTS_DIRECT_READ;
        }

        // Check the StreamCapabilities of jFile to see if we can do direct
        // preads
        if (hdfsHasStreamCapability(jFile, "in:preadbytebuffer")) {
            file->flags |= HDFS_FILE_SUPPORTS_DIRECT_PREAD;
        }
    }
    ret = 0;

https://github.com/apache/hadoop/blame/rel/release-3.2.0/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c

csharp 复制代码
    if ((flags & O_WRONLY) == 0) {
        // Try a test read to see if we can do direct reads
        char buf;
        if (readDirect(fs, file, &buf, 0) == 0) {
            // Success - 0-byte read should return 0
            file->flags |= HDFS_FILE_SUPPORTS_DIRECT_READ;
        } else if (errno != ENOTSUP) {
            // Unexpected error. Clear it, don't set the direct flag.
            fprintf(stderr,
                  "hdfsOpenFile(%s): WARN: Unexpected error %d when testing "
                  "for direct read compatibility\n", path, errno);
        }
    }
    ret = 0;

https://github.com/apache/hadoop/blob/rel/release-3.2.0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/StreamCapabilities.java

https://github.com/apache/hadoop/blob/rel/release-3.3.0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/StreamCapabilities.java

csharp 复制代码
  /**
   * Stream read(ByteBuffer) capability implemented by
   * {@link ByteBufferReadable#read(java.nio.ByteBuffer)}.
   */
  String READBYTEBUFFER = "in:readbytebuffer";

  /**
   * Stream read(long, ByteBuffer) capability implemented by
   * {@link ByteBufferPositionedReadable#read(long, java.nio.ByteBuffer)}.
   */
  String PREADBYTEBUFFER = "in:preadbytebuffer";
查看进程时使用了哪些动态库
csharp 复制代码
3747188 Jps
[root@hadoop00 test]#
[root@hadoop00 test]#
[root@hadoop00 test]# lsof -p 3745282 | grep hdfs
java    3745282 root  mem       REG                8,4     307760 1282588866 /usr/local/hadoop-3.3.3/lib/native/libhdfs.so.0.0.0
java    3745282 root  mem       REG                8,4    5023516 1623503278 /usr/local/spark-3.1.1-bin-hadoop3.2/jars/hadoop-hdfs-client-3.2.0.jar
java    3745282 root  279r      REG                8,4    5023516 1623503278 /usr/local/spark-3.1.1-bin-hadoop3.2/jars/hadoop-hdfs-client-3.2.0.jar
相关推荐
Zwawa4 小时前
两根线怎么挂住一堆设备:I2C 协议原理
c语言·单片机·嵌入式
武子康6 小时前
h3.c 的两个权重槽,怎样把内存压力换成 SSD 等待
c语言·人工智能·agent
Francek Chen11 小时前
【大数据处理与分析】数据仓库Hive:09 Hive 编程实践
大数据·数据仓库·hive·hadoop·sql
§ꦿCFོ༉1 天前
嵌入式八股—C语言入门学习(一)
c语言·编程语言·嵌入式八股文
沐晓时光1 天前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
智者知已应修善业1 天前
【51单片机实现从下到上,从上到下,从中间到两边,两边到中间】2024-10-23
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
布莱克6052 天前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
揽星河..2 天前
【C语言】底层程序设计
c语言·开发语言
揽星河..2 天前
【C语言】结构体
c语言·开发语言
唐青枫2 天前
C 语言 malloc() 详解与实战 Demo
c语言