hdfs_sys/hdfs_2_3.rs
1//! hdfs 2.3 added zero-copy read support.
2//!
3//! The diff between hdfs.h:
4//!
5//! ```diff
6//! 38a39,40
7//! > #define ELASTIC_BYTE_BUFFER_POOL_CLASS \
8//! > "org/apache/hadoop/io/ElasticByteBufferPool"
9//! 67a70,73
10//! > struct hadoopRzOptions;
11//! >
12//! > struct hadoopRzBuffer;
13//! >
14//! 87a94
15//! > uint64_t totalZeroCopyBytesRead;
16//! 683c690,790
17//! <
18//! ---
19//! >
20//! > /**
21//! > * Allocate a zero-copy options structure.
22//! > *
23//! > * You must free all options structures allocated with this function using
24//! > * hadoopRzOptionsFree.
25//! > *
26//! > * @return A zero-copy options structure, or NULL if one could
27//! > * not be allocated. If NULL is returned, errno will
28//! > * contain the error number.
29//! > */
30//! > struct hadoopRzOptions *hadoopRzOptionsAlloc(void);
31//! >
32//! > /**
33//! > * Determine whether we should skip checksums in read0.
34//! > *
35//! > * @param opts The options structure.
36//! > * @param skip Nonzero to skip checksums sometimes; zero to always
37//! > * check them.
38//! > *
39//! > * @return 0 on success; -1 plus errno on failure.
40//! > */
41//! > int hadoopRzOptionsSetSkipChecksum(
42//! > struct hadoopRzOptions *opts, int skip);
43//! >
44//! > /**
45//! > * Set the ByteBufferPool to use with read0.
46//! > *
47//! > * @param opts The options structure.
48//! > * @param className If this is NULL, we will not use any
49//! > * ByteBufferPool. If this is non-NULL, it will be
50//! > * treated as the name of the pool class to use.
51//! > * For example, you can use
52//! > * ELASTIC_BYTE_BUFFER_POOL_CLASS.
53//! > *
54//! > * @return 0 if the ByteBufferPool class was found and
55//! > * instantiated;
56//! > * -1 plus errno otherwise.
57//! > */
58//! > int hadoopRzOptionsSetByteBufferPool(
59//! > struct hadoopRzOptions *opts, const char *className);
60//! >
61//! > /**
62//! > * Free a hadoopRzOptionsFree structure.
63//! > *
64//! > * @param opts The options structure to free.
65//! > * Any associated ByteBufferPool will also be freed.
66//! > */
67//! > void hadoopRzOptionsFree(struct hadoopRzOptions *opts);
68//! >
69//! > /**
70//! > * Perform a byte buffer read.
71//! > * If possible, this will be a zero-copy (mmap) read.
72//! > *
73//! > * @param file The file to read from.
74//! > * @param opts An options structure created by hadoopRzOptionsAlloc.
75//! > * @param maxLength The maximum length to read. We may read fewer bytes
76//! > * than this length.
77//! > *
78//! > * @return On success, returns a new hadoopRzBuffer.
79//! > * This buffer will continue to be valid and readable
80//! > * until it is released by readZeroBufferFree. Failure to
81//! > * release a buffer will lead to a memory leak.
82//! > *
83//! > * NULL plus an errno code on an error.
84//! > * errno = EOPNOTSUPP indicates that we could not do a
85//! > * zero-copy read, and there was no ByteBufferPool
86//! > * supplied.
87//! > */
88//! > struct hadoopRzBuffer* hadoopReadZero(hdfsFile file,
89//! > struct hadoopRzOptions *opts, int32_t maxLength);
90//! >
91//! > /**
92//! > * Determine the length of the buffer returned from readZero.
93//! > *
94//! > * @param buffer a buffer returned from readZero.
95//! > * @return the length of the buffer.
96//! > */
97//! > int32_t hadoopRzBufferLength(const struct hadoopRzBuffer *buffer);
98//! >
99//! > /**
100//! > * Get a pointer to the raw buffer returned from readZero.
101//! > *
102//! > * To find out how many bytes this buffer contains, call
103//! > * hadoopRzBufferLength.
104//! > *
105//! > * @param buffer a buffer returned from readZero.
106//! > * @return a pointer to the start of the buffer. This will be
107//! > * NULL when end-of-file has been reached.
108//! > */
109//! > const void *hadoopRzBufferGet(const struct hadoopRzBuffer *buffer);
110//! >
111//! > /**
112//! > * Release a buffer obtained through readZero.
113//! > *
114//! > * @param file The hdfs stream that created this buffer. This must be
115//! > * the same stream you called hadoopReadZero on.
116//! > * @param buffer The buffer to release.
117//! > */
118//! > void hadoopRzBufferFree(hdfsFile file, struct hadoopRzBuffer *buffer);
119//! >
120//! ```
121
122use std::os::raw::*;
123
124use crate::hdfsFile;
125
126pub const ELASTIC_BYTE_BUFFER_POOL_CLASS: &[u8; 43usize] =
127 b"org/apache/hadoop/io/ElasticByteBufferPool\0";
128
129#[repr(C)]
130#[derive(Debug, Copy, Clone)]
131pub struct hadoopRzOptions {
132 _unused: [u8; 0],
133}
134
135#[repr(C)]
136#[derive(Debug, Copy, Clone)]
137pub struct hadoopRzBuffer {
138 _unused: [u8; 0],
139}
140
141extern "C" {
142 pub fn hadoopRzOptionsAlloc() -> *mut hadoopRzOptions;
143 pub fn hadoopRzOptionsSetSkipChecksum(opts: *mut hadoopRzOptions, skip: c_int) -> c_int;
144 pub fn hadoopRzOptionsSetByteBufferPool(
145 opts: *mut hadoopRzOptions,
146 className: *const c_char,
147 ) -> c_int;
148 pub fn hadoopRzOptionsFree(opts: *mut hadoopRzOptions);
149 pub fn hadoopReadZero(
150 file: hdfsFile,
151 opts: *mut hadoopRzOptions,
152 maxLength: i32,
153 ) -> *mut hadoopRzBuffer;
154 pub fn hadoopRzBufferLength(buffer: *const hadoopRzBuffer) -> i32;
155 pub fn hadoopRzBufferGet(buffer: *const hadoopRzBuffer) -> *const c_void;
156 pub fn hadoopRzBufferFree(file: hdfsFile, buffer: *mut hadoopRzBuffer);
157}