1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.chaos.actions;
20
21 import java.util.Random;
22
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HColumnDescriptor;
25 import org.apache.hadoop.hbase.HTableDescriptor;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.client.Admin;
28 import org.apache.hadoop.hbase.regionserver.BloomType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36 public class ChangeBloomFilterAction extends Action {
37 private final long sleepTime;
38 private final TableName tableName;
39 private static final Logger LOG = LoggerFactory.getLogger(ChangeBloomFilterAction.class);
40
41 public ChangeBloomFilterAction(TableName tableName) {
42 this(-1, tableName);
43 }
44
45 public ChangeBloomFilterAction(int sleepTime, TableName tableName) {
46 this.sleepTime = sleepTime;
47 this.tableName = tableName;
48 }
49
50 @Override
51 public void perform() throws Exception {
52 Random random = new Random();
53 HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
54 Admin admin = util.getHBaseAdmin();
55
56 LOG.info("Performing action: Change bloom filter on all columns of table "
57 + tableName);
58 HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
59 HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
60
61 if (columnDescriptors == null || columnDescriptors.length == 0) {
62 return;
63 }
64
65 final BloomType[] bloomArray = BloomType.values();
66 final int bloomArraySize = bloomArray.length;
67
68 for (HColumnDescriptor descriptor : columnDescriptors) {
69 int bloomFilterIndex = random.nextInt(bloomArraySize);
70 LOG.debug("Performing action: About to set bloom filter type to "
71 + bloomArray[bloomFilterIndex] + " on column "
72 + descriptor.getNameAsString() + " of table " + tableName);
73 descriptor.setBloomFilterType(bloomArray[bloomFilterIndex]);
74 LOG.debug("Performing action: Just set bloom filter type to "
75 + bloomArray[bloomFilterIndex] + " on column "
76 + descriptor.getNameAsString() + " of table " + tableName);
77 }
78
79
80 if (context.isStopping()) {
81 return;
82 }
83 admin.modifyTable(tableName, tableDescriptor);
84 }
85 }