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    * http://www.apache.org/licenses/LICENSE-2.0
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.hadoop.hbase.rsgroup;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  import com.google.common.collect.Lists;
23  import java.util.List;
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.HBaseTestingUtility;
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.MiniHBaseCluster;
28  import org.apache.hadoop.hbase.TableName;
29  import org.apache.hadoop.hbase.Waiter;
30  import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
31  import org.apache.hadoop.hbase.master.HMaster;
32  import org.apache.hadoop.hbase.master.ServerManager;
33  import org.apache.hadoop.hbase.util.compaction.TestMajorCompactorTTL;
34  import org.junit.After;
35  import org.junit.Before;
36  import org.junit.Test;
37  
38  public class TestRSGroupMajorCompactionTTL extends TestMajorCompactorTTL {
39  
40    private final static int NUM_SLAVES_BASE = 6;
41  
42    @Before
43    public void setUp() throws Exception {
44      utility = new HBaseTestingUtility();
45      Configuration conf = utility.getConfiguration();
46      conf.set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, RSGroupBasedLoadBalancer.class.getName());
47      conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, RSGroupAdminEndpoint.class.getName());
48      conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE);
49      conf.setInt("hbase.hfile.compaction.discharger.interval", 10);
50      utility.startMiniCluster(NUM_SLAVES_BASE);
51      MiniHBaseCluster cluster = utility.getHBaseCluster();
52      final HMaster master = cluster.getMaster();
53  
54      //wait for balancer to come online
55      utility.waitFor(60000, new Waiter.Predicate<Exception>() {
56        @Override
57        public boolean evaluate() {
58          return master.isInitialized() &&
59              ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline();
60        }
61      });
62      admin = utility.getHBaseAdmin();
63    }
64  
65    @After
66    public void tearDown() throws Exception {
67      utility.shutdownMiniCluster();
68    }
69  
70    @Test
71    public void testCompactingTables() throws Exception {
72      List<TableName> tableNames = Lists.newArrayList();
73      for (int i = 0; i < 10; i++) {
74        tableNames.add(createTable(name.getMethodName() + "___" + i));
75      }
76  
77      // Delay a bit, so we can set the table TTL to 5 seconds
78      Thread.sleep(10 * 1000);
79  
80      for (TableName tableName : tableNames) {
81        int numberOfRegions = admin.getTableRegions(tableName).size();
82        int numHFiles = utility.getNumHFiles(tableName, FAMILY);
83        // we should have a table with more store files than we would before we major compacted.
84        assertTrue(numberOfRegions < numHFiles);
85        modifyTTL(tableName);
86      }
87  
88      RSGroupMajorCompactionTTL compactor = new RSGroupMajorCompactionTTL();
89      compactor.compactTTLRegionsOnGroup(utility.getConfiguration(),
90          RSGroupInfo.DEFAULT_GROUP, 1, 200, -1, -1, false, false);
91  
92      for (TableName tableName : tableNames) {
93        int numberOfRegions = admin.getTableRegions(tableName).size();
94        int numHFiles = utility.getNumHFiles(tableName, FAMILY);
95        assertEquals(numberOfRegions, numHFiles);
96      }
97    }
98  }