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