HBASE-11462 MetaTableAccessor shouldn't use ZooKeeeper (Mikhail Antononv)

This commit is contained in:
stack 2014-09-19 11:02:35 -07:00
parent 0ff05f46e7
commit 7d0f5eba2d
15 changed files with 156 additions and 94 deletions

View File

@ -44,8 +44,6 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.PairOfSameType;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import java.io.IOException;
import java.io.InterruptedIOException;
@ -367,22 +365,21 @@ public class MetaTableAccessor {
}
/**
* Gets all of the regions of the specified table.
* @param zkw zookeeper connection to access meta table
* Gets all of the regions of the specified table. Do not use this method
* to get meta table regions, use methods in MetaTableLocator instead.
* @param hConnection connection we're using
* @param tableName table we're looking for
* @return Ordered list of {@link HRegionInfo}.
* @throws IOException
*/
public static List<HRegionInfo> getTableRegions(ZooKeeperWatcher zkw,
HConnection hConnection, TableName tableName)
public static List<HRegionInfo> getTableRegions(HConnection hConnection, TableName tableName)
throws IOException {
return getTableRegions(zkw, hConnection, tableName, false);
return getTableRegions(hConnection, tableName, false);
}
/**
* Gets all of the regions of the specified table.
* @param zkw zookeeper connection to access meta table
* Gets all of the regions of the specified table. Do not use this method
* to get meta table regions, use methods in MetaTableLocator instead.
* @param hConnection connection we're using
* @param tableName table we're looking for
* @param excludeOfflinedSplitParents If true, do not include offlined split
@ -390,12 +387,12 @@ public class MetaTableAccessor {
* @return Ordered list of {@link HRegionInfo}.
* @throws IOException
*/
public static List<HRegionInfo> getTableRegions(ZooKeeperWatcher zkw,
HConnection hConnection, TableName tableName, final boolean excludeOfflinedSplitParents)
public static List<HRegionInfo> getTableRegions(HConnection hConnection,
TableName tableName, final boolean excludeOfflinedSplitParents)
throws IOException {
List<Pair<HRegionInfo, ServerName>> result = null;
List<Pair<HRegionInfo, ServerName>> result;
try {
result = getTableRegionsAndLocations(zkw, hConnection, tableName,
result = getTableRegionsAndLocations(hConnection, tableName,
excludeOfflinedSplitParents);
} catch (InterruptedException e) {
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
@ -457,7 +454,7 @@ public class MetaTableAccessor {
}
/**
* @param zkw zookeeper connection to access meta table
* Do not use this method to get meta table regions, use methods in MetaTableLocator instead.
* @param hConnection connection we're using
* @param tableName table we're looking for
* @return Return list of regioninfos and server.
@ -465,14 +462,13 @@ public class MetaTableAccessor {
* @throws InterruptedException
*/
public static List<Pair<HRegionInfo, ServerName>>
getTableRegionsAndLocations(ZooKeeperWatcher zkw,
HConnection hConnection, TableName tableName)
getTableRegionsAndLocations(HConnection hConnection, TableName tableName)
throws IOException, InterruptedException {
return getTableRegionsAndLocations(zkw, hConnection, tableName, true);
return getTableRegionsAndLocations(hConnection, tableName, true);
}
/**
* @param zkw ZooKeeperWatcher instance we're using to get hbase:meta location
* Do not use this method to get meta table regions, use methods in MetaTableLocator instead.
* @param hConnection connection we're using
* @param tableName table to work with
* @return Return list of regioninfos and server addresses.
@ -480,17 +476,11 @@ public class MetaTableAccessor {
* @throws InterruptedException
*/
public static List<Pair<HRegionInfo, ServerName>> getTableRegionsAndLocations(
ZooKeeperWatcher zkw, HConnection hConnection, final TableName tableName,
HConnection hConnection, final TableName tableName,
final boolean excludeOfflinedSplitParents) throws IOException, InterruptedException {
if (tableName.equals(TableName.META_TABLE_NAME)) {
// If meta, do a bit of special handling.
ServerName serverName = new MetaTableLocator().getMetaRegionLocation(zkw);
List<Pair<HRegionInfo, ServerName>> list =
new ArrayList<Pair<HRegionInfo, ServerName>>();
list.add(new Pair<HRegionInfo, ServerName>(HRegionInfo.FIRST_META_REGIONINFO,
serverName));
return list;
throw new IOException("This method can't be used to locate meta regions;"
+ " use MetaTableLocator instead");
}
// Make a version of CollectingVisitor that collects HRegionInfo and ServerAddress
CollectingVisitor<Pair<HRegionInfo, ServerName>> visitor =

View File

@ -146,6 +146,7 @@ import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.util.StringUtils;
@ -1724,8 +1725,12 @@ public class HBaseAdmin implements Admin {
checkTableExists(tableName);
zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(),
new ThrowableAbortable());
List<Pair<HRegionInfo, ServerName>> pairs =
MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName);
List<Pair<HRegionInfo, ServerName>> pairs;
if (TableName.META_TABLE_NAME.equals(tableName)) {
pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
} else {
pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
}
for (Pair<HRegionInfo, ServerName> pair: pairs) {
if (pair.getFirst().isOffline()) continue;
if (pair.getSecond() == null) continue;
@ -2078,8 +2083,12 @@ public class HBaseAdmin implements Admin {
checkTableExists(tableName);
zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(),
new ThrowableAbortable());
List<Pair<HRegionInfo, ServerName>> pairs =
MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName);
List<Pair<HRegionInfo, ServerName>> pairs;
if (TableName.META_TABLE_NAME.equals(tableName)) {
pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
} else {
pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
}
for (Pair<HRegionInfo, ServerName> pair: pairs) {
// May not be a server for a particular row
if (pair.getSecond() == null) continue;
@ -2559,13 +2568,17 @@ public class HBaseAdmin implements Admin {
ZooKeeperWatcher zookeeper =
new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(),
new ThrowableAbortable());
List<HRegionInfo> Regions = null;
List<HRegionInfo> regions = null;
try {
Regions = MetaTableAccessor.getTableRegions(zookeeper, connection, tableName, true);
if (TableName.META_TABLE_NAME.equals(tableName)) {
regions = new MetaTableLocator().getMetaRegions(zookeeper);
} else {
regions = MetaTableAccessor.getTableRegions(connection, tableName, true);
}
} finally {
zookeeper.close();
}
return Regions;
return regions;
}
public List<HRegionInfo> getTableRegions(final byte[] tableName)
@ -2664,8 +2677,12 @@ public class HBaseAdmin implements Admin {
new ThrowableAbortable());
try {
checkTableExists(tableName);
List<Pair<HRegionInfo, ServerName>> pairs =
MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName);
List<Pair<HRegionInfo, ServerName>> pairs;
if (TableName.META_TABLE_NAME.equals(tableName)) {
pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
} else {
pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
}
for (Pair<HRegionInfo, ServerName> pair: pairs) {
if (pair.getFirst().isOffline()) continue;
if (pair.getSecond() == null) continue;

View File

@ -24,6 +24,8 @@ import java.net.NoRouteToHostException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.rmi.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
@ -48,6 +50,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.MetaRegionServer;
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.zookeeper.KeeperException;
@ -87,6 +90,37 @@ public class MetaTableLocator {
return getMetaRegionLocation(zkw) != null;
}
/**
* @param zkw ZooKeeper watcher to be used
* @return meta table regions and their locations.
*/
public List<Pair<HRegionInfo, ServerName>> getMetaRegionsAndLocations(ZooKeeperWatcher zkw) {
ServerName serverName = new MetaTableLocator().getMetaRegionLocation(zkw);
List<Pair<HRegionInfo, ServerName>> list = new ArrayList<>();
list.add(new Pair<>(HRegionInfo.FIRST_META_REGIONINFO, serverName));
return list;
}
/**
* @param zkw ZooKeeper watcher to be used
* @return List of meta regions
*/
public List<HRegionInfo> getMetaRegions(ZooKeeperWatcher zkw) {
List<Pair<HRegionInfo, ServerName>> result;
result = getMetaRegionsAndLocations(zkw);
return getListOfHRegionInfos(result);
}
private List<HRegionInfo> getListOfHRegionInfos(
final List<Pair<HRegionInfo, ServerName>> pairs) {
if (pairs == null || pairs.isEmpty()) return null;
List<HRegionInfo> result = new ArrayList<>(pairs.size());
for (Pair<HRegionInfo, ServerName> pair: pairs) {
result.add(pair.getFirst());
}
return result;
}
/**
* Gets the meta region location, if available. Does not block.
* @param zkw zookeeper connection to use

View File

@ -84,6 +84,7 @@ import org.apache.hadoop.hbase.util.KeyLocker;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.PairOfSameType;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.zookeeper.KeeperException;
@ -335,9 +336,13 @@ public class AssignmentManager {
*/
public Pair<Integer, Integer> getReopenStatus(TableName tableName)
throws IOException {
List <HRegionInfo> hris = MetaTableAccessor.getTableRegions(
this.server.getZooKeeper(), this.server.getShortCircuitConnection(),
tableName, true);
List<HRegionInfo> hris;
if (TableName.META_TABLE_NAME.equals(tableName)) {
hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper());
} else {
hris = MetaTableAccessor.getTableRegions(server.getShortCircuitConnection(), tableName, true);
}
Integer pending = 0;
for (HRegionInfo hri : hris) {
String name = hri.getEncodedName();

View File

@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.master.ServerManager;
import org.apache.hadoop.hbase.master.TableLockManager;
import org.apache.hadoop.hbase.master.TableLockManager.TableLock;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
/**
* Handler to run enable of a table.
@ -170,9 +171,15 @@ public class EnableTableHandler extends EventHandler {
ServerManager serverManager = ((HMaster)this.server).getServerManager();
// Get the regions of this table. We're done when all listed
// tables are onlined.
List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations = MetaTableAccessor
.getTableRegionsAndLocations(this.server.getZooKeeper(),
this.server.getShortCircuitConnection(), tableName, true);
List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations;
if (TableName.META_TABLE_NAME.equals(tableName)) {
tableRegionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
server.getZooKeeper());
} else {
tableRegionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
server.getShortCircuitConnection(), tableName, true);
}
int countOfRegionsInTable = tableRegionsAndLocations.size();
Map<HRegionInfo, ServerName> regionsToAssign =
regionsToAssignWithServerName(tableRegionsAndLocations);

View File

@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
/**
* Base class for performing operations against tables.
@ -125,9 +126,12 @@ public abstract class TableEventHandler extends EventHandler {
LOG.info("Handling table operation " + eventType + " on table " +
tableName);
List<HRegionInfo> hris =
MetaTableAccessor.getTableRegions(this.server.getZooKeeper(),
this.server.getShortCircuitConnection(), tableName);
List<HRegionInfo> hris;
if (TableName.META_TABLE_NAME.equals(tableName)) {
hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper());
} else {
hris = MetaTableAccessor.getTableRegions(server.getShortCircuitConnection(), tableName);
}
handleTableOperation(hris);
if (eventType.isOnlineSchemaChangeSupported() && this.masterServices.
getAssignmentManager().getTableStateManager().isTableState(

View File

@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException;
import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
import org.apache.hadoop.hbase.snapshot.SnapshotManifest;
import org.apache.hadoop.hbase.snapshot.SnapshotReferenceUtil;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
/**
* General snapshot verification on the master.
@ -150,8 +151,12 @@ public final class MasterSnapshotVerifier {
* @throws IOException if we can't reach hbase:meta or read the files from the FS
*/
private void verifyRegions(final SnapshotManifest manifest) throws IOException {
List<HRegionInfo> regions = MetaTableAccessor.getTableRegions(
this.services.getZooKeeper(), this.services.getShortCircuitConnection(), tableName);
List<HRegionInfo> regions;
if (TableName.META_TABLE_NAME.equals(tableName)) {
regions = new MetaTableLocator().getMetaRegions(services.getZooKeeper());
} else {
regions = MetaTableAccessor.getTableRegions(services.getShortCircuitConnection(), tableName);
}
// Remove the non-default regions
RegionReplicaUtil.removeNonDefaultRegions(regions);

View File

@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
import org.apache.hadoop.hbase.snapshot.SnapshotManifest;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.zookeeper.KeeperException;
/**
@ -167,9 +168,14 @@ public abstract class TakeSnapshotHandler extends EventHandler implements Snapsh
snapshotManifest.addTableDescriptor(this.htd);
monitor.rethrowException();
List<Pair<HRegionInfo, ServerName>> regionsAndLocations =
MetaTableAccessor.getTableRegionsAndLocations(this.server.getZooKeeper(),
this.server.getShortCircuitConnection(), snapshotTable, false);
List<Pair<HRegionInfo, ServerName>> regionsAndLocations;
if (TableName.META_TABLE_NAME.equals(snapshotTable)) {
regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
server.getZooKeeper());
} else {
regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
server.getShortCircuitConnection(), snapshotTable, false);
}
// run the snapshot
snapshotRegions(regionsAndLocations);

View File

@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.procedure.ProcedureCoordinatorRpcs;
import org.apache.hadoop.hbase.procedure.ZKProcedureCoordinatorRpcs;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ProcedureDescription;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.zookeeper.KeeperException;
import com.google.common.collect.Lists;
@ -124,12 +125,15 @@ public class MasterFlushTableProcedureManager extends MasterProcedureManager {
// It is possible that regions may move after we get the region server list.
// Each region server will get its own online regions for the table.
// We may still miss regions that need to be flushed.
List<Pair<HRegionInfo, ServerName>> regionsAndLocations = null;
List<Pair<HRegionInfo, ServerName>> regionsAndLocations;
try {
regionsAndLocations =
MetaTableAccessor.getTableRegionsAndLocations(this.master.getZooKeeper(),
this.master.getShortCircuitConnection(),
TableName.valueOf(desc.getInstance()), false);
if (TableName.META_TABLE_NAME.equals(tableName)) {
regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
master.getZooKeeper());
} else {
regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
master.getShortCircuitConnection(), tableName, false);
}
} catch (InterruptedException e1) {
String msg = "Failed to get regions for '" + desc.getInstance() + "'";
LOG.error(msg);

View File

@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@ -198,14 +199,13 @@ public class TestMetaTableAccessor {
abstract void metaTask() throws Throwable;
}
@Test public void testGetRegionsCatalogTables()
@Test public void testGetRegionsFromMetaTable()
throws IOException, InterruptedException {
List<HRegionInfo> regions =
MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(),
hConnection, TableName.META_TABLE_NAME);
new MetaTableLocator().getMetaRegions(UTIL.getZooKeeperWatcher());
assertTrue(regions.size() >= 1);
assertTrue(MetaTableAccessor.getTableRegionsAndLocations(UTIL.getZooKeeperWatcher(),
hConnection,TableName.META_TABLE_NAME).size() >= 1);
assertTrue(new MetaTableLocator().getMetaRegionsAndLocations(
UTIL.getZooKeeperWatcher()).size() >= 1);
}
@Test public void testTableExists() throws IOException {
@ -252,17 +252,14 @@ public class TestMetaTableAccessor {
// Now make sure we only get the regions from 1 of the tables at a time
assertEquals(1, MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(),
hConnection, name).size());
assertEquals(1, MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(),
hConnection, greaterName).size());
assertEquals(1, MetaTableAccessor.getTableRegions(hConnection, name).size());
assertEquals(1, MetaTableAccessor.getTableRegions(hConnection, greaterName).size());
}
private static List<HRegionInfo> testGettingTableRegions(final HConnection hConnection,
final TableName name, final int regionCount)
throws IOException, InterruptedException {
List<HRegionInfo> regions = MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(),
hConnection, name);
List<HRegionInfo> regions = MetaTableAccessor.getTableRegions(hConnection, name);
assertEquals(regionCount, regions.size());
Pair<HRegionInfo, ServerName> pair =
MetaTableAccessor.getRegion(hConnection, regions.get(0).getRegionName());

View File

@ -477,7 +477,7 @@ public class TestLoadIncrementalHFilesSplitRecovery {
// Mess it up by leaving a hole in the hbase:meta
HConnection hConnection = HConnectionManager.getConnection(util.getConfiguration());
List<HRegionInfo> regionInfos = MetaTableAccessor.getTableRegions(
util.getZooKeeperWatcher(), hConnection, TableName.valueOf(tableName));
hConnection, TableName.valueOf(tableName));
for (HRegionInfo regionInfo : regionInfos) {
if (Bytes.equals(regionInfo.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
MetaTableAccessor.deleteRegion(hConnection, regionInfo);

View File

@ -86,8 +86,7 @@ public class TestMaster {
TEST_UTIL.loadTable(ht, FAMILYNAME, false);
ht.close();
List<Pair<HRegionInfo, ServerName>> tableRegions =
MetaTableAccessor.getTableRegionsAndLocations(m.getZooKeeper(),
List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
m.getShortCircuitConnection(), TABLENAME);
LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));
assertEquals(1, tableRegions.size());
@ -105,8 +104,8 @@ public class TestMaster {
Thread.sleep(100);
}
LOG.info("Making sure we can call getTableRegions while opening");
tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getZooKeeper(),
m.getShortCircuitConnection(), TABLENAME, false);
tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getShortCircuitConnection(),
TABLENAME, false);
LOG.info("Regions: " + Joiner.on(',').join(tableRegions));
// We have three regions because one is split-in-progress

View File

@ -95,7 +95,7 @@ public class TestMasterOperationsForRegionReplicas {
admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions);
validateNumberOfRowsInMeta(table, numRegions, admin.getConnection());
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(),
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(
admin.getConnection(), table);
assert(hris.size() == numRegions * numReplica);
} finally {
@ -117,8 +117,7 @@ public class TestMasterOperationsForRegionReplicas {
TEST_UTIL.waitTableEnabled(table.getName());
validateNumberOfRowsInMeta(table, numRegions, admin.getConnection());
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(),
admin.getConnection(), table);
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table);
assert(hris.size() == numRegions * numReplica);
// check that the master created expected number of RegionState objects
for (int i = 0; i < numRegions; i++) {
@ -211,8 +210,7 @@ public class TestMasterOperationsForRegionReplicas {
.getAssignmentManager().getRegionStates().getRegionsOfTable(table);
assert(regions.size() == numRegions * numReplica);
//also make sure the meta table has the replica locations removed
hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(),
admin.getConnection(), table);
hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table);
assert(hris.size() == numRegions * numReplica);
//just check that the number of default replica regions in the meta table are the same
//as the number of regions the table was created with, and the count of the
@ -247,8 +245,7 @@ public class TestMasterOperationsForRegionReplicas {
admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions);
TEST_UTIL.waitTableEnabled(table.getName());
Set<byte[]> tableRows = new HashSet<byte[]>();
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(),
admin.getConnection(), table);
List<HRegionInfo> hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table);
for (HRegionInfo hri : hris) {
tableRows.add(hri.getRegionName());
}

View File

@ -173,8 +173,7 @@ public class TestRegionMergeTransactionOnCluster {
table.close();
List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor
.getTableRegionsAndLocations(master.getZooKeeper(),
master.getShortCircuitConnection(), tableName);
.getTableRegionsAndLocations(master.getShortCircuitConnection(), tableName);
HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst();
HTableDescriptor tableDescritor = master.getTableDescriptors().get(
tableName);
@ -291,13 +290,13 @@ public class TestRegionMergeTransactionOnCluster {
// Create table and load data.
createTableAndLoadData(master, tableName, 5, 2);
List<Pair<HRegionInfo, ServerName>> initialRegionToServers =
MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(),
MetaTableAccessor.getTableRegionsAndLocations(
master.getShortCircuitConnection(), tableName);
// Merge 1st and 2nd region
PairOfSameType<HRegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(master, tableName,
0, 2, 5 * 2 - 2);
List<Pair<HRegionInfo, ServerName>> currentRegionToServers =
MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(),
MetaTableAccessor.getTableRegionsAndLocations(
master.getShortCircuitConnection(), tableName);
List<HRegionInfo> initialRegions = new ArrayList<HRegionInfo>();
for (Pair<HRegionInfo, ServerName> p : initialRegionToServers) {
@ -337,7 +336,7 @@ public class TestRegionMergeTransactionOnCluster {
HMaster master, TableName tablename,
int regionAnum, int regionBnum) throws Exception {
List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor
.getTableRegionsAndLocations(master.getZooKeeper(),
.getTableRegionsAndLocations(
master.getShortCircuitConnection(), tablename);
HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();
HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();
@ -354,7 +353,7 @@ public class TestRegionMergeTransactionOnCluster {
long timeout = System.currentTimeMillis() + waitTime;
while (System.currentTimeMillis() < timeout) {
tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
master.getZooKeeper(), master.getShortCircuitConnection(), tablename);
master.getShortCircuitConnection(), tablename);
tableRegionsInMaster = master.getAssignmentManager().getRegionStates()
.getRegionsOfTable(tablename);
if (tableRegionsInMeta.size() == expectedRegionNum
@ -365,7 +364,7 @@ public class TestRegionMergeTransactionOnCluster {
}
tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
master.getZooKeeper(), master.getShortCircuitConnection(), tablename);
master.getShortCircuitConnection(), tablename);
LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));
assertEquals(expectedRegionNum, tableRegionsInMeta.size());
}
@ -395,14 +394,14 @@ public class TestRegionMergeTransactionOnCluster {
List<Pair<HRegionInfo, ServerName>> tableRegions;
while (System.currentTimeMillis() < timeout) {
tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
master.getZooKeeper(), master.getShortCircuitConnection(), tablename);
master.getShortCircuitConnection(), tablename);
if (tableRegions.size() == numRegions * replication)
break;
Thread.sleep(250);
}
tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
master.getZooKeeper(), master.getShortCircuitConnection(), tablename);
master.getShortCircuitConnection(), tablename);
LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));
assertEquals(numRegions * replication, tableRegions.size());
return table;

View File

@ -118,16 +118,14 @@ public class TestMergeTable {
HConnection hConnection = HConnectionManager.getConnection(c);
List<HRegionInfo> originalTableRegions =
MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), hConnection,
desc.getTableName());
MetaTableAccessor.getTableRegions(hConnection, desc.getTableName());
LOG.info("originalTableRegions size=" + originalTableRegions.size() +
"; " + originalTableRegions);
Admin admin = new HBaseAdmin(c);
admin.disableTable(desc.getTableName());
HMerge.merge(c, FileSystem.get(c), desc.getTableName());
List<HRegionInfo> postMergeTableRegions =
MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), hConnection,
desc.getTableName());
MetaTableAccessor.getTableRegions(hConnection, desc.getTableName());
LOG.info("postMergeTableRegions size=" + postMergeTableRegions.size() +
"; " + postMergeTableRegions);
assertTrue("originalTableRegions=" + originalTableRegions.size() +