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 3695e92..08fe105 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 @@ -1289,8 +1289,15 @@ public class MetaTableAccessor { */ public static Put makePutFromRegionInfo(HRegionInfo regionInfo) throws IOException { - long now = EnvironmentEdgeManager.currentTime(); - Put put = new Put(regionInfo.getRegionName(), now); + return makePutFromRegionInfo(regionInfo, EnvironmentEdgeManager.currentTime()); + } + + /** + * 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; } @@ -1533,11 +1540,23 @@ public class MetaTableAccessor { public static void addRegionsToMeta(Connection connection, List regionInfos, int regionReplication) throws IOException { + addRegionsToMeta(connection, regionInfos, regionReplication, 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 regionReplication + * @param ts desired timestamp + * @throws IOException if problem connecting or updating meta + */ + public static void addRegionsToMeta(Connection connection, + List regionInfos, int regionReplication, long ts) + throws IOException { List puts = new ArrayList(); for (HRegionInfo regionInfo : regionInfos) { if (RegionReplicaUtil.isDefaultReplica(regionInfo)) { - puts.add(makePutFromRegionInfo(regionInfo)); - Put put = makePutFromRegionInfo(regionInfo); + Put put = makePutFromRegionInfo(regionInfo, ts); // Add empty locations for region replicas so that number of replicas can be cached // whenever the primary region is looked up from meta for (int i = 1; i < regionReplication; i++) { @@ -1808,11 +1827,20 @@ public class MetaTableAccessor { */ public static void deleteRegions(Connection connection, List regionsInfo) throws IOException { + deleteRegions(connection, regionsInfo, EnvironmentEdgeManager.currentTime()); + } + /** + * 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, long ts) throws IOException { List deletes = new ArrayList(regionsInfo.size()); - long time = EnvironmentEdgeManager.currentTime(); for (HRegionInfo hri: regionsInfo) { Delete e = new Delete(hri.getRegionName()); - e.addFamily(getCatalogFamily(), time); + e.addFamily(getCatalogFamily(), ts); deletes.add(e); } deleteFromMetaTable(connection, deletes); @@ -1858,13 +1886,16 @@ public class MetaTableAccessor { */ public static void overwriteRegions(Connection connection, List regionInfos, int regionReplication) 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, regionReplication); + // + // HBASE-13875 uses master timestamp for the mutations. The 20ms sleep is not needed + addRegionsToMeta(connection, regionInfos, regionReplication, now+1); LOG.info("Overwritten " + regionInfos); }