Hadoop Distributed File System (HDFS)
1
Hadoop Distributed File System (HDFS) 1 HDFS Overview A - - PowerPoint PPT Presentation
Hadoop Distributed File System (HDFS) 1 HDFS Overview A distributed file system Built on the architecture of Google File System (GFS) Shares a similar architecture to many other common distributed storage engines such as Amazon S3
1
2
3
4
B B B B B B B B B B B B B B B Name node Data nodes
5
B B B B B B B B B B B B B B B Name node Data nodes File and directory names Block ordering and locations Capacity of data nodes Architecture of data nodes Block data Name node location
6
Input file (600 MB) 128 MB 128 MB 128 MB 128 MB 88 MB HDFS Block
7
B B B B B B B B B B B B B B B
8
9
File1 List of iNodes Block 1 Block 2 Block 3 … File1 List of block locations Meta data B B B B B B B B B B B B B B B
10
11
12
f1 f2
13
f3
14
15
16
File creator Name node Data nodes 1 2 3
17
File creator Create(…) The creator process calls the create function which translates to an RPC call at the name node Name node Data nodes 1 2 3
18
Name node Data nodes File creator Create(…) The master node creates one initial block with three replicas
machine
random machine in a different rack
machine on the same rack of the second machine 1 2 3 B1 File r1 r2 r3
19
Node #32
Node #3 Node #2 Node #1
…
Node #34 Node #33
20
File creator OutputStream(r1) Name node Data nodes 1 2 3 B1 File r1 r2 r3
21
File creator OutputStream#write Name node Data nodes 1 2 3 B1 File r1 r2 r3
22
File creator OutputStream#write Name node Data nodes 1 2 3 B1 File r1 r2 r3
23
File creator OutputStream#write Name node Data nodes 1 2 3 B1 File r1 r2 r3
24
File creator OutputStream#write à B2.r1 When a block is filled up, the creator contacts the name node to create the next block Next block Name node Data nodes 1 2 3 B1 File r1 r2 r3 B2 r1 r2 r3
25
26
Name node Data nodes File creator If the file creator is running on one of the data nodes, the first replica is always assigned to that node The second and third replicas are assigned as before, i.e., the second replica on a different rack and the third replica on the same rack as the second one.
27
28
29
Data nodes File reader
Name node The reader process calls the open function which translates to an RPC call at the name node
30
Data nodes File reader InputStream Name node The name node locates the first block of that file and returns the address of one of the nodes that store that block The name node returns an input stream for the file
31
Data nodes File reader InputStream#read(…) Name node
32
Data nodes File reader Name node When an end-of-block is reached, the name node locates the next block Next block
33
Data nodes File reader Name node seek(pos) InputStream#seek operation locates a block and positions the stream accordingly
34
Data nodes File reader Name node
the reader, this replica is chosen to read
machine in the same rack is chosen
chosen Open, seek When self-reading occurs, HDFS can make it much faster through a feature called short-circuit
35
36
37
38
B B B B B B B B B B B B B B B B B B B
39
B B B B B B B B B B B B B B B
40
B B B B B B B B B B B B B B B
41
Name node File 1 File 2 File 3 Concatenate File 1 + File 2 + File 3 è File 4 Rather than creating new blocks, HDFS can just change the metadata in the name node to delete File 1, File 2, and File 3, and assign their blocks to a new File 4 in the right order.
42
43
§ https://hadoop.apache.org/docs/r3.3.0/hadoop-project-dist/hadoop- common/FileSystemShell.html
44
45
FileSystem DistributedFileSystem LocalFileSystem S3FileSystem Path Configuration
46
47
48
49
Configuration conf = new Configuration(); Path path = new Path(“…”); FileSystem fs = path.getFileSystem(conf); // To get the local FS fs = FileSystem.getLocal (conf); // To get the default FS fs = FileSystem.get(conf);
50
FSDataOutputStream out = fs.create(path, …);
fs.delete(path, recursive); fs.deleteOnExit(path);
fs.rename(oldPath, newPath);
51
FSDataInputStream in = fs.open(path, …);
in.seek(pos); in.seekToNewSource(pos);
52
fs.concat(destination, src[]);
fs.getFileStatus(path);
fs.getFileBlockLocations(path, from, to);
53
54
55
Input File
56
Input File Block 1 Block 2 Block 3 Block 4
Block 1 Block 2 Block 3 Block 4 record
57
Input File
58
Input File record3 record2 record1 record6 record5 record4 record9 record8 record7 record10
59
60