
Hadoop is an open-source framework that allows for the distributed processing and storage of large datasets across clusters of computers. It is designed to handle massive amounts...
Hadoop is an open-source framework that allows for the distributed processing and storage of large datasets across clusters of computers. It is designed to handle massive amounts of data efficiently, making it an essential tool for Big Data analytics. The primary components of Hadoop are HDFS (Hadoop Distributed File System) and MapReduce.
HDFS (Hadoop Distributed File System):
MapReduce:
YARN (Yet Another Resource Negotiator):
Hadoop Ecosystem:
Here’s a simple example of a word count application in Hadoop using MapReduce:
Mapper Class (Processes input data):
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String[] words = value.toString().split("\\s+");
for (String wordText : words) {
word.set(wordText);
context.write(word, one);
}
}
}
Reducer Class (Aggregates results from the mapper):
public class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
Driver Class (Sets up the job):
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
TokenizerMapper class reads the input text, splits it into words, and sends each word with a count of 1 to the reducer. The IntSumReducer class aggregates the counts for each word.FUSE is a software interface that allows users to create their own file systems without requiring kernel-level code. This means that file systems can be implemented and run in user space rather than being built directly into the kernel. FUSE provides a simple way to create file systems that can interact with applications just like traditional file systems, without modifying the core operating system.
User-Space File System:
FUSE Architecture:
FUSE API:
Advantages of FUSE:
Use Cases for FUSE:
Here’s a minimal example of creating a FUSE-based file system in Python using the FUSE Python bindings:
import fuse
import os
class SimpleFS(fuse.Fuse):
def readdir(self, path, fh):
# Return the contents of the directory (for now, return an empty list)
return ['.', '..', 'hello.txt']
def getattr(self, path):
# Return file information
if path == '/hello.txt':
return { 'st_mode': 0o100644, 'st_nlink': 1, 'st_size': 13 }
return -fuse.ENOENT # File doesn't exist
def read(self, path, size, offset, fh):
if path == '/hello.txt':
return 'Hello, world!'
return ''
if __name__ == '__main__':
fuse.FUSE(SimpleFS(), '/mnt/simplefs', foreground=True)
In this example, SimpleFS is a class that defines basic file system operations:
readdir: Lists the contents of the root directory (with a file called hello.txt).getattr: Provides file attributes for hello.txt (size, permissions).read: Reads the contents of hello.txt (returns "Hello, world!").The file system is mounted at /mnt/simplefs, and once you run this code, accessing the mounted directory will show the virtual file hello.txt.
Purpose:
Architecture:
Use Cases:
While Hadoop handles distributed data storage and processing, FUSE is focused on file system abstraction and allows for custom implementations of storage systems. They serve different needs but can be used in conjunction with each other in larger data storage and processing systems.
Open this section to view and download past papers
Click on Show Past Papers to load available exam papers.