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.mapreduce;
20
21 import java.io.IOException;
22
23 import org.apache.hadoop.classification.InterfaceAudience;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.conf.Configured;
26 import org.apache.hadoop.fs.FileSystem;
27 import org.apache.hadoop.hbase.HBaseConfiguration;
28 import org.apache.hadoop.hbase.HColumnDescriptor;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.client.HBaseAdmin;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.hadoop.util.Tool;
34 import org.apache.hadoop.util.ToolRunner;
35 import org.apache.zookeeper.KeeperException;
36
37 import com.google.protobuf.ServiceException;
38
39
40
41
42
43
44
45 @InterfaceAudience.Public
46 public class Sweeper extends Configured implements Tool {
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 int sweepFamily(String tableName, String familyName) throws IOException, InterruptedException,
62 ClassNotFoundException, KeeperException, ServiceException {
63 Configuration conf = getConf();
64
65 HBaseAdmin.checkHBaseAvailable(conf);
66 HBaseAdmin admin = new HBaseAdmin(conf);
67 try {
68 FileSystem fs = FileSystem.get(conf);
69 TableName tn = TableName.valueOf(tableName);
70 HTableDescriptor htd = admin.getTableDescriptor(tn);
71 HColumnDescriptor family = htd.getFamily(Bytes.toBytes(familyName));
72 if (family == null || !family.isMobEnabled()) {
73 throw new IOException("Column family " + familyName + " is not a MOB column family");
74 }
75 SweepJob job = new SweepJob(conf, fs);
76
77 return job.sweep(tn, family);
78 } catch (Exception e) {
79 System.err.println("Job aborted due to exception " + e);
80 return 2;
81 } finally {
82 try {
83 admin.close();
84 } catch (IOException e) {
85 System.out.println("Fail to close the HBaseAdmin: " + e.getMessage());
86 }
87 }
88 }
89
90 public static void main(String[] args) throws Exception {
91 Configuration conf = HBaseConfiguration.create();
92 int ret = ToolRunner.run(conf, new Sweeper(), args);
93 System.exit(ret);
94 }
95
96 private void printUsage() {
97 System.err.println("Usage:\n" + "--------------------------\n" + Sweeper.class.getName()
98 + " tableName familyName");
99 System.err.println(" tableName The table name");
100 System.err.println(" familyName The column family name");
101 }
102
103
104
105
106
107
108 public int run(String[] args) throws Exception {
109 if (args.length != 2) {
110 printUsage();
111 return 1;
112 }
113 String table = args[0];
114 String family = args[1];
115 return sweepFamily(table, family);
116 }
117 }