From a60a9afab55287fdac90858cc58d9ead23fd02a9 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Wed, 26 Jun 2019 18:12:46 +0800 Subject: [PATCH] HBASE-22632 UT to reprocedure the problem --- .../procedure/TestIgnoreUnknownFamily.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestIgnoreUnknownFamily.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestIgnoreUnknownFamily.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestIgnoreUnknownFamily.java new file mode 100644 index 0000000000..7f4b06efc7 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestIgnoreUnknownFamily.java @@ -0,0 +1,95 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable + * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under the License. + */ +package org.apache.hadoop.hbase.master.procedure; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; +import org.apache.hadoop.hbase.io.hfile.HFileContext; +import org.apache.hadoop.hbase.master.MasterFileSystem; +import org.apache.hadoop.hbase.regionserver.StoreFileWriter; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; + +/** + * Testcase for HBASE-22632 + */ +@Category({ MasterTests.class, MediumTests.class }) +public class TestIgnoreUnknownFamily { + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + private static final byte[] FAMILY = Bytes.toBytes("cf"); + + private static final byte[] UNKNOWN_FAMILY = Bytes.toBytes("wrong_cf"); + + @Rule + public TestName name = new TestName(); + + @BeforeClass + public static void setUp() throws Exception { + UTIL.startMiniCluster(1); + } + + @AfterClass + public static void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @After + public void tearDownAfterTest() throws IOException { + Admin admin = UTIL.getAdmin(); + for (TableName tableName : admin.listTableNames()) { + admin.disableTable(tableName); + admin.deleteTable(tableName); + } + } + + private void addStoreFileToKnownFamily(RegionInfo region) throws IOException { + MasterFileSystem mfs = UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); + Path regionDir = + FSUtils.getRegionDirFromRootDir(FSUtils.getRootDir(mfs.getConfiguration()), region); + Path familyDir = new Path(regionDir, Bytes.toString(UNKNOWN_FAMILY)); + StoreFileWriter writer = + new StoreFileWriter.Builder(mfs.getConfiguration(), mfs.getFileSystem()) + .withOutputDir(familyDir).withFileContext(new HFileContext()).build(); + writer.close(); + } + + @Test + public void testSplit() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + TableName tableName = TableName.valueOf(name.getMethodName()); + Admin admin = UTIL.getAdmin(); + admin.createTable(TableDescriptorBuilder.newBuilder(tableName) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build()); + RegionInfo region = admin.getRegions(tableName).get(0); + addStoreFileToKnownFamily(region); + admin.splitRegionAsync(region.getRegionName(), Bytes.toBytes(0)).get(30, TimeUnit.SECONDS); + } +} -- 2.17.1