source: proiecte/HadoopJUnit/hadoop-0.20.1/docs/libhdfs.html

Last change on this file was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 10.8 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<meta content="Apache Forrest" name="Generator">
6<meta name="Forrest-version" content="0.8">
7<meta name="Forrest-skin-name" content="pelt">
8<meta name="http-equiv" content="Content-Type">
9<meta name="content" content="text/html;">
10<meta name="charset" content="utf-8">
11<title>C API to HDFS: libhdfs</title>
12<link type="text/css" href="skin/basic.css" rel="stylesheet">
13<link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
14<link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
15<link type="text/css" href="skin/profile.css" rel="stylesheet">
16<script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
17<link rel="shortcut icon" href="images/favicon.ico">
18</head>
19<body onload="init()">
20<script type="text/javascript">ndeSetTextSize();</script>
21<div id="top">
22<!--+
23    |breadtrail
24    +-->
25<div class="breadtrail">
26<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://hadoop.apache.org/">Hadoop</a> &gt; <a href="http://hadoop.apache.org/core/">Core</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
27</div>
28<!--+
29    |header
30    +-->
31<div class="header">
32<!--+
33    |start group logo
34    +-->
35<div class="grouplogo">
36<a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
37</div>
38<!--+
39    |end group logo
40    +-->
41<!--+
42    |start Project Logo
43    +-->
44<div class="projectlogo">
45<a href="http://hadoop.apache.org/core/"><img class="logoImage" alt="Hadoop" src="images/core-logo.gif" title="Scalable Computing Platform"></a>
46</div>
47<!--+
48    |end Project Logo
49    +-->
50<!--+
51    |start Search
52    +-->
53<div class="searchbox">
54<form action="http://www.google.com/search" method="get" class="roundtopsmall">
55<input value="hadoop.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp; 
56                    <input name="Search" value="Search" type="submit">
57</form>
58</div>
59<!--+
60    |end search
61    +-->
62<!--+
63    |start Tabs
64    +-->
65<ul id="tabs">
66<li>
67<a class="unselected" href="http://hadoop.apache.org/core/">Project</a>
68</li>
69<li>
70<a class="unselected" href="http://wiki.apache.org/hadoop">Wiki</a>
71</li>
72<li class="current">
73<a class="selected" href="index.html">Hadoop 0.20 Documentation</a>
74</li>
75</ul>
76<!--+
77    |end Tabs
78    +-->
79</div>
80</div>
81<div id="main">
82<div id="publishedStrip">
83<!--+
84    |start Subtabs
85    +-->
86<div id="level2tabs"></div>
87<!--+
88    |end Endtabs
89    +-->
90<script type="text/javascript"><!--
91document.write("Last Published: " + document.lastModified);
92//  --></script>
93</div>
94<!--+
95    |breadtrail
96    +-->
97<div class="breadtrail">
98
99             &nbsp;
100           </div>
101<!--+
102    |start Menu, mainarea
103    +-->
104<!--+
105    |start Menu
106    +-->
107<div id="menu">
108<div onclick="SwitchMenu('menu_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Getting Started</div>
109<div id="menu_1.1" class="menuitemgroup">
110<div class="menuitem">
111<a href="index.html">Overview</a>
112</div>
113<div class="menuitem">
114<a href="quickstart.html">Quick Start</a>
115</div>
116<div class="menuitem">
117<a href="cluster_setup.html">Cluster Setup</a>
118</div>
119<div class="menuitem">
120<a href="mapred_tutorial.html">Map/Reduce Tutorial</a>
121</div>
122</div>
123<div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Programming Guides</div>
124<div id="menu_1.2" class="menuitemgroup">
125<div class="menuitem">
126<a href="commands_manual.html">Commands</a>
127</div>
128<div class="menuitem">
129<a href="distcp.html">DistCp</a>
130</div>
131<div class="menuitem">
132<a href="native_libraries.html">Native Libraries</a>
133</div>
134<div class="menuitem">
135<a href="streaming.html">Streaming</a>
136</div>
137<div class="menuitem">
138<a href="fair_scheduler.html">Fair Scheduler</a>
139</div>
140<div class="menuitem">
141<a href="capacity_scheduler.html">Capacity Scheduler</a>
142</div>
143<div class="menuitem">
144<a href="service_level_auth.html">Service Level Authorization</a>
145</div>
146<div class="menuitem">
147<a href="vaidya.html">Vaidya</a>
148</div>
149<div class="menuitem">
150<a href="hadoop_archives.html">Archives</a>
151</div>
152</div>
153<div onclick="SwitchMenu('menu_selected_1.3', 'skin/')" id="menu_selected_1.3Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">HDFS</div>
154<div id="menu_selected_1.3" class="selectedmenuitemgroup" style="display: block;">
155<div class="menuitem">
156<a href="hdfs_user_guide.html">User Guide</a>
157</div>
158<div class="menuitem">
159<a href="hdfs_design.html">Architecture</a>
160</div>
161<div class="menuitem">
162<a href="hdfs_shell.html">File System Shell Guide</a>
163</div>
164<div class="menuitem">
165<a href="hdfs_permissions_guide.html">Permissions Guide</a>
166</div>
167<div class="menuitem">
168<a href="hdfs_quota_admin_guide.html">Quotas Guide</a>
169</div>
170<div class="menuitem">
171<a href="SLG_user_guide.html">Synthetic Load Generator Guide</a>
172</div>
173<div class="menupage">
174<div class="menupagetitle">C API libhdfs</div>
175</div>
176</div>
177<div onclick="SwitchMenu('menu_1.4', 'skin/')" id="menu_1.4Title" class="menutitle">HOD</div>
178<div id="menu_1.4" class="menuitemgroup">
179<div class="menuitem">
180<a href="hod_user_guide.html">User Guide</a>
181</div>
182<div class="menuitem">
183<a href="hod_admin_guide.html">Admin Guide</a>
184</div>
185<div class="menuitem">
186<a href="hod_config_guide.html">Config Guide</a>
187</div>
188</div>
189<div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Miscellaneous</div>
190<div id="menu_1.5" class="menuitemgroup">
191<div class="menuitem">
192<a href="api/index.html">API Docs</a>
193</div>
194<div class="menuitem">
195<a href="jdiff/changes.html">API Changes</a>
196</div>
197<div class="menuitem">
198<a href="http://wiki.apache.org/hadoop/">Wiki</a>
199</div>
200<div class="menuitem">
201<a href="http://wiki.apache.org/hadoop/FAQ">FAQ</a>
202</div>
203<div class="menuitem">
204<a href="releasenotes.html">Release Notes</a>
205</div>
206<div class="menuitem">
207<a href="changes.html">Change Log</a>
208</div>
209</div>
210<div id="credit"></div>
211<div id="roundbottom">
212<img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
213<!--+
214  |alternative credits
215  +-->
216<div id="credit2"></div>
217</div>
218<!--+
219    |end Menu
220    +-->
221<!--+
222    |start content
223    +-->
224<div id="content">
225<div title="Portable Document Format" class="pdflink">
226<a class="dida" href="libhdfs.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
227        PDF</a>
228</div>
229<h1>C API to HDFS: libhdfs</h1>
230<div id="minitoc-area">
231<ul class="minitoc">
232<li>
233<a href="#C+API+to+HDFS%3A+libhdfs">C API to HDFS: libhdfs</a>
234</li>
235<li>
236<a href="#The+APIs">The APIs</a>
237</li>
238<li>
239<a href="#A+sample+program">A sample program</a>
240</li>
241<li>
242<a href="#How+to+link+with+the+library">How to link with the library</a>
243</li>
244<li>
245<a href="#Common+problems">Common problems</a>
246</li>
247<li>
248<a href="#libhdfs+is+thread+safe">libhdfs is thread safe</a>
249</li>
250</ul>
251</div>
252
253<a name="N10019"></a><a name="C+API+to+HDFS%3A+libhdfs"></a>
254<h2 class="h3">C API to HDFS: libhdfs</h2>
255<div class="section">
256<p>
257libhdfs is a JNI based C api for Hadoop's DFS. It provides C apis to a subset of the HDFS APIs to manipulate DFS files and the filesystem. libhdfs is part of the hadoop distribution and comes pre-compiled in ${HADOOP_HOME}/libhdfs/libhdfs.so .
258</p>
259</div>
260
261<a name="N10023"></a><a name="The+APIs"></a>
262<h2 class="h3">The APIs</h2>
263<div class="section">
264<p>
265The libhdfs APIs are a subset of: <a href="api/org/apache/hadoop/fs/FileSystem.html">hadoop fs APIs</a>
266</p>
267<p>
268The header file for libhdfs describes each API in detail and is available in ${HADOOP_HOME}/src/c++/libhdfs/hdfs.h
269</p>
270</div>
271
272<a name="N10034"></a><a name="A+sample+program"></a>
273<h2 class="h3">A sample program</h2>
274<div class="section">
275<pre class="code">
276#include "hdfs.h"
277
278int main(int argc, char **argv) {
279
280    hdfsFS fs = hdfsConnect("default", 0);
281    const char* writePath = "/tmp/testfile.txt";
282    hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);
283    if(!writeFile) {
284          fprintf(stderr, "Failed to open %s for writing!\n", writePath);
285          exit(-1);
286    }
287    char* buffer = "Hello, World!";
288    tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
289    if (hdfsFlush(fs, writeFile)) {
290           fprintf(stderr, "Failed to 'flush' %s\n", writePath);
291          exit(-1);
292    }
293   hdfsCloseFile(fs, writeFile);
294}
295
296</pre>
297</div>
298
299
300<a name="N1003F"></a><a name="How+to+link+with+the+library"></a>
301<h2 class="h3">How to link with the library</h2>
302<div class="section">
303<p>
304See the Makefile for hdfs_test.c in the libhdfs source directory (${HADOOP_HOME}/src/c++/libhdfs/Makefile) or something like:
305gcc above_sample.c -I${HADOOP_HOME}/src/c++/libhdfs -L${HADOOP_HOME}/libhdfs -lhdfs -o above_sample
306</p>
307</div>
308
309<a name="N10049"></a><a name="Common+problems"></a>
310<h2 class="h3">Common problems</h2>
311<div class="section">
312<p>
313The most common problem is the CLASSPATH is not set properly when calling a program that uses libhdfs. Make sure you set it to all the hadoop jars needed to run Hadoop itself. Currently, there is no way to programmatically generate the classpath, but a good bet is to include all the jar files in ${HADOOP_HOME} and ${HADOOP_HOME}/lib as well as the right configuration directory containing hdfs-site.xml
314</p>
315</div>
316
317<a name="N10053"></a><a name="libhdfs+is+thread+safe"></a>
318<h2 class="h3">libhdfs is thread safe</h2>
319<div class="section">
320<p>Concurrency and Hadoop FS "handles" - the hadoop FS implementation includes a FS handle cache which caches based on the URI of the namenode along with the user connecting. So, all calls to hdfsConnect will return the same handle but calls to hdfsConnectAsUser with different users will return different handles.  But, since HDFS client handles are completely thread safe, this has no bearing on concurrency.
321</p>
322<p>Concurrency and libhdfs/JNI - the libhdfs calls to JNI should always be creating thread local storage, so (in theory), libhdfs should be as thread safe as the underlying calls to the Hadoop FS.
323</p>
324</div>
325
326</div>
327<!--+
328    |end content
329    +-->
330<div class="clearboth">&nbsp;</div>
331</div>
332<div id="footer">
333<!--+
334    |start bottomstrip
335    +-->
336<div class="lastmodified">
337<script type="text/javascript"><!--
338document.write("Last Published: " + document.lastModified);
339//  --></script>
340</div>
341<div class="copyright">
342        Copyright &copy;
343         2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
344</div>
345<!--+
346    |end bottomstrip
347    +-->
348</div>
349</body>
350</html>
Note: See TracBrowser for help on using the repository browser.