Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
hdfs-internal.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef ARROW_IO_HDFS_INTERNAL
19 #define ARROW_IO_HDFS_INTERNAL
20 
21 #include <cstddef>
22 #include <cstdint>
23 
24 #include <hdfs.h>
25 
26 #include "arrow/io/windows_compatibility.h" // IWYU pragma: keep
27 #include "arrow/util/visibility.h"
28 
29 using std::size_t;
30 
31 struct hdfsBuilder;
32 
33 namespace arrow {
34 
35 class Status;
36 
37 namespace io {
38 namespace internal {
39 
40 // NOTE(wesm): cpplint does not like use of short and other imprecise C types
41 struct LibHdfsShim {
42 #ifndef _WIN32
43  void* handle;
44 #else
45  HINSTANCE handle;
46 #endif
47 
48  hdfsBuilder* (*hdfsNewBuilder)(void);
49  void (*hdfsBuilderSetNameNode)(hdfsBuilder* bld, const char* nn);
50  void (*hdfsBuilderSetNameNodePort)(hdfsBuilder* bld, tPort port);
51  void (*hdfsBuilderSetUserName)(hdfsBuilder* bld, const char* userName);
52  void (*hdfsBuilderSetKerbTicketCachePath)(hdfsBuilder* bld,
53  const char* kerbTicketCachePath);
54  hdfsFS (*hdfsBuilderConnect)(hdfsBuilder* bld);
55 
56  int (*hdfsDisconnect)(hdfsFS fs);
57 
58  hdfsFile (*hdfsOpenFile)(hdfsFS fs, const char* path, int flags, int bufferSize,
59  short replication, tSize blocksize); // NOLINT
60 
61  int (*hdfsCloseFile)(hdfsFS fs, hdfsFile file);
62  int (*hdfsExists)(hdfsFS fs, const char* path);
63  int (*hdfsSeek)(hdfsFS fs, hdfsFile file, tOffset desiredPos);
64  tOffset (*hdfsTell)(hdfsFS fs, hdfsFile file);
65  tSize (*hdfsRead)(hdfsFS fs, hdfsFile file, void* buffer, tSize length);
66  tSize (*hdfsPread)(hdfsFS fs, hdfsFile file, tOffset position, void* buffer,
67  tSize length);
68  tSize (*hdfsWrite)(hdfsFS fs, hdfsFile file, const void* buffer, tSize length);
69  int (*hdfsFlush)(hdfsFS fs, hdfsFile file);
70  int (*hdfsAvailable)(hdfsFS fs, hdfsFile file);
71  int (*hdfsCopy)(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
72  int (*hdfsMove)(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
73  int (*hdfsDelete)(hdfsFS fs, const char* path, int recursive);
74  int (*hdfsRename)(hdfsFS fs, const char* oldPath, const char* newPath);
75  char* (*hdfsGetWorkingDirectory)(hdfsFS fs, char* buffer, size_t bufferSize);
76  int (*hdfsSetWorkingDirectory)(hdfsFS fs, const char* path);
77  int (*hdfsCreateDirectory)(hdfsFS fs, const char* path);
78  int (*hdfsSetReplication)(hdfsFS fs, const char* path, int16_t replication);
79  hdfsFileInfo* (*hdfsListDirectory)(hdfsFS fs, const char* path, int* numEntries);
80  hdfsFileInfo* (*hdfsGetPathInfo)(hdfsFS fs, const char* path);
81  void (*hdfsFreeFileInfo)(hdfsFileInfo* hdfsFileInfo, int numEntries);
82  char*** (*hdfsGetHosts)(hdfsFS fs, const char* path, tOffset start, tOffset length);
83  void (*hdfsFreeHosts)(char*** blockHosts);
84  tOffset (*hdfsGetDefaultBlockSize)(hdfsFS fs);
85  tOffset (*hdfsGetCapacity)(hdfsFS fs);
86  tOffset (*hdfsGetUsed)(hdfsFS fs);
87  int (*hdfsChown)(hdfsFS fs, const char* path, const char* owner, const char* group);
88  int (*hdfsChmod)(hdfsFS fs, const char* path, short mode); // NOLINT
89  int (*hdfsUtime)(hdfsFS fs, const char* path, tTime mtime, tTime atime);
90 
91  void Initialize() {
92  this->handle = nullptr;
93  this->hdfsNewBuilder = nullptr;
94  this->hdfsBuilderSetNameNode = nullptr;
95  this->hdfsBuilderSetNameNodePort = nullptr;
96  this->hdfsBuilderSetUserName = nullptr;
97  this->hdfsBuilderSetKerbTicketCachePath = nullptr;
98  this->hdfsBuilderConnect = nullptr;
99  this->hdfsDisconnect = nullptr;
100  this->hdfsOpenFile = nullptr;
101  this->hdfsCloseFile = nullptr;
102  this->hdfsExists = nullptr;
103  this->hdfsSeek = nullptr;
104  this->hdfsTell = nullptr;
105  this->hdfsRead = nullptr;
106  this->hdfsPread = nullptr;
107  this->hdfsWrite = nullptr;
108  this->hdfsFlush = nullptr;
109  this->hdfsAvailable = nullptr;
110  this->hdfsCopy = nullptr;
111  this->hdfsMove = nullptr;
112  this->hdfsDelete = nullptr;
113  this->hdfsRename = nullptr;
114  this->hdfsGetWorkingDirectory = nullptr;
115  this->hdfsSetWorkingDirectory = nullptr;
116  this->hdfsCreateDirectory = nullptr;
117  this->hdfsSetReplication = nullptr;
118  this->hdfsListDirectory = nullptr;
119  this->hdfsGetPathInfo = nullptr;
120  this->hdfsFreeFileInfo = nullptr;
121  this->hdfsGetHosts = nullptr;
122  this->hdfsFreeHosts = nullptr;
123  this->hdfsGetDefaultBlockSize = nullptr;
124  this->hdfsGetCapacity = nullptr;
125  this->hdfsGetUsed = nullptr;
126  this->hdfsChown = nullptr;
127  this->hdfsChmod = nullptr;
128  this->hdfsUtime = nullptr;
129  }
130 
131  hdfsBuilder* NewBuilder(void);
132 
133  void BuilderSetNameNode(hdfsBuilder* bld, const char* nn);
134 
135  void BuilderSetNameNodePort(hdfsBuilder* bld, tPort port);
136 
137  void BuilderSetUserName(hdfsBuilder* bld, const char* userName);
138 
139  void BuilderSetKerbTicketCachePath(hdfsBuilder* bld, const char* kerbTicketCachePath);
140 
141  hdfsFS BuilderConnect(hdfsBuilder* bld);
142 
143  int Disconnect(hdfsFS fs);
144 
145  hdfsFile OpenFile(hdfsFS fs, const char* path, int flags, int bufferSize,
146  short replication, tSize blocksize); // NOLINT
147 
148  int CloseFile(hdfsFS fs, hdfsFile file);
149 
150  int Exists(hdfsFS fs, const char* path);
151 
152  int Seek(hdfsFS fs, hdfsFile file, tOffset desiredPos);
153 
154  tOffset Tell(hdfsFS fs, hdfsFile file);
155 
156  tSize Read(hdfsFS fs, hdfsFile file, void* buffer, tSize length);
157 
158  bool HasPread();
159 
160  tSize Pread(hdfsFS fs, hdfsFile file, tOffset position, void* buffer, tSize length);
161 
162  tSize Write(hdfsFS fs, hdfsFile file, const void* buffer, tSize length);
163 
164  int Flush(hdfsFS fs, hdfsFile file);
165 
166  int Available(hdfsFS fs, hdfsFile file);
167 
168  int Copy(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
169 
170  int Move(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
171 
172  int Delete(hdfsFS fs, const char* path, int recursive);
173 
174  int Rename(hdfsFS fs, const char* oldPath, const char* newPath);
175 
176  char* GetWorkingDirectory(hdfsFS fs, char* buffer, size_t bufferSize);
177 
178  int SetWorkingDirectory(hdfsFS fs, const char* path);
179 
180  int MakeDirectory(hdfsFS fs, const char* path);
181 
182  int SetReplication(hdfsFS fs, const char* path, int16_t replication);
183 
184  hdfsFileInfo* ListDirectory(hdfsFS fs, const char* path, int* numEntries);
185 
186  hdfsFileInfo* GetPathInfo(hdfsFS fs, const char* path);
187 
188  void FreeFileInfo(hdfsFileInfo* hdfsFileInfo, int numEntries);
189 
190  char*** GetHosts(hdfsFS fs, const char* path, tOffset start, tOffset length);
191 
192  void FreeHosts(char*** blockHosts);
193 
194  tOffset GetDefaultBlockSize(hdfsFS fs);
195  tOffset GetCapacity(hdfsFS fs);
196 
197  tOffset GetUsed(hdfsFS fs);
198 
199  int Chown(hdfsFS fs, const char* path, const char* owner, const char* group);
200 
201  int Chmod(hdfsFS fs, const char* path, short mode); // NOLINT
202 
203  int Utime(hdfsFS fs, const char* path, tTime mtime, tTime atime);
204 
205  Status GetRequiredSymbols();
206 };
207 
208 // TODO(wesm): Remove these exports when we are linking statically
209 Status ARROW_EXPORT ConnectLibHdfs(LibHdfsShim** driver);
210 Status ARROW_EXPORT ConnectLibHdfs3(LibHdfsShim** driver);
211 
212 } // namespace internal
213 } // namespace io
214 } // namespace arrow
215 
216 #endif // ARROW_IO_HDFS_INTERNAL
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29