libhdfs是hdfs的c++客户端,提供了操作hdfs的基本接口,对于典型的读写场景,使用libhdfs的流程如下:
// 建立连接
1. hdfsFS hdfsConnectAsUserNewInstance(const char* host, tPort port, const char *user , const char **groups, int groups_size )
// 打开文件
2. hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags, int bufferSize, short replication, tSize blockSize)
// 读写文件
3. tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
tSize hdfsWrite(hdfsFS fs, hdfsFile f, const void* buffer, tSize length)
// 关闭文件
4. int hdfsCloseFile(hdfsFS fs, hdfsFile file)
// 关闭连接
5. int hdfsDisconnect(hdfsFS fs)
针对0.20.1版本的源码,对主要流程做了简单的分析。
hdfsConnectAsUserNewInstance的流程如下:
1. 生成Configuration对象
2. 根据参数生成UnixUserGroupInformation
3. 通过Filesystem::get(URI, conf)方法获得DistributedFileSystem对象并返回
Filesystem::get的流程如下:
1. 根据uri获取scheme
2.