View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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   * Simple {@link InputFormat} for {@link WAL} files.
37   * @deprecated use {@link WALInputFormat}
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    // Delegate to WALInputFormat for implementation.
47    private final WALInputFormat delegate = new WALInputFormat();
48  
49    /**
50     * {@link RecordReader} that pulls out the legacy HLogKey format directly.
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  }