HDFS Interfaces

Outline

Hadoop Cluster vs. Pseudo-Distributed Hadoop

  • A Hadoop cluster is deployed in a cluster of computer nodes
    • As Hadoop is developed in Java, all Hadoop services sit on Java Virtual Machines running on the cluster nodes
  • Hadoop provides a pseudo-distributed mode on a single machine
    • All Java Virtual Machines for necessary Hadoop services are running on a single machine
    • In our case this machine is a Virtual Machine running under Ubuntu 14.04 or 22.04
  • HDFS provides the following interfaces to read, write, interrogate, and manage the filesystem
    • The file system shell (Command-Line Interface): hadoop fs or hdfs dfs
    • Hadoop Filesystem Java API
    • Hadoop simple Web User Interface
    • Snakebite pure Python HDFS client library
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

HDFS Interfaces

Outline

Shell Interface to HDFS

  • Commands are provided in the shell Bash
  • Moving to Hadoop's home directory
      $ cd $HADOOP_HOME
  • You will mostly use programs in the bin and shell scripts in sbin folders, and use jar files in the share folder
  • Starting all Hadoop processes
      $ ./sbin/start-all.sh
  • Hadoop is running properly only if the above services are running
      $ jps
      28530 SecondaryNameNode
      11188 NodeManager
      28133 NameNode
      28311 DataNode
      10845 ResourceManager
      3542 Jps
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Shell Interface to HDFS

  • Create a HDFS user account (already created in a virtual machine used by us)
      $ bin/hdfs dfs -mkdir -p /user/bigdata
  • Create a folder input in a home folder
      $ hdfs dfs -mkdir input
  • View the folders in Hadoop home
      $ hdfs dfs -ls
      Found 1 item
      drwxr-xr-x - bigdata supergroup 0 2017-07-17 16:33 input
  • What is a path to Hadoop home folder ?
      $ hdfs dfs -ls /user/bigdata
      Found 1 item
      drwxr-xr-x - bigdata supergroup 0 2017-07-17 16:33 /user/bigdata/input
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Shell Interface to HDFS

  • Upload a file to HDFS to input folder
      $ hdfs dfs -put README.txt input
  • Check the contents of input folder
      $ hdfs dfs -put README.txt input
      $ bin/hdfs dfs -ls input
      -rw-r--r-- 1 bigdata supergroup 1494 2017-07-12 17:53 input/README.txt
  • Read a file located in HDFS
      $ bin/hdfs dfs -cat input/README.txt
      < Contents of README.txt is displayed here >
  • Get help on all commands of shell interface to HDFS
      $ bin/hdfs dfs -help
      < A long list of commands of shell interface to HDFS displayed here >
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Shell Interface to HDFS

  • The path in HDFS is represented as a URI with the prefix hdfs://
  • For example
       
      hdfs://<hostname>:<port>/user/bigdata/input
  • refers to the input folder in HDFS under the user of bigdata
       
      hdfs ://<hostname>:<port>/user/bigdata/input/README.txt
  • refers to the file README.txt in the above input directory in HDFS
  • When interacting with HDFS interface in the default setting, one can omitt IP, port, and user, and simply mention the directory or file
  • Thus, the full-spelling of hdfs dfs -ls input is
      hdfs dfs -ls hdfs://<hostname>:<port>/user/bigdata/input
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Shell Interface to HDFS

  • Some of frequently used commands of shell interface to HDFS
       
      Command          Description
      -put             Upload a file (or files) from the local filesystem to HDFS
      -mkdir           Create a directory in HDFS
      -ls              List the files in a directory in HDFS
      -cat             Read the content of a file (or files) in HDFS
      -copyFromLocal   Copy a file from the local filesystem to HDFS (similar to
                       put)
      -copyToLocal     Copy a file (or files) from HDFS to the local filesystem
      -rm              Delete a file (or files) in HDFS
      -rm -r           Delete a directory in HDFS
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

HDFS Interfaces

Outline

Web Interface of HDFS

    • ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Web Interface of HDFS

    • ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

HDFS Interfaces

Outline

Python interface to HDFS

  • Snakebite is a Python package, created by Spotify, that allows for HDFS to be accessed programmatically from Python applications
  • Protocol buffer messages are used to communicate directly with the NameNode
  • Snakebite package also includes its own command-line interface to HDFS
  • A sample application of Snakebite that lists the contents of /user folder in HDFS
       
      #!/usr/bin/env python3
      	      
      from snakebite.client import Client
      	      
      client = Client('localhost', 9000)
      for x in client.ls(['/user']):
            print(x)
       
      {'file_type': 'd', 'permission': 493, 'path': '/user/bigdata', 'length': 0, 'owner': 'bigdata',
      'group': 'supergroup', 'block_replication': 0, 'modification_time': 1711847570566, 'access_time': 0,
      'blocksize': 0}
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • A sample application of Snakebite that lists the parameters of a file NOTICE.txt located at /user in HDFS
       
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      for x in client.ls(['/user/NOTICE.txt']):
            print(x)
       
      {'file_type': 'f', 'permission': 420, 'path': '/user/NOTICE.txt', 'length': 1541, 'owner': 'bigdata',
      'group': 'supergroup', 'block_replication': 1, 'modification_time': 1711864616929,
      'access_time': 1711864616715, 'blocksize': 134217728}
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • The sample applications of Snakebite that list the names and type of folders/files located at the end of a path
       
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      for x in client.ls(['/user/NOTICE.txt']):
            print(x['path'], x['file_type'])
      /user/NOTICE.txt f
       
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      for x in client.ls(['/user/NOTICE.txt',/]):
            print(x['path'], x['file_type'])
       
      /user/NOTICE.txt f
      /user d
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • A sample application of Snakebite that copies a file from HDFS to a local file system
       
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      for x in client.copyToLocal(['/user/NOTICE.txt'],'.'):
            print(x)
       
      {'path': '/home/bigdata/NOTICE.txt', 'result': True, 'error': '', 'source_path': '/user/NOTICE.txt'}
        
      bigdata@bigdata-VirtualBox:~$ ls
       
      Desktop    Downloads  hadoop-3.3.6  NOTICE.txt  Public     snap       UMLet15-1
      Documents  ex.py      Music         Pictures    shrink.sh  Templates  Videos
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • A sample application of Snakebite that lists a file located in HDFS
       
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      for file in client.cat(['/user/NOTICE.txt']):
            for y in file:
      	  print(y)
       
      b"Apache Hadoop\nCopyright 2006 and onwards The Apache Software Foundation.\n\nThis product includes
      software developed at\nThe Apache Software Foundation (https://url.au.m.mimecastprotect.com/s/2HlmC5QPyyHGPEZzhyiQhk89x1?domain=apache.org).\n\nExport Control Notice
      \n---------------------\n\nThis distribution ... "
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • A sample application of Snakebite that lists several files located in HDFS
      #!/usr/bin/env python3
      
      from snakebite.client import Client
      
      client = Client('localhost', 9000)
      
      files = []
      for x in client.ls(['/user/bigdata/NOTICE.txt']):
              if x['file_type'] == 'f':
                      files.append(x['path'])
      
      for cat in client.text(files):
            print(cat)
       
      b'\n                      Apache License\n                Version 2.0, January 2004\n
      https://url.au.m.mimecastprotect.com/s/Bj0mC6XQ88iK6zrgT5sph5H-n2?domain=apache.org\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n
      1. Definitions.\n\n      "License" shall mean ... "
       
      b"Apache Hadoop\nCopyright 2006 and onwards The Apache Software Foundation.\n\n
      This product includes software developed at\nThe Apache Software Foundation (https://url.au.m.mimecastprotect.com/s/2HlmC5QPyyHGPEZzhyiQhk89x1?domain=apache.org/).
      \n\nExport Control Notice\n----------------\n\nThis distribution includes cryptographic software. ..."
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • A sample application that reads and filters a file located in HDFS
  • The application uses Hadoop Streaming technique to process the files located in HDFS
  • Assume that a file numbers.txt contains a sequence of numbers
       
      23
      56
      78
      23
      12
      ...
  • The file is uploaded to HDFS
       
      hdfs dfs -put ~/numbers.txt /user
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • We would like to filter out all numbers greater than 50
       
      #!/usr/bin/env python3
      
      import sys
      
      for number in sys.stdin:
            if int(number) > 50:
                        print(int(number))
  • The file in HDFS is processed with Hadoop Streaming feature
       
      $HADOOP_HOME/bin/hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-3.3.6.jar \
       -D mapred.reduce.tasks=0 \
       -input /user/numbers.txt \
       -output /user/output     \
       -mapper ./filter.py
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Python interface to HDFS

  • The results are retrieved from HDFS
       
      hdfs dfs -ls /user/output
       
      Found 2 items
      -rw-r--r--   1 bigdata supergroup          0 2024-04-01 20:09 /user/output/_SUCCESS
      -rw-r--r--   1 bigdata supergroup          8 2024-04-01 20:09 /user/output/part-00000
       
      bigdata@bigdata-VirtualBox:~/hadoop-3.3.6$ hdfs dfs -cat /user/output/part*
       
      56    
      78
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

HDFS Interfaces

Outline

Internals of HDFS

  • What happens "inside" when we read data into HDFS ?

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Internals of HDFS

  • Read data from HDFS
  • Step 1: The client opens the file it wishes to read by calling open() on the FileSystem object, which for HDFS is an instance of DistributedFileSystem
  • Step 2: DistributedFileSystem calls the namenode, using remote procedure calls (RPCs), to determine the locations of the first few blocks in the file
  • Step 3: The DistributedFileSystem returns an FSDataInputStream to the client and the client calls read() on the stream

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Internals of HDFS

  • Step 4: FSDataInputStream connects to the first datanode for the first block in the file, and then data is streamed from the datanode back to the client, by calling read() repeatedly on the stream
  • Step 5: When the end of the block is reached, FSDataInputStream will close the connection to the datanode, then find the best (possibly the same) datanode for the next block
  • Step 6: When the client has finished reading, it calls close() on the FSDataInputStream

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Internals of HDFS

  • Write data into HDFS

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Internals of HDFS

  • Step 1: The client creates the file by calling create() on DistributedFileSystem
  • Step 2: DistributedFileSystem makes an RPC call to the namenode to create a new file in the file system namespace and returns an FSDataOutputStream for the client to start writing data to
  • Step 3: The client writes data into the FSDataOutputStream
  • Step 4: Data wrapped by the FSDataOutputStream is split into packages, which are flushed into a queue; data packages are sent to the blocks in a datanode and forwarded to other (usually two) datanodes

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Internals of HDFS

  • Step 5: If FSDataStream receives an ack signal from the datanode the data packages are removed from the queue
  • Step 6: When the client has finished writing data, it calls close() on the stream
  • Step 7: The client signals the namenode that the writing is completed

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

References

TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026