HADOOP I/O
Prepared By: Madhuri J
Assistant Professor
Dept. of Computer Science and Engg
Bangalore Institute of Technology
1
Contents
2
�
�
�
Data Integrity
3
Usual way of detecting corrupted data
–
Technique for only error detection (cannot fix the corrupted data)
–
CRC
-
32 (cyclic redundancy check)
Compute a 32
-
bit integer checksum for input of any size
3
/ 18
�
Data Integrity in HDFS
4
Data Integrity in HDFS
5
DataBlockScanner
6
7
LocalFileSystem
8
ChecksumFileSystem
9
Compression
10
11
12
CompressionCodec�
create a CompressionOutputStream to which you write your uncompressed data to have it written in compressed form to the underlying stream.
obtain a CompressionInputStream, which allows you to read uncompressed data from the underlying stream.
13
14
Serialization
15
16
The Writable Interface
public interface Writable {
void write(DataOutput out) throws IOException;
void readFields(DataInput in) throws IOException;
}
IntWritable writable = new IntWritable();writable.set(163);
public static byte[] serialize(Writable writable) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(out);
writable.write(dataOut);
dataOut.close();
return out.toByteArray();
}
byte[] bytes = serialize(writable);
17
Writable Classes
18
Text Writable
Text t = new Text("hadoop");
t.set("pig");
assertThat(t.getLength(), is(3));
assertThat(t.getBytes().length, is(3));
19
20
WritableComparable and comparators
package org.apache.hadoop.io;
import java.util.Comparator;
public interface RawComparator<T> extends Comparator<T> {
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2);
}
21
Serialization Frameworks
22
File-Based Data Structures
23
Sequence file
24
Sequence file Format
25
26