|
| 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 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.regionserver; |
| 19 | + |
| 20 | +import static org.apache.hadoop.hbase.regionserver.HRegion.SPLIT_IGNORE_BLOCKING_ENABLED_KEY; |
| 21 | +import static org.apache.hadoop.hbase.regionserver.Store.PRIORITY_USER; |
| 22 | +import static org.junit.Assert.assertEquals; |
| 23 | +import static org.junit.Assert.assertFalse; |
| 24 | +import static org.junit.Assert.assertNotNull; |
| 25 | +import static org.junit.Assert.assertTrue; |
| 26 | +import java.util.List; |
| 27 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 28 | +import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 29 | +import org.apache.hadoop.hbase.HConstants; |
| 30 | +import org.apache.hadoop.hbase.TableName; |
| 31 | +import org.apache.hadoop.hbase.client.Admin; |
| 32 | +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; |
| 33 | +import org.apache.hadoop.hbase.client.Put; |
| 34 | +import org.apache.hadoop.hbase.client.ResultScanner; |
| 35 | +import org.apache.hadoop.hbase.client.Scan; |
| 36 | +import org.apache.hadoop.hbase.client.Table; |
| 37 | +import org.apache.hadoop.hbase.client.TableDescriptor; |
| 38 | +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; |
| 39 | +import org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure; |
| 40 | +import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; |
| 41 | +import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; |
| 42 | +import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; |
| 43 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 44 | +import org.apache.hadoop.hbase.util.Bytes; |
| 45 | +import org.junit.AfterClass; |
| 46 | +import org.junit.Assert; |
| 47 | +import org.junit.BeforeClass; |
| 48 | +import org.junit.ClassRule; |
| 49 | +import org.junit.Test; |
| 50 | +import org.junit.experimental.categories.Category; |
| 51 | +import org.slf4j.Logger; |
| 52 | +import org.slf4j.LoggerFactory; |
| 53 | +import org.apache.hbase.thirdparty.com.google.common.io.Closeables; |
| 54 | + |
| 55 | +@Category({ MediumTests.class}) |
| 56 | +public class TestSplitWithBlockingFiles { |
| 57 | + |
| 58 | + @ClassRule |
| 59 | + public static final HBaseClassTestRule CLASS_RULE = |
| 60 | + HBaseClassTestRule.forClass(TestSplitWithBlockingFiles.class); |
| 61 | + |
| 62 | + private static final Logger LOG = LoggerFactory.getLogger(TestSplitWithBlockingFiles.class); |
| 63 | + |
| 64 | + protected static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); |
| 65 | + private static TableName TABLE_NAME = TableName.valueOf("test"); |
| 66 | + private static Admin ADMIN; |
| 67 | + private static byte[] CF = Bytes.toBytes("cf"); |
| 68 | + private static Table TABLE; |
| 69 | + |
| 70 | + |
| 71 | + @BeforeClass |
| 72 | + public static void setupCluster() throws Exception { |
| 73 | + UTIL.getConfiguration().setLong(HConstants.HREGION_MAX_FILESIZE, 8 * 2 * 10240L); |
| 74 | + UTIL.getConfiguration().setInt(HStore.BLOCKING_STOREFILES_KEY, 1); |
| 75 | + UTIL.getConfiguration().set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, |
| 76 | + ConstantSizeRegionSplitPolicy.class.getName()); |
| 77 | + UTIL.getConfiguration().setBoolean(SPLIT_IGNORE_BLOCKING_ENABLED_KEY, true); |
| 78 | + UTIL.startMiniCluster(1); |
| 79 | + ADMIN = UTIL.getAdmin(); |
| 80 | + TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLE_NAME) |
| 81 | + .setColumnFamily( |
| 82 | + ColumnFamilyDescriptorBuilder.newBuilder(CF).setBlocksize(1000).build()).build(); |
| 83 | + TABLE = UTIL.createTable(td, null); |
| 84 | + UTIL.waitTableAvailable(TABLE_NAME); |
| 85 | + } |
| 86 | + |
| 87 | + @AfterClass |
| 88 | + public static void cleanupTest() throws Exception { |
| 89 | + Closeables.close(TABLE, true); |
| 90 | + UTIL.shutdownMiniCluster(); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void testSplitIgnoreBlockingFiles() throws Exception { |
| 95 | + ADMIN.splitSwitch(false, true); |
| 96 | + byte[] value = new byte[1024]; |
| 97 | + for (int m = 0; m < 10; m++) { |
| 98 | + String rowPrefix = "row" + m; |
| 99 | + for (int i = 0; i < 10; i++) { |
| 100 | + Put p = new Put(Bytes.toBytes(rowPrefix + i)); |
| 101 | + p.addColumn(CF, Bytes.toBytes("qualifier"), value); |
| 102 | + p.addColumn(CF, Bytes.toBytes("qualifier2"), value); |
| 103 | + TABLE.put(p); |
| 104 | + } |
| 105 | + ADMIN.flush(TABLE_NAME); |
| 106 | + } |
| 107 | + Scan scan = new Scan(); |
| 108 | + ResultScanner results = TABLE.getScanner(scan); |
| 109 | + int count = 0; |
| 110 | + while (results.next() != null) { |
| 111 | + count++; |
| 112 | + } |
| 113 | + Assert.assertEquals("There should be 100 rows!", 100, count); |
| 114 | + List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegionServer(0).getRegions(); |
| 115 | + regions.removeIf(r -> !r.getRegionInfo().getTable().equals(TABLE_NAME)); |
| 116 | + assertEquals(1, regions.size()); |
| 117 | + assertNotNull(regions.get(0).getSplitPolicy().getSplitPoint()); |
| 118 | + assertTrue(regions.get(0).getCompactPriority() >= PRIORITY_USER); |
| 119 | + assertTrue(UTIL.getMiniHBaseCluster().getRegionServer(0).getCompactSplitThread() |
| 120 | + .requestSplit(regions.get(0))); |
| 121 | + |
| 122 | + // split region |
| 123 | + ADMIN.splitSwitch(true, true); |
| 124 | + MasterProcedureEnv env = |
| 125 | + UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment(); |
| 126 | + final ProcedureExecutor<MasterProcedureEnv> executor = |
| 127 | + UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor(); |
| 128 | + SplitTableRegionProcedure splitProcedure = |
| 129 | + new SplitTableRegionProcedure(env, regions.get(0).getRegionInfo(), Bytes.toBytes("row5")); |
| 130 | + executor.submitProcedure(splitProcedure); |
| 131 | + ProcedureTestingUtility.waitProcedure(executor, splitProcedure.getProcId()); |
| 132 | + |
| 133 | + regions = UTIL.getMiniHBaseCluster().getRegionServer(0).getRegions(); |
| 134 | + regions.removeIf(r -> !r.getRegionInfo().getTable().equals(TABLE_NAME)); |
| 135 | + assertEquals(2, regions.size()); |
| 136 | + scan = new Scan(); |
| 137 | + results = TABLE.getScanner(scan); |
| 138 | + count = 0; |
| 139 | + while (results.next() != null) { |
| 140 | + count++; |
| 141 | + } |
| 142 | + Assert.assertEquals("There should be 100 rows!", 100, count); |
| 143 | + for (HRegion region : regions) { |
| 144 | + assertTrue(region.getCompactPriority() < PRIORITY_USER); |
| 145 | + assertFalse( |
| 146 | + UTIL.getMiniHBaseCluster().getRegionServer(0).getCompactSplitThread().requestSplit(region)); |
| 147 | + } |
| 148 | + } |
| 149 | +} |
0 commit comments