001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.mob;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.HBaseClassTestRule;
022import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
023import org.apache.hadoop.hbase.client.TableDescriptor;
024import org.apache.hadoop.hbase.testclassification.LargeTests;
025import org.junit.Before;
026import org.junit.ClassRule;
027import org.junit.experimental.categories.Category;
028import org.junit.runner.RunWith;
029import org.junit.runners.Parameterized;
030import org.slf4j.Logger;
031import org.slf4j.LoggerFactory;
032
033/**
034 * Mob file compaction chore in a generational batch mode test. 1. Enables batch mode for regular
035 * MOB compaction, Sets batch size to 7 regions. Enables generational mode. 2. Disables periodic MOB
036 * compactions, sets minimum age to archive to 10 sec 3. Creates MOB table with 20 regions 4. Loads
037 * MOB data (randomized keys, 1000 rows), flushes data. 5. Repeats 4. two more times 6. Verifies
038 * that we have 20 *3 = 60 mob files (equals to number of regions x 3) 7. Runs major MOB compaction.
039 * 8. Verifies that number of MOB files in a mob directory is 20 x4 = 80 9. Waits for a period of
040 * time larger than minimum age to archive 10. Runs Mob cleaner chore 11 Verifies that number of MOB
041 * files in a mob directory is 20. 12 Runs scanner and checks all 3 * 1000 rows.
042 */
043@RunWith(Parameterized.class)
044@Category(LargeTests.class)
045public class TestMobCompactionOptRegionBatchMode extends TestMobCompactionWithDefaults {
046  private static final Logger LOG =
047    LoggerFactory.getLogger(TestMobCompactionOptRegionBatchMode.class);
048  @ClassRule
049  public static final HBaseClassTestRule CLASS_RULE =
050    HBaseClassTestRule.forClass(TestMobCompactionOptRegionBatchMode.class);
051
052  private static final int batchSize = 7;
053  private MobFileCompactionChore compactionChore;
054
055  public TestMobCompactionOptRegionBatchMode(Boolean useFileBasedSFT) {
056    super(useFileBasedSFT);
057  }
058
059  @Before
060  public void setUp() throws Exception {
061    super.setUp();
062    compactionChore = new MobFileCompactionChore(conf, batchSize);
063  }
064
065  protected void additonalConfigSetup() {
066    conf.setInt(MobConstants.MOB_MAJOR_COMPACTION_REGION_BATCH_SIZE, batchSize);
067    conf.set(MobConstants.MOB_COMPACTION_TYPE_KEY, MobConstants.OPTIMIZED_MOB_COMPACTION_TYPE);
068    conf.setLong(MobConstants.MOB_COMPACTION_MAX_FILE_SIZE_KEY, 1000000);
069  }
070
071  @Override
072  protected void mobCompactImpl(TableDescriptor tableDescriptor,
073    ColumnFamilyDescriptor familyDescriptor) throws IOException, InterruptedException {
074    LOG.debug("compacting {} in batch mode.", tableDescriptor.getTableName());
075    compactionChore.performMajorCompactionInBatches(admin, tableDescriptor, familyDescriptor);
076  }
077
078  @Override
079  protected String description() {
080    return "generational batch mode";
081  }
082
083}