1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.regionserver.wal;
22
23 import java.io.IOException;
24 import java.util.List;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.fs.FileSystem;
30 import org.apache.hadoop.fs.Path;
31 import org.apache.hadoop.hbase.HConstants;
32 import org.apache.hadoop.hbase.regionserver.wal.HLog.Reader;
33 import org.apache.hadoop.hbase.regionserver.wal.HLog.Writer;
34
35 public class HLogFactory {
36 private static final Log LOG = LogFactory.getLog(HLogFactory.class);
37
38 public static HLog createHLog(final FileSystem fs, final Path root, final String logName,
39 final Configuration conf) throws IOException {
40 return new FSHLog(fs, root, logName, conf);
41 }
42
43 public static HLog createHLog(final FileSystem fs, final Path root, final String logName,
44 final String oldLogName, final Configuration conf) throws IOException {
45 return new FSHLog(fs, root, logName, oldLogName, conf);
46 }
47
48 public static HLog createHLog(final FileSystem fs, final Path root, final String logName,
49 final Configuration conf, final List<WALActionsListener> listeners,
50 final String prefix) throws IOException {
51 return new FSHLog(fs, root, logName, conf, listeners, prefix);
52 }
53
54 public static HLog createMetaHLog(final FileSystem fs, final Path root, final String logName,
55 final Configuration conf, final List<WALActionsListener> listeners,
56 final String prefix) throws IOException {
57 return new FSHLog(fs, root, logName, HConstants.HREGION_OLDLOGDIR_NAME,
58 conf, listeners, false, prefix, true);
59 }
60
61
62
63
64
65 private static Class<? extends Reader> logReaderClass;
66
67 static void resetLogReaderClass() {
68 logReaderClass = null;
69 }
70
71
72
73
74
75
76
77
78 public static HLog.Reader createReader(final FileSystem fs,
79 final Path path, Configuration conf)
80 throws IOException {
81 try {
82
83 if (logReaderClass == null) {
84
85 logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl",
86 SequenceFileLogReader.class, Reader.class);
87 }
88
89
90 HLog.Reader reader = logReaderClass.newInstance();
91 reader.init(fs, path, conf);
92 return reader;
93 } catch (IOException e) {
94 throw e;
95 }
96 catch (Exception e) {
97 throw new IOException("Cannot get log reader", e);
98 }
99 }
100
101
102
103
104
105 private static Class<? extends Writer> logWriterClass;
106
107
108
109
110
111
112 public static HLog.Writer createWriter(final FileSystem fs,
113 final Path path, Configuration conf)
114 throws IOException {
115 try {
116 if (logWriterClass == null) {
117 logWriterClass = conf.getClass("hbase.regionserver.hlog.writer.impl",
118 SequenceFileLogWriter.class, Writer.class);
119 }
120 HLog.Writer writer = (HLog.Writer) logWriterClass.newInstance();
121 writer.init(fs, path, conf);
122 return writer;
123 } catch (Exception e) {
124 throw new IOException("cannot get log writer", e);
125 }
126 }
127
128 }