1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid;
19
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.hbase.CellComparator;
22 import org.apache.hadoop.hbase.HColumnDescriptor;
23 import org.apache.hadoop.hbase.HTableDescriptor;
24 import org.apache.hadoop.hbase.KeyValue;
25 import org.apache.hadoop.hbase.TableName;
26 import org.apache.hadoop.hbase.client.Admin;
27 import org.apache.hadoop.hbase.client.Connection;
28 import org.apache.hadoop.hbase.client.CoprocessorHConnection;
29 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
30 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
31 import org.apache.hadoop.hbase.regionserver.HRegionServer;
32 import org.apache.hadoop.hbase.regionserver.Region;
33 import org.apache.hadoop.hbase.regionserver.Store;
34 import org.apache.hadoop.hbase.util.Bytes;
35
36 import java.io.IOException;
37
38 public class HBaseShims {
39
40 static public void setKeyValueSequenceId(KeyValue kv, int sequenceId) {
41
42 kv.setSequenceId(sequenceId);
43
44 }
45
46 static public Region getRegionCoprocessorRegion(RegionCoprocessorEnvironment env) {
47
48 return env.getRegion();
49
50 }
51
52 static public void flushAllOnlineRegions(HRegionServer regionServer, TableName tableName) throws IOException {
53
54 for (Region r : regionServer.getOnlineRegions(tableName)) {
55 r.flush(true);
56 }
57
58 }
59
60 static public void addFamilyToHTableDescriptor(HTableDescriptor tableDesc, HColumnDescriptor columnDesc) {
61
62 tableDesc.addFamily(columnDesc);
63
64 }
65
66 public static CellComparator cellComparatorInstance() {
67 return new CellComparator();
68 }
69
70 public static boolean OmidCompactionEnabled(ObserverContext<RegionCoprocessorEnvironment> env,
71 Store store,
72 String cfFlagValue) {
73 HTableDescriptor desc = env.getEnvironment().getRegion().getTableDesc();
74 HColumnDescriptor famDesc
75 = desc.getFamily(Bytes.toBytes(store.getColumnFamilyName()));
76 return Boolean.valueOf(famDesc.getValue(cfFlagValue));
77 }
78
79
80 public static void setCompaction(Connection conn, TableName table, byte[] columnFamily, String key, String value)
81 throws IOException {
82 try(Admin admin = conn.getAdmin()) {
83 HTableDescriptor desc = admin.getTableDescriptor(table);
84 HColumnDescriptor cfDesc = desc.getFamily(columnFamily);
85 cfDesc.setValue(key, value);
86 admin.modifyColumn(table, cfDesc);
87 }
88 }
89
90
91
92
93
94
95 public static int getNoRetriesNumber() {
96 return 0;
97 }
98
99
100
101
102 public static Connection newServerConnection(Configuration config, RegionCoprocessorEnvironment env) throws IOException {
103 return new CoprocessorHConnection(config, (HRegionServer)env.getRegionServerServices());
104 }
105
106 }