@InterfaceAudience.Private public final class MetaTableAccessor extends Object
hbase:meta region as well as assignment information stored
to hbase:meta.
Some of the methods of this class take ZooKeeperWatcher as a param. The only reason for this is
when this class is used on client-side (e.g. HBaseAdmin), we want to use short-lived connection
(opened before each operation, closed right after), while when used on HM or HRS (like in
AssignmentManager) we want permanent connection.
HBASE-10070 adds a replicaId to HRI, meaning more than one HRI can be defined for the same table
range (table, startKey, endKey). For every range, there will be at least one HRI defined which is
called default replica.
table:state => contains table stateFor the catalog family, see the comments of
CatalogFamilyFormat for more details.
TODO: Add rep_barrier for serial replication explanation. See SerialReplicationChecker.
The actual layout of meta should be encapsulated inside MetaTableAccessor methods, and should not
leak out of it (through Result objects, etc)CatalogFamilyFormat,
ClientMetaTableAccessor| Modifier and Type | Method and Description |
|---|---|
static Put |
addDaughtersToPut(Put put,
RegionInfo splitA,
RegionInfo splitB)
Adds split daughters to the Put
|
static Put |
addEmptyLocation(Put p,
int replicaId) |
static Put |
addLocation(Put p,
ServerName sn,
long openSeqNum,
int replicaId) |
static Put |
addRegionInfo(Put p,
RegionInfo hri) |
static Put |
addRegionStateToPut(Put put,
RegionState.State state) |
static void |
addRegionsToMeta(Connection connection,
List<RegionInfo> regionInfos,
int regionReplication)
Adds a hbase:meta row for each of the specified new regions.
|
static void |
addRegionsToMeta(Connection connection,
List<RegionInfo> regionInfos,
int regionReplication,
long ts)
Adds a hbase:meta row for each of the specified new regions.
|
static void |
addSplitsToParent(Connection connection,
RegionInfo regionInfo,
RegionInfo splitA,
RegionInfo splitB)
Adds daughter region infos to hbase:meta row for the specified region.
|
static void |
deleteTableState(Connection connection,
TableName table)
Remove state for table from meta
|
static void |
fullScanMetaAndPrint(Connection connection) |
static List<Result> |
fullScanRegions(Connection connection)
Performs a full scan of
hbase:meta for regions. |
static void |
fullScanRegions(Connection connection,
ClientMetaTableAccessor.Visitor visitor)
Performs a full scan of
hbase:meta for regions. |
static void |
fullScanTables(Connection connection,
ClientMetaTableAccessor.Visitor visitor)
Performs a full scan of
hbase:meta for tables. |
static List<RegionInfo> |
getAllRegions(Connection connection,
boolean excludeOfflinedSplitParents)
Lists all of the regions currently in META.
|
static Result |
getCatalogFamilyRow(Connection connection,
RegionInfo ri) |
static PairOfSameType<RegionInfo> |
getDaughterRegions(Result data)
Returns the daughter regions by reading the corresponding columns of the catalog table Result.
|
static Table |
getMetaHTable(Connection connection)
Callers should call close on the returned
Table instance. |
static Pair<RegionInfo,ServerName> |
getRegion(Connection connection,
byte[] regionName)
Deprecated.
use
getRegionLocation(Connection, byte[]) instead |
static HRegionLocation |
getRegionLocation(Connection connection,
byte[] regionName)
Returns the HRegionLocation from meta for the given region
|
static HRegionLocation |
getRegionLocation(Connection connection,
RegionInfo regionInfo)
Returns the HRegionLocation from meta for the given region
|
static Result |
getRegionResult(Connection connection,
byte[] regionName)
Gets the result in hbase:meta for the specified region.
|
static Scan |
getScanForTableName(org.apache.hadoop.conf.Configuration conf,
TableName tableName)
This method creates a Scan object that will only scan catalog rows that belong to the specified
table.
|
static List<RegionInfo> |
getTableRegions(Connection connection,
TableName tableName)
Gets all of the regions of the specified table.
|
static List<RegionInfo> |
getTableRegions(Connection connection,
TableName tableName,
boolean excludeOfflinedSplitParents)
Gets all of the regions of the specified table.
|
static List<Pair<RegionInfo,ServerName>> |
getTableRegionsAndLocations(Connection connection,
TableName tableName)
Do not use this method to get meta table regions, use methods in MetaTableLocator instead.
|
static List<Pair<RegionInfo,ServerName>> |
getTableRegionsAndLocations(Connection connection,
TableName tableName,
boolean excludeOfflinedSplitParents)
Do not use this method to get meta table regions, use methods in MetaTableLocator instead.
|
static TableState |
getTableState(Connection conn,
TableName tableName)
Fetch table state for given table from META table
|
static Map<TableName,TableState> |
getTableStates(Connection conn)
Fetch table states from META table
|
static ServerName |
getTargetServerName(Result r,
int replicaId)
Returns the
ServerName from catalog table Result where the region is
transitioning on. |
static Delete |
makeDeleteFromRegionInfo(RegionInfo regionInfo,
long ts)
Generates and returns a Delete containing the region info for the catalog table
|
static Put |
makePutFromRegionInfo(RegionInfo regionInfo,
long ts)
Generates and returns a Put containing the region into for the catalog table
|
static Put |
makePutFromTableState(TableState state,
long ts)
Construct PUT for given state
|
static void |
putsToMetaTable(Connection connection,
List<Put> ps)
Put the passed
ps to the hbase:meta table. |
static Result |
scanByRegionEncodedName(Connection connection,
String regionEncodedName)
Scans META table for a row whose key contains the specified regionEncodedName, returning
a single related
Result instance if any row is found, null otherwise. |
static void |
scanMeta(Connection connection,
byte[] startRow,
byte[] stopRow,
ClientMetaTableAccessor.QueryType type,
ClientMetaTableAccessor.Visitor visitor) |
static void |
scanMeta(Connection connection,
byte[] startRow,
byte[] stopRow,
ClientMetaTableAccessor.QueryType type,
Filter filter,
int maxRows,
ClientMetaTableAccessor.Visitor visitor) |
static void |
scanMeta(Connection connection,
byte[] startRow,
byte[] stopRow,
ClientMetaTableAccessor.QueryType type,
int maxRows,
ClientMetaTableAccessor.Visitor visitor)
Performs a scan of META table.
|
static void |
scanMeta(Connection connection,
ClientMetaTableAccessor.Visitor visitor,
TableName tableName,
byte[] row,
int rowLimit)
Performs a scan of META table for given table starting from given row.
|
static void |
scanMetaForTableRegions(Connection connection,
ClientMetaTableAccessor.Visitor visitor,
TableName tableName) |
static void |
updateRegionLocation(Connection connection,
RegionInfo regionInfo,
ServerName sn,
long openSeqNum,
long masterSystemTime)
Updates the location of the specified region in hbase:meta to be the specified server hostname
and startcode.
|
static void |
updateRegionState(Connection connection,
RegionInfo ri,
RegionState.State state)
Update state column in hbase:meta.
|
static void |
updateTableState(Connection conn,
TableName tableName,
TableState.State actual)
Updates state in META Do not use.
|
public static void fullScanRegions(Connection connection, ClientMetaTableAccessor.Visitor visitor) throws IOException
hbase:meta for regions.connection - connection we're usingvisitor - Visitor invoked against each row in regions family.IOExceptionpublic static List<Result> fullScanRegions(Connection connection) throws IOException
hbase:meta for regions.connection - connection we're usingIOExceptionpublic static void fullScanTables(Connection connection, ClientMetaTableAccessor.Visitor visitor) throws IOException
hbase:meta for tables.connection - connection we're usingvisitor - Visitor invoked against each row in tables family.IOExceptionpublic static Table getMetaHTable(Connection connection) throws IOException
Table instance.connection - connection we're using to access MetaTable for hbase:metaNullPointerException - if connection is nullIOException@Deprecated public static Pair<RegionInfo,ServerName> getRegion(Connection connection, byte[] regionName) throws IOException
getRegionLocation(Connection, byte[]) insteadconnection - connection we're usingregionName - Region to lookup.regionNameIOExceptionpublic static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException
connection - connection we're usingregionName - region we're looking forIOExceptionpublic static HRegionLocation getRegionLocation(Connection connection, RegionInfo regionInfo) throws IOException
connection - connection we're usingregionInfo - region informationIOExceptionpublic static Result getCatalogFamilyRow(Connection connection, RegionInfo ri) throws IOException
HConstants.CATALOG_FAMILY row from hbase:meta.IOExceptionpublic static Result getRegionResult(Connection connection, byte[] regionName) throws IOException
connection - connection we're usingregionName - region we're looking forIOExceptionpublic static Result scanByRegionEncodedName(Connection connection, String regionEncodedName) throws IOException
Result instance if any row is found, null otherwise.connection - the connection to query META table.regionEncodedName - the region encoded name to look for at META.Result instance with the row related info in META, null otherwise.IOException - if any errors occur while querying META.public static List<RegionInfo> getAllRegions(Connection connection, boolean excludeOfflinedSplitParents) throws IOException
connection - to connect withexcludeOfflinedSplitParents - False if we are to include offlined/splitparents regions,
true and we'll leave out offlined regions from returned listIOExceptionpublic static List<RegionInfo> getTableRegions(Connection connection, TableName tableName) throws IOException
connection - connection we're usingtableName - table we're looking forRegionInfo.IOExceptionpublic static List<RegionInfo> getTableRegions(Connection connection, TableName tableName, boolean excludeOfflinedSplitParents) throws IOException
connection - connection we're usingtableName - table we're looking forexcludeOfflinedSplitParents - If true, do not include offlined split parents in the
return.RegionInfo.IOExceptionpublic static Scan getScanForTableName(org.apache.hadoop.conf.Configuration conf, TableName tableName)
tableName - bytes of table's namepublic static List<Pair<RegionInfo,ServerName>> getTableRegionsAndLocations(Connection connection, TableName tableName) throws IOException
connection - connection we're usingtableName - table we're looking forIOExceptionpublic static List<Pair<RegionInfo,ServerName>> getTableRegionsAndLocations(Connection connection, @Nullable TableName tableName, boolean excludeOfflinedSplitParents) throws IOException
connection - connection we're usingtableName - table to work with, can be null for getting all regionsexcludeOfflinedSplitParents - don't return split parentsIOExceptionpublic static void fullScanMetaAndPrint(Connection connection) throws IOException
IOExceptionpublic static void scanMetaForTableRegions(Connection connection, ClientMetaTableAccessor.Visitor visitor, TableName tableName) throws IOException
IOExceptionpublic static void scanMeta(Connection connection, @Nullable byte[] startRow, @Nullable byte[] stopRow, ClientMetaTableAccessor.QueryType type, ClientMetaTableAccessor.Visitor visitor) throws IOException
IOExceptionpublic static void scanMeta(Connection connection, ClientMetaTableAccessor.Visitor visitor, TableName tableName, byte[] row, int rowLimit) throws IOException
connection - connection we're usingvisitor - visitor to calltableName - table withing we scanrow - start scan from this rowrowLimit - max number of rows to returnIOExceptionpublic static void scanMeta(Connection connection, @Nullable byte[] startRow, @Nullable byte[] stopRow, ClientMetaTableAccessor.QueryType type, int maxRows, ClientMetaTableAccessor.Visitor visitor) throws IOException
connection - connection we're usingstartRow - Where to start the scan. Pass null if want to begin scan at first row.stopRow - Where to stop the scan. Pass null if want to scan all rows from the start onetype - scanned part of metamaxRows - maximum rows to returnvisitor - Visitor invoked against each row.IOExceptionpublic static void scanMeta(Connection connection, @Nullable byte[] startRow, @Nullable byte[] stopRow, ClientMetaTableAccessor.QueryType type, @Nullable Filter filter, int maxRows, ClientMetaTableAccessor.Visitor visitor) throws IOException
IOException@Nullable public static ServerName getTargetServerName(Result r, int replicaId)
ServerName from catalog table Result where the region is
transitioning on. It should be the same as
CatalogFamilyFormat.getServerName(Result,int) if the server is at OPEN state.r - Result to pull the transitioning server name fromCatalogFamilyFormat.getServerName(Result,int) if
necessary fields not found or empty.public static PairOfSameType<RegionInfo> getDaughterRegions(Result data)
data - a Result object from the catalog table scan@Nullable public static TableState getTableState(Connection conn, TableName tableName) throws IOException
conn - connection to usetableName - table to fetch state forIOExceptionpublic static Map<TableName,TableState> getTableStates(Connection conn) throws IOException
conn - connection to useIOExceptionpublic static void updateTableState(Connection conn, TableName tableName, TableState.State actual) throws IOException
conn - connection to usetableName - table to look forIOExceptionpublic static Put makePutFromRegionInfo(RegionInfo regionInfo, long ts) throws IOException
IOExceptionpublic static Delete makeDeleteFromRegionInfo(RegionInfo regionInfo, long ts)
public static Put addDaughtersToPut(Put put, RegionInfo splitA, RegionInfo splitB) throws IOException
IOExceptionpublic static void putsToMetaTable(Connection connection, List<Put> ps) throws IOException
ps to the hbase:meta table.connection - connection we're usingps - Put to add to hbase:metaIOExceptionpublic static Put addRegionStateToPut(Put put, RegionState.State state) throws IOException
IOExceptionpublic static void updateRegionState(Connection connection, RegionInfo ri, RegionState.State state) throws IOException
IOExceptionpublic static void addSplitsToParent(Connection connection, RegionInfo regionInfo, RegionInfo splitA, RegionInfo splitB) throws IOException
RegionStateStore if you want to split a
region.connection - connection we're usingregionInfo - RegionInfo of parent regionsplitA - first split daughter of the parent regionInfosplitB - second split daughter of the parent regionInfoIOException - if problem connecting or updating metapublic static void addRegionsToMeta(Connection connection, List<RegionInfo> regionInfos, int regionReplication) throws IOException
connection - connection we're usingregionInfos - region information listIOException - if problem connecting or updating metapublic static void addRegionsToMeta(Connection connection, List<RegionInfo> regionInfos, int regionReplication, long ts) throws IOException
connection - connection we're usingregionInfos - region information listts - desired timestampIOException - if problem connecting or updating metapublic static Put makePutFromTableState(TableState state, long ts)
state - new statepublic static void deleteTableState(Connection connection, TableName table) throws IOException
connection - to use for deletiontable - to delete state forIOExceptionpublic static void updateRegionLocation(Connection connection, RegionInfo regionInfo, ServerName sn, long openSeqNum, long masterSystemTime) throws IOException
Uses passed catalog tracker to get a connection to the server hosting hbase:meta and makes edits to that region.
connection - connection we're usingregionInfo - region to update location ofopenSeqNum - the latest sequence number obtained when the region was opensn - Server namemasterSystemTime - wall clock time from master if passed in the open region RPCIOExceptionpublic static Put addRegionInfo(Put p, RegionInfo hri) throws IOException
IOExceptionpublic static Put addLocation(Put p, ServerName sn, long openSeqNum, int replicaId) throws IOException
IOExceptionpublic static Put addEmptyLocation(Put p, int replicaId) throws IOException
IOExceptionCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.