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 org.apache.hadoop.hbase.HBaseTestingUtility;
22 import org.apache.hadoop.hbase.HConstants;
23 import org.apache.hadoop.hbase.HTableDescriptor;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.client.Admin;
26
27 import java.util.Random;
28
29 public class DecreaseMaxHFileSizeAction extends Action {
30
31 private static final long minFileSize = 1 * 1024 * 1024 * 1024L;
32
33 private final long sleepTime;
34 private final TableName tableName;
35 private final Random random;
36
37 public DecreaseMaxHFileSizeAction(long sleepTime, TableName tableName) {
38 this.sleepTime = sleepTime;
39 this.tableName = tableName;
40 this.random = new Random();
41 }
42
43 @Override
44 public void perform() throws Exception {
45 HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
46 Admin admin = util.getHBaseAdmin();
47 HTableDescriptor htd = admin.getTableDescriptor(tableName);
48
49
50 long currentValue = htd.getMaxFileSize();
51
52
53
54
55 if (currentValue <= 0) {
56 currentValue =
57 context.getHBaseCluster().getConf().getLong(HConstants.HREGION_MAX_FILESIZE,
58 HConstants.DEFAULT_MAX_FILE_SIZE);
59 }
60
61
62 long newValue = (long) (currentValue * 0.9);
63
64
65
66 newValue = Math.max(minFileSize, newValue) - (512 - random.nextInt(1024));
67
68
69 htd.setMaxFileSize(newValue);
70
71
72 if (context.isStopping()) {
73 return;
74 }
75
76
77 admin.modifyTable(tableName, htd);
78
79
80 if (sleepTime > 0) {
81 Thread.sleep(sleepTime);
82 }
83 }
84 }