diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java index cea7423..ac8e427 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java @@ -63,7 +63,15 @@ public class MetaEditor { */ 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; } @@ -271,9 +279,22 @@ public class MetaEditor { public static void addRegionsToMeta(CatalogTracker catalogTracker, List regionInfos) throws IOException { + addRegionsToMeta(catalogTracker, regionInfos, HConstants.LATEST_TIMESTAMP); + } + + /** + * Adds a hbase:meta row for each of the specified new regions. + * @param catalogTracker CatalogTracker + * @param regionInfos region information list + * @param ts desired timestamp + * @throws IOException if problem connecting or updating meta + */ + public static void addRegionsToMeta(CatalogTracker catalogTracker, + List regionInfos, long ts) + throws IOException { List puts = new ArrayList(); for (HRegionInfo regionInfo : regionInfos) { - puts.add(makePutFromRegionInfo(regionInfo)); + puts.add(makePutFromRegionInfo(regionInfo, ts)); } putsToMetaTable(catalogTracker, puts); LOG.info("Added " + puts.size()); @@ -488,9 +509,21 @@ public class MetaEditor { */ public static void deleteRegions(CatalogTracker catalogTracker, List regionsInfo) throws IOException { + deleteRegions(catalogTracker, regionsInfo, HConstants.LATEST_TIMESTAMP); + } + + /** + * Deletes the specified regions from META. + * @param catalogTracker + * @param regionsInfo list of regions to be deleted from META + * @param ts desired timestamp + * @throws IOException + */ + public static void deleteRegions(CatalogTracker catalogTracker, + 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(catalogTracker, deletes); LOG.info("Deleted " + regionsInfo); @@ -534,13 +567,16 @@ public class MetaEditor { */ public static void overwriteRegions(CatalogTracker catalogTracker, List regionInfos) throws IOException { - deleteRegions(catalogTracker, regionInfos); + // use master time for delete marker and the Put + long now = EnvironmentEdgeManager.currentTimeMillis(); + deleteRegions(catalogTracker, 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(catalogTracker, regionInfos); + // + // HBASE-13875 uses master timestamp for the mutations. The 20ms sleep is not needed + addRegionsToMeta(catalogTracker, regionInfos, now+1); LOG.info("Overwritten " + regionInfos); }