View Javadoc

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
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
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 }