Skip to content

Commit

Permalink
fix merging regions of different tables when multiple table args is used
Browse files Browse the repository at this point in the history
But there was no problem without this patch, the region server rejects that merging request.
  • Loading branch information
terence-yoo committed Aug 30, 2019
1 parent 2a50039 commit 1041aab
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public static boolean mergeRegions(Args args, HBaseAdmin admin,
HRegionInfo regionA, HRegionInfo regionB) throws IOException {
long timestamp = System.currentTimeMillis();

assert regionA.getTable().equals(regionB.getTable());

if (HRegionInfo.areAdjacent(regionA, regionB)) {
admin.mergeRegions(regionA.getEncodedNameAsBytes(), regionB.getEncodedNameAsBytes(), false);
Util.printVerboseMessage(args, "CommandAdapter.mergeRegions", timestamp);
Expand Down Expand Up @@ -299,4 +301,4 @@ public static Map<String, Map<String, String>> versionedRegionMap(HBaseAdmin adm
public static ServerName create(String serverNameStr) {
return ServerName.valueOf(serverNameStr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.kakao.hbase.manager.command;

import com.kakao.hbase.ManagerArgs;
import com.kakao.hbase.TestBase;
import com.kakao.hbase.common.Args;
import com.kakao.hbase.common.Constant;
import org.apache.hadoop.hbase.HRegionInfo;
Expand Down Expand Up @@ -88,4 +89,32 @@ public void testMergeEmptyFast6() throws Exception {
regionInfoList = getRegionInfoList(tableName);
assertEquals(1, regionInfoList.size());
}

@Test
public void testMergeMultipleTables() throws Exception {
makeTestData7();

String tableName2 = TestBase.tableName + "2";
String tableName3 = TestBase.tableName + "3";

List<HRegionInfo> regionInfoList;

// merge
String[] argsParam = {"zookeeper", ".*", "empty-FAST", "--force-proceed"
, "--test", "--verbose", "--debug", "--max-iteration", "2"};
Args args = new ManagerArgs(argsParam);
Merge command = new Merge(admin, args);
command.run();

// check
Thread.sleep(Constant.SMALL_WAIT_INTERVAL_MS);
regionInfoList = getRegionInfoList(tableName);
assertEquals(1, regionInfoList.size());

regionInfoList = getRegionInfoList(tableName2);
assertEquals(1, regionInfoList.size());

regionInfoList = getRegionInfoList(tableName3);
assertEquals(1, regionInfoList.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.kakao.hbase.manager.command;

import com.kakao.hbase.ManagerArgs;
import com.kakao.hbase.TestBase;
import com.kakao.hbase.common.Args;
import com.kakao.hbase.common.Constant;
import org.apache.hadoop.hbase.HRegionInfo;
Expand Down Expand Up @@ -93,4 +94,32 @@ public void testMergeEmpty6() throws Exception {
regionInfoList = getRegionInfoList(tableName);
assertEquals(1, regionInfoList.size());
}

@Test
public void testMergeMultipleTables() throws Exception {
makeTestData7();

String tableName2 = TestBase.tableName + "2";
String tableName3 = TestBase.tableName + "3";

List<HRegionInfo> regionInfoList;

// merge
String[] argsParam = {"zookeeper", ".*", "empty", "--force-proceed"
, "--test", "--verbose", "--debug", "--max-iteration", "2"};
Args args = new ManagerArgs(argsParam);
Merge command = new Merge(admin, args);
command.run();

// check
Thread.sleep(Constant.SMALL_WAIT_INTERVAL_MS);
regionInfoList = getRegionInfoList(tableName);
assertEquals(1, regionInfoList.size());

regionInfoList = getRegionInfoList(tableName2);
assertEquals(1, regionInfoList.size());

regionInfoList = getRegionInfoList(tableName3);
assertEquals(1, regionInfoList.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,28 @@ protected void makeTestData6() throws Exception {
regionInfoList = getRegionInfoList(tableName);
assertEquals(11, regionInfoList.size());
}

protected void makeTestData7() throws Exception {
List<HRegionInfo> regionInfoList;

// create tables
String tableName2 = createAdditionalTable(TestBase.tableName + "2");
String tableName3 = createAdditionalTable(TestBase.tableName + "3");

// split tables
splitTable(tableName, "a".getBytes());
splitTable(tableName, "b".getBytes());
regionInfoList = getRegionInfoList(tableName);
assertEquals(3, regionInfoList.size());

splitTable(tableName2, "a".getBytes());
splitTable(tableName2, "b".getBytes());
regionInfoList = getRegionInfoList(tableName2);
assertEquals(3, regionInfoList.size());

splitTable(tableName3, "a".getBytes());
splitTable(tableName3, "b".getBytes());
regionInfoList = getRegionInfoList(tableName3);
assertEquals(3, regionInfoList.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ private void initializeRegionServerMap() throws Exception {
regionServerMap = CommandAdapter.regionServerMap(args, admin.getConfiguration()
, admin.getConnection(), false);
} else {
regionServerMap = CommandAdapter.regionServerMap(args, admin.getConfiguration()
, admin.getConnection(), tables, false);
if (isMultiTable()) {
regionServerMap = CommandAdapter.regionServerMap(args, admin.getConfiguration(),
admin.getConnection(), tables, false);
} else {
regionServerMap = CommandAdapter.regionServerMap(args, admin.getConfiguration(),
admin.getConnection(), new TreeSet<>(Collections.singletonList(tableName)), false);
}
}
clean(regionServerMap);

Expand Down

0 comments on commit 1041aab

Please sign in to comment.