1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import com.beust.jcommander.JCommander;
21 import com.beust.jcommander.Parameter;
22 import com.beust.jcommander.ParametersDelegate;
23
24 import org.apache.hadoop.hbase.client.Connection;
25 import org.apache.hadoop.hbase.client.ConnectionFactory;
26
27 import org.apache.omid.HBaseShims;
28 import org.apache.omid.tools.hbase.HBaseLogin;
29 import org.apache.omid.tools.hbase.SecureHBaseConfig;
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.hbase.HBaseConfiguration;
32
33 import org.apache.hadoop.hbase.TableName;
34 import org.apache.hadoop.hbase.util.Bytes;
35
36 import java.io.IOException;
37
38 public class CompactorUtil {
39
40 public static void setOmidCompaction(Connection conn, TableName table, byte[] columnFamily, String value)
41 throws IOException {
42 HBaseShims.setCompaction(conn, table, columnFamily, OmidCompactor.OMID_COMPACTABLE_CF_FLAG, value);
43 }
44
45 public static void enableOmidCompaction(Connection conn,
46 TableName table, byte[] columnFamily) throws IOException {
47
48 setOmidCompaction(conn, table, columnFamily, Boolean.TRUE.toString());
49 }
50
51 public static void disableOmidCompaction(Connection conn,
52 TableName table, byte[] columnFamily) throws IOException {
53 setOmidCompaction(conn, table, columnFamily, Boolean.FALSE.toString());
54 }
55
56 static class Config {
57 @Parameter(names = "-table", required = true)
58 String table;
59
60 @Parameter(names = "-columnFamily", required = false)
61 String columnFamily;
62
63 @Parameter(names = "-help")
64 boolean help = false;
65
66 @Parameter(names = "-enable")
67 boolean enable = false;
68
69 @Parameter(names = "-disable")
70 boolean disable = false;
71
72 @ParametersDelegate
73 private SecureHBaseConfig loginFlags = new SecureHBaseConfig();
74
75 }
76
77 public static void main(String[] args) throws IOException {
78 Config cmdline = new Config();
79 JCommander jcommander = new JCommander(cmdline, args);
80 if (cmdline.help) {
81 jcommander.usage("CompactorUtil");
82 System.exit(1);
83 }
84
85 HBaseLogin.loginIfNeeded(cmdline.loginFlags);
86
87 Configuration conf = HBaseConfiguration.create();
88 try (Connection conn = ConnectionFactory.createConnection(conf)) {
89 if (cmdline.enable) {
90 enableOmidCompaction(conn, TableName.valueOf(cmdline.table),
91 Bytes.toBytes(cmdline.columnFamily));
92 } else if (cmdline.disable) {
93 disableOmidCompaction(conn, TableName.valueOf(cmdline.table),
94 Bytes.toBytes(cmdline.columnFamily));
95 } else {
96 System.err.println("Must specify enable or disable");
97 }
98 }
99 }
100 }