diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java index 57018dc..458ecc3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java @@ -921,7 +921,14 @@ public class MetaTableAccessor { */ public static Put makePutFromRegionInfo(HRegionInfo regionInfo) throws IOException { - Put put = new Put(regionInfo.getRegionName()); + return makePutFromRegionInfo(regionInfo, HConstants.LATEST_TIMESTAMP); + } + /** + * Generates and returns a Put containing the region into for the catalog table + */ + public static Put makePutFromRegionInfo(HRegionInfo regionInfo, long ts) + throws IOException { + Put put = new Put(regionInfo.getRegionName(), ts); addRegionInfo(put, regionInfo); return put; } @@ -1147,10 +1154,23 @@ public class MetaTableAccessor { public static void addRegionsToMeta(Connection connection, List regionInfos) throws IOException { + addRegionsToMeta(connection, regionInfos, HConstants.LATEST_TIMESTAMP); + } + + /** + * Adds a hbase:meta row for each of the specified new regions. + * @param connection connection we're using + * @param regionInfos region information list + * @param ts desired timestamp + * @throws IOException if problem connecting or updating meta + */ + public static void addRegionsToMeta(Connection connection, + List regionInfos, long ts) + throws IOException { List puts = new ArrayList(); for (HRegionInfo regionInfo : regionInfos) { if (RegionReplicaUtil.isDefaultReplica(regionInfo)) { - puts.add(makePutFromRegionInfo(regionInfo)); + puts.add(makePutFromRegionInfo(regionInfo, ts)); } } putsToMetaTable(connection, puts); @@ -1352,17 +1372,28 @@ public class MetaTableAccessor { * Deletes the specified regions from META. * @param connection connection we're using * @param regionsInfo list of regions to be deleted from META + * @param ts desired timestamp * @throws IOException */ public static void deleteRegions(Connection connection, - List regionsInfo) throws IOException { + List regionsInfo, long ts) throws IOException { List deletes = new ArrayList(regionsInfo.size()); for (HRegionInfo hri: regionsInfo) { - deletes.add(new Delete(hri.getRegionName())); + deletes.add(new Delete(hri.getRegionName(), ts)); } deleteFromMetaTable(connection, deletes); LOG.info("Deleted " + regionsInfo); } + /** + * Deletes the specified regions from META. + * @param connection connection we're using + * @param regionsInfo list of regions to be deleted from META + * @throws IOException + */ + public static void deleteRegions(Connection connection, + List regionsInfo) throws IOException { + deleteRegions(connection, regionsInfo, HConstants.LATEST_TIMESTAMP); + } /** * Adds and Removes the specified regions from hbase:meta @@ -1403,13 +1434,16 @@ public class MetaTableAccessor { */ public static void overwriteRegions(Connection connection, List regionInfos) throws IOException { - deleteRegions(connection, regionInfos); + // use master time for delete marker and the Put + long now = EnvironmentEdgeManager.currentTime(); + deleteRegions(connection, regionInfos, now); // Why sleep? This is the easiest way to ensure that the previous deletes does not // eclipse the following puts, that might happen in the same ts from the server. // See HBASE-9906, and HBASE-9879. Once either HBASE-9879, HBASE-8770 is fixed, // or HBASE-9905 is fixed and meta uses seqIds, we do not need the sleep. - Threads.sleep(20); - addRegionsToMeta(connection, regionInfos); + // + // HBASE-13875 uses master timestamp for the mutations. The 20ms sleep is not needed + addRegionsToMeta(connection, regionInfos, now+1); LOG.info("Overwritten " + regionInfos); }