1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.mapreduce;
19
20 import java.io.IOException;
21 import java.util.List;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.wal.WAL;
27 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
28 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
29 import org.apache.hadoop.mapreduce.InputFormat;
30 import org.apache.hadoop.mapreduce.InputSplit;
31 import org.apache.hadoop.mapreduce.JobContext;
32 import org.apache.hadoop.mapreduce.RecordReader;
33 import org.apache.hadoop.mapreduce.TaskAttemptContext;
34
35
36
37
38
39 @Deprecated
40 @InterfaceAudience.Public
41 public class HLogInputFormat extends InputFormat<HLogKey, WALEdit> {
42 private static final Log LOG = LogFactory.getLog(HLogInputFormat.class);
43 public static final String START_TIME_KEY = "hlog.start.time";
44 public static final String END_TIME_KEY = "hlog.end.time";
45
46
47 private final WALInputFormat delegate = new WALInputFormat();
48
49
50
51
52 static class HLogKeyRecordReader extends WALInputFormat.WALRecordReader<HLogKey> {
53 @Override
54 public HLogKey getCurrentKey() throws IOException, InterruptedException {
55 if (!(currentEntry.getKey() instanceof HLogKey)) {
56 final IllegalStateException exception = new IllegalStateException(
57 "HLogInputFormat only works when given entries that have HLogKey for keys. This" +
58 " one had '" + currentEntry.getKey().getClass() + "'");
59 LOG.error("The deprecated HLogInputFormat has to work with the deprecated HLogKey class, " +
60 " but HBase internals read the wal entry using some other class." +
61 " This is a bug; please file an issue or email the developer mailing list. It is " +
62 "likely that you would not have this problem if you updated to use WALInputFormat. " +
63 "You will need the following exception details when seeking help from the HBase " +
64 "community.",
65 exception);
66 throw exception;
67 }
68 return (HLogKey)currentEntry.getKey();
69 }
70 }
71
72 @Override
73 public List<InputSplit> getSplits(JobContext context) throws IOException,
74 InterruptedException {
75 return delegate.getSplits(context, START_TIME_KEY, END_TIME_KEY);
76 }
77
78 @Override
79 public RecordReader<HLogKey, WALEdit> createRecordReader(InputSplit split,
80 TaskAttemptContext context) throws IOException, InterruptedException {
81 return new HLogKeyRecordReader();
82 }
83 }