Before you start developing applications on MapR’s Converged Data Platform, consider how you will get the data onto the
platform, the format it will be stored in, the type of processing or modeling that is required, and how the data will
be accessed.

The APIs are defined in hdfs.h. The file fcntl.h defines
the file-access flags.

The application performs the actions that are described in the following sections.

Takes a filename, file size, and buffer size as input

When you launch the application, provide the path and name of the file, the size of the
file, and the number of bytes to write.

hdfs_write <filename> <filesize> <buffersize>

Sets an RPC timeout

hdfsSetRpcTimeout() is specific to the libMapRClient
version of libhdfs and takes a value that is specified in seconds. The
default is 99 seconds. If you change this value, set it either to 0 (which eliminates
timeouts) or to a value greater than 30.

Connects to a filesystem, using an API that is supported in the hadoop-2.x version
of libhdfs

The application tries to connect to the first MapR Filesystem cluster that is specified in the
mapr-clusters.conf file in the MAPR_HOME/conf directory
on the client. After connecting to the filesystem, the application returns a handle to the
filesystem.

The application stores the values of the arguments in a character array and in two
variables of type tSize. This datatype is defined in
hdfs.h and is a fixed-width, signed 32-byte integer type for storing the
size of data for read or write operations.

The application opens the specified file, passing the following values to the
hdfsOpenFile() function:

The handle to the filesystem

The name of the file, which you supplied when you launched the application.

A flag to indicate the mode in which to open the file. In this case, the flag is
O_WRONLY. This flag creates the file if the file does not exist and
truncates the file if the file does exist. If the file existed and you wanted to preserve
the content of the file, you would specify O_WRONLY | O_APPEND for flag.
These flags are defined in the header file fcntl.h.

The default chunk size for the directory in which the file is either located or will be
created. This value is specified by the 0 in the last parameter.

Although there are two other parameters in the hdfsOpenFile() function –
the fourth and fifth, the libMapRClient version of libhdfs
ignores them.

This function writes the content of the buffer to the file, starting at the specified
offset. If the file already exists, the file is first truncated to this offset before the
write operation begins. In this case, the specified offset is 0.

The difference between this function and the previous function is that, before writing, it
calls hdfsSeek() to move to the specified offset in the file.