1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mob;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.Cell;
30 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
31 import org.apache.hadoop.hbase.regionserver.BloomType;
32 import org.apache.hadoop.hbase.regionserver.StoreFile;
33 import org.apache.hadoop.hbase.regionserver.StoreFileScanner;
34
35
36
37
38 @InterfaceAudience.Private
39 public class MobFile {
40
41 private StoreFile sf;
42
43
44 protected MobFile() {
45 }
46
47 protected MobFile(StoreFile sf) {
48 this.sf = sf;
49 }
50
51
52
53
54
55
56
57 public StoreFileScanner getScanner() throws IOException {
58 List<StoreFile> sfs = new ArrayList<StoreFile>();
59 sfs.add(sf);
60 List<StoreFileScanner> sfScanners = StoreFileScanner.getScannersForStoreFiles(sfs, false, true,
61 false, null, sf.getMaxMemstoreTS());
62
63 return sfScanners.get(0);
64 }
65
66
67
68
69
70
71
72
73 public Cell readCell(Cell search, boolean cacheMobBlocks) throws IOException {
74 return readCell(search, cacheMobBlocks, sf.getMaxMemstoreTS());
75 }
76
77
78
79
80
81
82
83
84
85 public Cell readCell(Cell search, boolean cacheMobBlocks, long readPt) throws IOException {
86 Cell result = null;
87 StoreFileScanner scanner = null;
88 List<StoreFile> sfs = new ArrayList<StoreFile>();
89 sfs.add(sf);
90 try {
91 List<StoreFileScanner> sfScanners = StoreFileScanner.getScannersForStoreFiles(sfs,
92 cacheMobBlocks, true, false, null, readPt);
93 if (!sfScanners.isEmpty()) {
94 scanner = sfScanners.get(0);
95 if (scanner.seek(search)) {
96 result = scanner.peek();
97 }
98 }
99 } finally {
100 if (scanner != null) {
101 scanner.close();
102 }
103 }
104 return result;
105 }
106
107
108
109
110
111 public String getFileName() {
112 return sf.getPath().getName();
113 }
114
115
116
117
118
119
120 public void open() throws IOException {
121 if (sf.getReader() == null) {
122 sf.createReader();
123 }
124 }
125
126
127
128
129
130
131 public void close() throws IOException {
132 if (sf != null) {
133 sf.closeReader(false);
134 sf = null;
135 }
136 }
137
138
139
140
141
142
143
144
145
146
147 public static MobFile create(FileSystem fs, Path path, Configuration conf, CacheConfig cacheConf)
148 throws IOException {
149 StoreFile sf = new StoreFile(fs, path, conf, cacheConf, BloomType.NONE);
150 return new MobFile(sf);
151 }
152 }