HBASE-26700 The way we bypass broken track file is not enough in StoreFileListFile...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / RegionAsTable.java
blob969d01afa42484215f20391780dcd0ac1ec441f9
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.hadoop.hbase.regionserver;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.TimeUnit;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.Cell;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.client.Append;
30 import org.apache.hadoop.hbase.client.Delete;
31 import org.apache.hadoop.hbase.client.Durability;
32 import org.apache.hadoop.hbase.client.Get;
33 import org.apache.hadoop.hbase.client.Increment;
34 import org.apache.hadoop.hbase.client.Put;
35 import org.apache.hadoop.hbase.client.RegionLocator;
36 import org.apache.hadoop.hbase.client.Result;
37 import org.apache.hadoop.hbase.client.ResultScanner;
38 import org.apache.hadoop.hbase.client.Row;
39 import org.apache.hadoop.hbase.client.RowMutations;
40 import org.apache.hadoop.hbase.client.Scan;
41 import org.apache.hadoop.hbase.client.Table;
42 import org.apache.hadoop.hbase.client.TableDescriptor;
43 import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
44 import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
45 import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
46 import org.apache.hadoop.hbase.filter.Filter;
47 import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
49 import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor;
50 import org.apache.hbase.thirdparty.com.google.protobuf.Message;
51 import org.apache.hbase.thirdparty.com.google.protobuf.Service;
52 import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
54 /**
55 * An implementation of {@link Table} that sits directly on a Region; it decorates the passed in
56 * Region instance with the Table API. Some API is not implemented yet (throws
57 * {@link UnsupportedOperationException}) mostly because no need as yet or it necessitates copying
58 * a load of code local from RegionServer.
60 * <p>Use as an instance of a {@link Table} in-the-small -- no networking or servers
61 * necessary -- or to write a test that can run directly against the datastore and then
62 * over the network.
64 public class RegionAsTable implements Table {
65 private final Region region;
67 /**
68 * @param region Region to decorate with Table API.
70 public RegionAsTable(final Region region) {
71 this.region = region;
74 @Override
75 public TableName getName() {
76 return this.region.getTableDescriptor().getTableName();
79 @Override
80 public Configuration getConfiguration() {
81 throw new UnsupportedOperationException();
84 @Override
85 public TableDescriptor getDescriptor() throws IOException {
86 return this.region.getTableDescriptor();
89 @Override
90 public boolean exists(Get get) throws IOException {
91 if (!get.isCheckExistenceOnly()) throw new IllegalArgumentException();
92 return get(get) != null;
95 @Override
96 public boolean[] exists(List<Get> gets) throws IOException {
97 boolean [] results = new boolean[gets.size()];
98 int index = 0;
99 for (Get get: gets) {
100 results[index++] = exists(get);
102 return results;
105 @Override
106 public void batch(List<? extends Row> actions, Object[] results)
107 throws IOException, InterruptedException {
108 throw new UnsupportedOperationException();
111 @Override
112 public <R> void batchCallback(List<? extends Row> actions, Object[] results,
113 Callback<R> callback)
114 throws IOException, InterruptedException {
115 throw new UnsupportedOperationException();
118 @Override
119 public Result get(Get get) throws IOException {
120 return this.region.get(get);
123 @Override
124 public Result[] get(List<Get> gets) throws IOException {
125 Result [] results = new Result[gets.size()];
126 int index = 0;
127 for (Get get: gets) {
128 results[index++] = get(get);
130 return results;
133 static class RegionScannerToResultScannerAdaptor implements ResultScanner {
134 private static final Result [] EMPTY_RESULT_ARRAY = new Result[0];
135 private final RegionScanner regionScanner;
137 RegionScannerToResultScannerAdaptor(final RegionScanner regionScanner) {
138 this.regionScanner = regionScanner;
141 @Override
142 public Iterator<Result> iterator() {
143 throw new UnsupportedOperationException();
146 @Override
147 public Result next() throws IOException {
148 List<Cell> cells = new ArrayList<>();
149 return regionScanner.next(cells)? Result.create(cells): null;
152 @Override
153 public Result[] next(int nbRows) throws IOException {
154 List<Result> results = new ArrayList<>(nbRows);
155 for (int i = 0; i < nbRows; i++) {
156 Result result = next();
157 if (result == null) break;
158 results.add(result);
160 return results.toArray(EMPTY_RESULT_ARRAY);
163 @Override
164 public void close() {
165 try {
166 regionScanner.close();
167 } catch (IOException e) {
168 throw new RuntimeException(e);
172 @Override
173 public boolean renewLease() {
174 throw new UnsupportedOperationException();
177 @Override
178 public ScanMetrics getScanMetrics() {
179 throw new UnsupportedOperationException();
183 @Override
184 public ResultScanner getScanner(Scan scan) throws IOException {
185 return new RegionScannerToResultScannerAdaptor(this.region.getScanner(scan));
188 @Override
189 public ResultScanner getScanner(byte[] family) throws IOException {
190 return getScanner(new Scan().addFamily(family));
193 @Override
194 public ResultScanner getScanner(byte[] family, byte[] qualifier) throws IOException {
195 return getScanner(new Scan().addColumn(family, qualifier));
198 @Override
199 public void put(Put put) throws IOException {
200 this.region.put(put);
203 @Override
204 public void put(List<Put> puts) throws IOException {
205 for (Put put: puts) put(put);
208 @Override
209 public void delete(Delete delete) throws IOException {
210 this.region.delete(delete);
213 @Override
214 public void delete(List<Delete> deletes) throws IOException {
215 for(Delete delete: deletes) delete(delete);
218 @Override
219 public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
220 throw new UnsupportedOperationException();
223 @Override
224 public CheckAndMutateWithFilterBuilder checkAndMutate(byte[] row, Filter filter) {
225 throw new UnsupportedOperationException();
228 @Override
229 public Result mutateRow(RowMutations rm) throws IOException {
230 throw new UnsupportedOperationException();
233 @Override
234 public Result append(Append append) throws IOException {
235 return this.region.append(append);
238 @Override
239 public Result increment(Increment increment) throws IOException {
240 return this.region.increment(increment);
243 @Override
244 public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
245 throws IOException {
246 throw new UnsupportedOperationException();
249 @Override
250 public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount,
251 Durability durability)
252 throws IOException {
253 throw new UnsupportedOperationException();
257 * This call will NOT close the underlying region.
259 @Override
260 public void close() throws IOException {
263 @Override
264 public CoprocessorRpcChannel coprocessorService(byte[] row) {
265 throw new UnsupportedOperationException();
268 @Override
269 public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey,
270 byte[] endKey, Call<T, R> callable)
271 throws ServiceException, Throwable {
272 throw new UnsupportedOperationException();
275 @Override
276 public <T extends Service, R> void coprocessorService(Class<T> service, byte[] startKey,
277 byte[] endKey, Call<T, R> callable, Callback<R> callback)
278 throws ServiceException, Throwable {
279 throw new UnsupportedOperationException();
282 @Override
283 public <R extends Message> Map<byte[], R> batchCoprocessorService(MethodDescriptor
284 methodDescriptor, Message request,
285 byte[] startKey, byte[] endKey, R responsePrototype)
286 throws ServiceException, Throwable {
287 throw new UnsupportedOperationException();
290 @Override
291 public <R extends Message> void batchCoprocessorService(MethodDescriptor methodDescriptor,
292 Message request, byte[] startKey, byte[] endKey, R responsePrototype, Callback<R> callback)
293 throws ServiceException, Throwable {
294 throw new UnsupportedOperationException();
297 @Override
298 public long getReadRpcTimeout(TimeUnit unit) {
299 throw new UnsupportedOperationException();
302 @Override
303 public long getOperationTimeout(TimeUnit unit) {
304 throw new UnsupportedOperationException();
307 @Override
308 public long getWriteRpcTimeout(TimeUnit unit) {
309 throw new UnsupportedOperationException();
312 @Override
313 public long getRpcTimeout(TimeUnit unit) {
314 throw new UnsupportedOperationException();
317 @Override
318 public RegionLocator getRegionLocator() throws IOException {
319 throw new UnsupportedOperationException();