1 | /******************************************************************** |
---|---|
2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
3 | * All rights reserved. |
4 | * |
5 | * Author: Zhanwei Wang |
6 | ********************************************************************/ |
7 | /******************************************************************** |
8 | * 2014 - |
9 | * open source under Apache License Version 2.0 |
10 | ********************************************************************/ |
11 | /** |
12 | * Licensed to the Apache Software Foundation (ASF) under one |
13 | * or more contributor license agreements. See the NOTICE file |
14 | * distributed with this work for additional information |
15 | * regarding copyright ownership. The ASF licenses this file |
16 | * to you under the Apache License, Version 2.0 (the |
17 | * "License"); you may not use this file except in compliance |
18 | * with the License. You may obtain a copy of the License at |
19 | * |
20 | * http://www.apache.org/licenses/LICENSE-2.0 |
21 | * |
22 | * Unless required by applicable law or agreed to in writing, software |
23 | * distributed under the License is distributed on an "AS IS" BASIS, |
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
25 | * See the License for the specific language governing permissions and |
26 | * limitations under the License. |
27 | */ |
28 | #ifndef _HDFS_LIBHDFS3_COMMON_SESSIONCONFIG_H_ |
29 | #define _HDFS_LIBHDFS3_COMMON_SESSIONCONFIG_H_ |
30 | |
31 | #include "Exception.h" |
32 | #include "ExceptionInternal.h" |
33 | #include "Function.h" |
34 | #include "Logger.h" |
35 | #include "XmlConfig.h" |
36 | |
37 | #include <cassert> |
38 | #include <vector> |
39 | |
40 | namespace Hdfs { |
41 | namespace Internal { |
42 | |
43 | template<typename T> |
44 | struct ConfigDefault { |
45 | T * variable; //variable this configure item should be bound to. |
46 | const char * key; //configure key. |
47 | T value; //default value. |
48 | function<void(const char *, T const &)> check; //the function to validate the value. |
49 | }; |
50 | |
51 | class SessionConfig { |
52 | public: |
53 | |
54 | SessionConfig(const Config & conf); |
55 | |
56 | /* |
57 | * rpc configure |
58 | */ |
59 | |
60 | int32_t getRpcConnectTimeout() const { |
61 | return rpcConnectTimeout; |
62 | } |
63 | |
64 | int32_t getRpcMaxIdleTime() const { |
65 | return rpcMaxIdleTime; |
66 | } |
67 | |
68 | int32_t getRpcMaxRetryOnConnect() const { |
69 | return rpcMaxRetryOnConnect; |
70 | } |
71 | |
72 | void setRpcMaxRetryOnConnect(int32_t rpcMaxRetryOnConnect) { |
73 | this->rpcMaxRetryOnConnect = rpcMaxRetryOnConnect; |
74 | } |
75 | |
76 | int32_t getRpcPingTimeout() const { |
77 | return rpcPingTimeout; |
78 | } |
79 | |
80 | int32_t getRpcReadTimeout() const { |
81 | return rpcReadTimeout; |
82 | } |
83 | |
84 | bool isRpcTcpNoDelay() const { |
85 | return rpcTcpNoDelay; |
86 | } |
87 | |
88 | int32_t getRpcWriteTimeout() const { |
89 | return rpcWriteTimeout; |
90 | } |
91 | |
92 | /* |
93 | * FileSystem configure |
94 | */ |
95 | const std::string & getDefaultUri() const { |
96 | return defaultUri; |
97 | } |
98 | |
99 | int32_t getDefaultReplica() const { |
100 | return defaultReplica; |
101 | } |
102 | |
103 | int64_t getDefaultBlockSize() const { |
104 | return defaultBlockSize; |
105 | } |
106 | |
107 | /* |
108 | * InputStream configure |
109 | */ |
110 | int32_t getLocalReadBufferSize() const { |
111 | return localReadBufferSize; |
112 | } |
113 | |
114 | int32_t getInputReadTimeout() const { |
115 | return inputReadTimeout; |
116 | } |
117 | |
118 | int32_t getInputWriteTimeout() const { |
119 | return inputWriteTimeout; |
120 | } |
121 | |
122 | int32_t getInputConnTimeout() const { |
123 | return inputConnTimeout; |
124 | } |
125 | |
126 | int32_t getPrefetchSize() const { |
127 | return prefetchSize; |
128 | } |
129 | |
130 | bool isReadFromLocal() const { |
131 | return readFromLocal; |
132 | } |
133 | |
134 | int32_t getMaxGetBlockInfoRetry() const { |
135 | return maxGetBlockInfoRetry; |
136 | } |
137 | |
138 | int32_t getMaxLocalBlockInfoCacheSize() const { |
139 | return maxLocalBlockInfoCacheSize; |
140 | } |
141 | |
142 | /* |
143 | * OutputStream configure |
144 | */ |
145 | int32_t getDefaultChunkSize() const { |
146 | return chunkSize; |
147 | } |
148 | |
149 | int32_t getDefaultPacketSize() const { |
150 | if (packetSize % chunkSize != 0) { |
151 | THROW(HdfsConfigInvalid, |
152 | "output.default.packetsize should be larger than 0 " |
153 | "and be the multiple of output.default.chunksize."); |
154 | } |
155 | |
156 | return packetSize; |
157 | } |
158 | |
159 | int32_t getBlockWriteRetry() const { |
160 | return blockWriteRetry; |
161 | } |
162 | |
163 | int32_t getOutputConnTimeout() const { |
164 | return outputConnTimeout; |
165 | } |
166 | |
167 | int32_t getOutputReadTimeout() const { |
168 | return outputReadTimeout; |
169 | } |
170 | |
171 | int32_t getOutputWriteTimeout() const { |
172 | return outputWriteTimeout; |
173 | } |
174 | |
175 | bool canAddDatanode() const { |
176 | return addDatanode; |
177 | } |
178 | |
179 | int32_t getHeartBeatInterval() const { |
180 | return heartBeatInterval; |
181 | } |
182 | |
183 | int32_t getRpcMaxHaRetry() const { |
184 | return rpcMaxHARetry; |
185 | } |
186 | |
187 | void setRpcMaxHaRetry(int32_t rpcMaxHaRetry) { |
188 | rpcMaxHARetry = rpcMaxHaRetry; |
189 | } |
190 | |
191 | const std::string & getRpcAuthMethod() const { |
192 | return rpcAuthMethod; |
193 | } |
194 | |
195 | void setRpcAuthMethod(const std::string & rpcAuthMethod) { |
196 | this->rpcAuthMethod = rpcAuthMethod; |
197 | } |
198 | |
199 | const std::string & getKerberosCachePath() const { |
200 | return kerberosCachePath; |
201 | } |
202 | |
203 | void setKerberosCachePath(const std::string & kerberosCachePath) { |
204 | this->kerberosCachePath = kerberosCachePath; |
205 | } |
206 | |
207 | int32_t getRpcSocketLingerTimeout() const { |
208 | return rpcSocketLingerTimeout; |
209 | } |
210 | |
211 | void setRpcSocketLingerTimeout(int32_t rpcSocketLingerTimeout) { |
212 | this->rpcSocketLingerTimeout = rpcSocketLingerTimeout; |
213 | } |
214 | |
215 | LogSeverity getLogSeverity() const { |
216 | for (size_t i = FATAL; i < sizeof(SeverityName) / sizeof(SeverityName[1]); |
217 | ++i) { |
218 | if (logSeverity == SeverityName[i]) { |
219 | return static_cast<LogSeverity>(i); |
220 | } |
221 | } |
222 | |
223 | return DEFAULT_LOG_LEVEL; |
224 | } |
225 | |
226 | void setLogSeverity(const std::string & logSeverityLevel) { |
227 | this->logSeverity = logSeverityLevel; |
228 | } |
229 | |
230 | int32_t getPacketPoolSize() const { |
231 | return packetPoolSize; |
232 | } |
233 | |
234 | void setPacketPoolSize(int32_t packetPoolSize) { |
235 | this->packetPoolSize = packetPoolSize; |
236 | } |
237 | |
238 | int32_t getCloseFileTimeout() const { |
239 | return closeFileTimeout; |
240 | } |
241 | |
242 | void setCloseFileTimeout(int32_t closeFileTimeout) { |
243 | this->closeFileTimeout = closeFileTimeout; |
244 | } |
245 | |
246 | int32_t getRpcTimeout() const { |
247 | return rpcTimeout; |
248 | } |
249 | |
250 | void setRpcTimeout(int32_t rpcTimeout) { |
251 | this->rpcTimeout = rpcTimeout; |
252 | } |
253 | |
254 | bool doesNotRetryAnotherNode() const { |
255 | return notRetryAnotherNode; |
256 | } |
257 | |
258 | void setIFNotRetryAnotherNode(bool notRetryAnotherNode) { |
259 | this->notRetryAnotherNode = notRetryAnotherNode; |
260 | } |
261 | |
262 | int32_t getMaxReadBlockRetry() const { |
263 | return maxReadBlockRetry; |
264 | } |
265 | |
266 | void setMaxReadBlockRetry(int32_t maxReadBlockRetry) { |
267 | this->maxReadBlockRetry = maxReadBlockRetry; |
268 | } |
269 | |
270 | bool doUseMappedFile() const { |
271 | return useMappedFile; |
272 | } |
273 | |
274 | void setUseMappedFile(bool useMappedFile) { |
275 | this->useMappedFile = useMappedFile; |
276 | } |
277 | |
278 | bool isLegacyLocalBlockReader() const { |
279 | return legacyLocalBlockReader; |
280 | } |
281 | |
282 | void setLegacyLocalBlockReader(bool legacyLocalBlockReader) { |
283 | this->legacyLocalBlockReader = legacyLocalBlockReader; |
284 | } |
285 | |
286 | const std::string& getDomainSocketPath() const { |
287 | return domainSocketPath; |
288 | } |
289 | |
290 | void setDomainSocketPath(const std::string& domainSocketPath) { |
291 | this->domainSocketPath = domainSocketPath; |
292 | } |
293 | |
294 | int32_t getMaxFileDescriptorCacheSize() const { |
295 | return maxFileDescriptorCacheSize; |
296 | } |
297 | |
298 | void setMaxFileDescriptorCacheSize(int32_t maxFileDescriptorCacheSize) { |
299 | this->maxFileDescriptorCacheSize = maxFileDescriptorCacheSize; |
300 | } |
301 | |
302 | int32_t getSocketCacheExpiry() const { |
303 | return socketCacheExpiry; |
304 | } |
305 | |
306 | int32_t getSocketCacheCapacity() const { |
307 | return socketCacheCapacity; |
308 | } |
309 | |
310 | public: |
311 | /* |
312 | * rpc configure |
313 | */ |
314 | int32_t rpcMaxIdleTime; |
315 | int32_t rpcPingTimeout; |
316 | int32_t rpcConnectTimeout; |
317 | int32_t rpcReadTimeout; |
318 | int32_t rpcWriteTimeout; |
319 | int32_t rpcMaxRetryOnConnect; |
320 | int32_t rpcMaxHARetry; |
321 | int32_t rpcSocketLingerTimeout; |
322 | int32_t rpcTimeout; |
323 | bool rpcTcpNoDelay; |
324 | std::string rpcAuthMethod; |
325 | |
326 | /* |
327 | * FileSystem configure |
328 | */ |
329 | std::string defaultUri; |
330 | std::string kerberosCachePath; |
331 | std::string logSeverity; |
332 | int32_t defaultReplica; |
333 | int64_t defaultBlockSize; |
334 | |
335 | /* |
336 | * InputStream configure |
337 | */ |
338 | bool useMappedFile; |
339 | bool readFromLocal; |
340 | bool notRetryAnotherNode; |
341 | bool legacyLocalBlockReader; |
342 | int32_t inputConnTimeout; |
343 | int32_t inputReadTimeout; |
344 | int32_t inputWriteTimeout; |
345 | int32_t localReadBufferSize; |
346 | int32_t maxFileDescriptorCacheSize; |
347 | int32_t maxGetBlockInfoRetry; |
348 | int32_t maxLocalBlockInfoCacheSize; |
349 | int32_t maxReadBlockRetry; |
350 | int32_t prefetchSize; |
351 | int32_t socketCacheCapacity; |
352 | int32_t socketCacheExpiry; |
353 | std::string domainSocketPath; |
354 | |
355 | /* |
356 | * OutputStream configure |
357 | */ |
358 | bool addDatanode; |
359 | int32_t chunkSize; |
360 | int32_t packetSize; |
361 | int32_t blockWriteRetry; //retry on block not replicated yet. |
362 | int32_t outputConnTimeout; |
363 | int32_t outputReadTimeout; |
364 | int32_t outputWriteTimeout; |
365 | int32_t packetPoolSize; |
366 | int32_t heartBeatInterval; |
367 | int32_t closeFileTimeout; |
368 | |
369 | }; |
370 | |
371 | } |
372 | } |
373 | |
374 | #endif /* _HDFS_LIBHDFS3_COMMON_SESSIONCONFIG_H_ */ |
375 |