-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-22819 Automatically migrate the rs group config for table after H…
- Loading branch information
Showing
4 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestMigrateRSGroupInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* 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.rsgroup; | ||
|
||
import static org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl.*; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.Put; | ||
import org.apache.hadoop.hbase.client.Table; | ||
import org.apache.hadoop.hbase.client.TableDescriptor; | ||
import org.apache.hadoop.hbase.protobuf.ProtobufUtil; | ||
import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
/** | ||
* Testcase for HBASE-22819 | ||
*/ | ||
@Category({ MediumTests.class }) | ||
public class TestMigrateRSGroupInfo extends TestRSGroupsBase { | ||
|
||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestMigrateRSGroupInfo.class); | ||
|
||
private static String TABLE_NAME_PREFIX = "Table_"; | ||
|
||
private static int NUM_TABLES = 10; | ||
|
||
private static byte[] FAMILY = Bytes.toBytes("family"); | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
setUpTestBeforeClass(); | ||
for (int i = 0; i < NUM_TABLES; i++) { | ||
TEST_UTIL.createTable(TableName.valueOf(TABLE_NAME_PREFIX + i), FAMILY); | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
tearDownAfterClass(); | ||
} | ||
|
||
@Test | ||
public void testMigrate() throws IOException, InterruptedException { | ||
String groupName = name.getMethodName(); | ||
addGroup(groupName, TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().size() - 1); | ||
RSGroupInfo rsGroupInfo = rsGroupAdmin.getRSGroupInfo(groupName); | ||
assertTrue(rsGroupInfo.getTables().isEmpty()); | ||
for (int i = 0; i < NUM_TABLES; i++) { | ||
rsGroupInfo.addTable(TableName.valueOf(TABLE_NAME_PREFIX + i)); | ||
} | ||
try (Table table = TEST_UTIL.getConnection().getTable(RSGROUP_TABLE_NAME)) { | ||
RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(rsGroupInfo); | ||
Put p = new Put(Bytes.toBytes(rsGroupInfo.getName())); | ||
p.addColumn(META_FAMILY_BYTES, META_QUALIFIER_BYTES, proto.toByteArray()); | ||
table.put(p); | ||
} | ||
TEST_UTIL.getMiniHBaseCluster().stopMaster(0).join(); | ||
TEST_UTIL.getMiniHBaseCluster().startMaster(); | ||
TEST_UTIL.waitFor(60000, () -> { | ||
for (int i = 0; i < NUM_TABLES; i++) { | ||
TableDescriptor td; | ||
try { | ||
td = TEST_UTIL.getAdmin().getDescriptor(TableName.valueOf(TABLE_NAME_PREFIX + i)); | ||
} catch (IOException e) { | ||
return false; | ||
} | ||
if (!rsGroupInfo.getName().equals(td.getRegionServerGroup().orElse(null))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
} | ||
} |