Hadoop Introduction

What is Hadoop

Apache Hadoop is an open-source distributed computing framework developed by the Apache Software Foundation, designed for processing and storing large-scale datasets. Hadoop provides reliable, scalable solutions for distributed data storage and computing, capable of processing massive amounts of data on clusters made up of commodity hardware. The core design philosophy of Hadoop is to move computation to where the data is located, rather than moving large amounts of data to computation nodes, thereby significantly reducing network transfer overhead and improving processing efficiency.

The origin of the Hadoop project can be traced back to 2003 when Google published its paper on the Google File System (GFS), followed by a paper on MapReduce in 2004. Inspired by these papers, Yahoo! engineers Doug Cutting and Mike Cafarella began developing an open-source implementation, which became Hadoop. In 2006, Hadoop officially became a project of the Apache Software Foundation, with its name derived from Doug Cutting's son's toy elephant.

Hadoop is developed in Java, offering excellent cross-platform capabilities. Its core components include HDFS (Hadoop Distributed File System) and YARN (Yet Another Resource Negotiator), along with the MapReduce programming model. Hadoop's design philosophy is "everything is scalable"—the system can linearly scale storage capacity and computing power by simply adding more nodes. This simple yet powerful design has made Hadoop the infrastructure of choice in the big data processing field.

Core Components

HDFS - Distributed File System

HDFS is Hadoop's distributed file system, designed for storing extremely large files. HDFS uses a master-slave architecture consisting of one NameNode and multiple DataNodes. The NameNode manages the file system namespace and metadata, maintaining the directory structure, recording block lists for each file, and the locations of each block on DataNodes. DataNodes are responsible for actual data storage, periodically reporting their stored block information to the NameNode.

HDFS features high fault tolerance through data replication. By default, each data block is replicated to three different DataNodes, ensuring data can be recovered from other replicas even if a node fails. HDFS is optimized for sequential reading of large files, making it suitable for batch processing scenarios, but not ideal for low-latency random read/write operations. HDFS also supports rack awareness, intelligently distributing block replicas to nodes on different racks to further improve data availability and system fault tolerance.

The HDFS architecture follows a "Write Once Read Many" (WORM) principle, meaning files should not be modified after being written. This design simplifies the consistency model, improves read performance, and makes data replication and distribution simpler. HDFS also provides snapshot functionality, allowing creation of read-only point-in-time copies of the file system for data backup and recovery.

YARN - Resource Manager

YARN is a resource management platform introduced in Hadoop 2.x, responsible for unified cluster resource management and scheduling. YARN separates resource management from application execution, enabling Hadoop to support more types of workloads beyond just MapReduce batch jobs. YARN's core components include ResourceManager, NodeManager, and ApplicationMaster.

ResourceManager is the core component of YARN, responsible for resource allocation and management across the entire cluster. It receives resource requests from applications and schedules based on available cluster resources. ResourceManager consists of a Scheduler and an ApplicationsManager. The Scheduler is responsible for allocating resources according to preset policies, while the ApplicationsManager accepts application submission requests and launches ApplicationMasters for applications.

NodeManager is the agent on each worker node, responsible for managing resources on that node including CPU, memory, disk, and network resources. NodeManager periodically reports its resource usage and container status to ResourceManager and executes instructions from ResourceManager. ApplicationMaster is the manager for each application, responsible for negotiating resources with ResourceManager and coordinating with NodeManagers to execute tasks.

MapReduce - Programming Model

MapReduce is Hadoop's core computing model for parallel processing of large-scale data. The MapReduce programming model divides the data processing into two main phases: Map and Reduce. In the Map phase, the system splits input data into independent chunks and processes each chunk in parallel, outputting key-value pairs as intermediate results. In the Reduce phase, the system aggregates and processes intermediate results with the same keys to produce the final computation results.

The MapReduce framework automatically handles complex details such as data distribution, task scheduling, load balancing, and fault tolerance, allowing developers to focus on implementing business logic. This abstraction greatly simplifies distributed program development—developers only need to write Map and Reduce functions, and the framework handles all the complexities of distributed execution. MapReduce also supports custom Partitioners and Combiners for optimizing data flow and reducing network transmission.

The execution process of a MapReduce job includes stages such as input splitting, Map task execution, intermediate result shuffling, Reduce task execution, and result output. The shuffle phase is the core process of MapReduce, responsible for partitioning, sorting, and merging Map task outputs by key, then transporting them to corresponding Reduce tasks. This process is computation-intensive and network-intensive, significantly impacting overall job performance.

Technical Architecture

NameNode and Secondary NameNode

NameNode is the core component of HDFS, maintaining metadata for the entire file system. It keeps the complete file system metadata in memory, including file names, file attributes, mappings between files and data blocks, and mappings between blocks and DataNodes. To ensure metadata persistence, NameNode also writes metadata to a transaction log (EditLog) on the local file system. When NameNode starts, it reads the image file (FsImage) and replays the transaction log to restore the file system state.

Secondary NameNode is not a backup of NameNode; its main purpose is to periodically merge FsImage and EditLog, helping NameNode reduce startup time and EditLog file size. Secondary NameNode typically runs on a separate machine, periodically downloading FsImage and EditLog from NameNode, merging them locally, and uploading the new FsImage back to NameNode. This process, called Checkpointing, can effectively reduce NameNode's memory pressure and startup time.

ResourceManager Architecture

ResourceManager uses a two-level scheduler architecture. The first level includes Capacity Scheduler and Fair Scheduler, which are responsible for distributing cluster resources among different queues and applications. The second level is ApplicationMaster—each application has its own ApplicationMaster responsible for negotiating resources with ResourceManager and managing application execution.

Capacity Scheduler allows multiple organizations to share cluster resources, with each organization having its own queue, ensuring each organization receives a certain resource quota. Fair Scheduler emphasizes fairness, automatically balancing resource distribution among all running applications so each gets relatively fair resources. Both schedulers can be flexibly configured through configuration files to meet different scenario requirements.

Data Locality

Data locality is an important optimization strategy in Hadoop, aiming to reduce network data transmission. Hadoop attempts to assign computation tasks to nodes where the corresponding data is stored—this is the "move computation to data" philosophy. Data locality has three levels: node-local (computation and data on the same node), rack-local (computation and data on the same rack), and cross-rack (computation and data on different racks).

Hadoop considers node-local data first when scheduling tasks; if that node is unavailable, it falls back to rack-local data. To achieve this optimization, NameNode reports each block's location information to ResourceManager, which uses this information to make optimal scheduling decisions. Data locality is very important for large-scale data processing and can significantly improve overall cluster performance.

Application Scenarios

Hadoop is widely used in various fields of big data processing. In data analysis, Hadoop can process and analyze massive volumes of log data, user behavior data, and business transaction data, helping enterprises extract valuable information from huge datasets. In the data warehouse field, Hadoop can complement traditional data warehouses, handling structured and unstructured data with lower-cost storage and analytics capabilities.

In machine learning, Hadoop can serve as the infrastructure for large-scale feature engineering and model training, supporting distributed machine learning algorithms. In data lake architectures, HDFS provides a cheap and reliable data storage layer for storing raw data from various sources. For real-time processing, while Hadoop itself is not suited for real-time computing, it can be combined with streaming frameworks like Apache Spark and Apache Flink to achieve near-real-time data processing and analysis.

Hadoop is also the foundation for many other big data technologies. Many popular distributed computing frameworks such as Apache Spark, Apache Hive, and Apache Pig are built on Hadoop or deeply integrated with it. Mastering Hadoop's principles and practices is of great significance for understanding and using other big data technologies.

Development History

Since its birth in 2006, Hadoop has undergone multiple major version iterations. In the Hadoop 1.0 era, MapReduce was responsible for both resource scheduling and task execution—simple architecture but limited scalability. Hadoop 2.0 introduced YARN, separating resource management from task execution, greatly improving system scalability and flexibility while supporting more types of workloads.

Hadoop 3.0 brought significant improvements including support for multiple NameNodes (HA Federation), containerized execution environments, and GPU acceleration. Hadoop 3.x also optimized storage efficiency, providing erasure coding-based data protection that can significantly reduce storage overhead while ensuring data reliability. Currently, the Hadoop ecosystem continues to evolve and improve, with new features and optimizations constantly being introduced.

Hadoop's development has also spawned a large and active ecosystem. Apache Hive provides SQL-like query language, allowing SQL-familiar users to easily process big data. Apache Pig provides high-level data flow language, simplifying development of complex data processing tasks. Apache HBase provides a column-oriented distributed database supporting random read/write. Apache Sqoop simplifies data migration between relational databases and HDFS. These projects together form a complete big data processing solution.